|
| 1 | +Text PII Detection & Redaction |
| 2 | +============================== |
| 3 | + |
| 4 | +The image-redaction module blurs PII in screenshots, but text scraped from a UI, |
| 5 | +OCR, the clipboard, an LLM prompt/response, or a log line had no string-level |
| 6 | +equivalent — so PII could leak into action records, audit logs, or a model call. |
| 7 | +``detect_pii`` / ``redact_pii_text`` find and mask emails, phone numbers, SSNs, |
| 8 | +credit-card numbers, IPv4 addresses, and IBANs over plain text. |
| 9 | + |
| 10 | +Patterns are deliberately simple (no nested quantifiers → no catastrophic |
| 11 | +backtracking). Pure standard library (``re`` + ``hashlib``); imports no |
| 12 | +``PySide6``. |
| 13 | + |
| 14 | +Headless API |
| 15 | +------------ |
| 16 | + |
| 17 | +.. code-block:: python |
| 18 | +
|
| 19 | + from je_auto_control import detect_pii, redact_pii_text |
| 20 | +
|
| 21 | + detect_pii("mail a@b.com, ip 10.0.0.1") |
| 22 | + # -> [PIIFinding(kind='email', value='a@b.com', start=5, end=12), ...] |
| 23 | +
|
| 24 | + redact_pii_text("contact a@b.com") # -> "contact [email]" |
| 25 | + redact_pii_text("a@b.com", mode="mask") # -> "*******" |
| 26 | + redact_pii_text("4111111111111111", mode="partial") # -> "************1111" |
| 27 | + redact_pii_text("a@b.com", mode="hash") # -> "[email:fb98d44a]" |
| 28 | +
|
| 29 | + detect_pii(text, kinds=["email", "phone"]) # restrict detectors |
| 30 | +
|
| 31 | +``detect_pii`` returns non-overlapping findings sorted by position (the earlier, |
| 32 | +then longer, match wins — so a credit-card number is not also flagged as a |
| 33 | +phone). ``redact_pii_text`` modes: ``label`` (``[email]``), ``mask`` (``****``), |
| 34 | +``partial`` (keep last 4), ``hash`` (``[email:<digest>]``). |
| 35 | + |
| 36 | +Executor commands |
| 37 | +----------------- |
| 38 | + |
| 39 | +================================ =================================================== |
| 40 | +Command Effect |
| 41 | +================================ =================================================== |
| 42 | +``AC_detect_pii`` ``{findings}`` — PII spans in text. |
| 43 | +``AC_redact_pii`` ``{text}`` — text with PII masked. |
| 44 | +================================ =================================================== |
| 45 | + |
| 46 | +``kinds`` accepts a list or JSON-string list. The same operations are exposed as |
| 47 | +MCP tools (``ac_detect_pii`` / ``ac_redact_pii``) and as Script Builder commands |
| 48 | +under **Data**. |
0 commit comments