From b4075d1857cffee11362ada550327cca92ca9bb7 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 9 Nov 2026 00:55:32 +0100 Subject: tools: redact, codice fiscale survives OCR misreads Live check: a scanned codice fiscale read as NREMRCE0A01F205X (80 as E0) failed the strict layout and stayed visible. Any 16-character code mixing at least 3 letters and 3 digits is now blacked out. The tool description no longer promises these are always found and asks the model to list them in items on scans too. Co-Authored-By: Claude Opus 5.5 --- examples/tools/redact.py | 10 ++++++++-- examples/tools/redact.toml | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/tools/redact.py b/examples/tools/redact.py index 7884d3b..af9201c 100755 --- a/examples/tools/redact.py +++ b/examples/tools/redact.py @@ -48,8 +48,11 @@ def luhn_ok(s): RULES = [ ("email", re.compile(r"[\w.+-]+@[\w-]+(?:\.[\w-]+)+"), None), ("iban", re.compile(r"\b[A-Z]{2}\d{2}(?: ?[A-Z0-9]{4}){2,7}(?: ?[A-Z0-9]{1,3})?\b", re.I), iban_ok), - ("codice fiscale", re.compile(r"\b[A-Z]{6}[0-9LMNPQRSTUV]{2}[ABCDEHLMPRST]" - r"[0-9LMNPQRSTUV]{2}[A-Z][0-9LMNPQRSTUV]{3}[A-Z]\b", re.I), None), + # Any 16-character code mixing letters and digits, not the strict + # codice fiscale layout: OCR read a scanned "80" as "E0" and the strict + # pattern let it through. Other 16-character codes go too (safe side). + ("codice fiscale", re.compile(r"\b[A-Z0-9]{16}\b", re.I), + lambda s: sum(c.isdigit() for c in s) >= 3 and sum(c.isalpha() for c in s) >= 3), ("card", re.compile(r"(?-redacted.' beside the original, and opens it for the user to check. Emails, phone numbers, IBANs, codici fiscali and card numbers are always found. Pass in items every other piece of personal data you see in the document: names, addresses, account or document numbers, exactly as written there. The original is not changed. Report what the tool says, including anything not found." +description = "Redact personal data (PII) from an attached PDF or image: writes a copy with black boxes, '-redacted.' beside the original, and opens it for the user to check. Emails, phone numbers, IBANs, codici fiscali and card numbers are found automatically; on a scan or photo list them in items too, since OCR can misread them. Pass in items every other piece of personal data you see in the document: names, addresses, account or document numbers, exactly as written there. The original is not changed. Report what the tool says, including anything not found." command = ["redact.py", "{path}", "{items}"] cloud = ["hetzner"] timeout = 120 -- cgit v1.2.3