Inconsistent detection of PII written with non-ASCII digits (Arabic-Indic, Persian, ...), first step toward Arabic support
Is your feature request related to a problem? Please describe.
Presidio has no Arabic support yet (no language config, context words or Arabic-region recognizers), and a first measurement shows a concrete gap that affects every language using non-ASCII digits: PII written with Arabic-Indic (٠١٢٣٤٥٦٧٨٩), Persian (۰۱۲…) or other Unicode decimal digits is detected inconsistently, and most sensitive identifiers are missed entirely.
I took every string literal containing digits from the analyzer's own recognizer tests (1,839 strings), kept those each PatternRecognizer detects in ASCII form, swapped the ASCII digits for Arabic-Indic digits, and re-ran the same recognizer (90 recognizers, main at 4f0e236):
| Outcome with Arabic-Indic digits | Recognizers (examples) |
|---|---|
| never detected (0%) | CreditCardRecognizer 0/18, IbanRecognizer 0/157, UsSsnRecognizer 0/76, UsPassportRecognizer 0/100, InAadhaarRecognizer 0/22, KrRrnRecognizer 0/18, ... (44 recognizers) |
| partially detected | DateRecognizer 4/36, IpRecognizer 3/84, FiPersonalIdentityCodeRecognizer 19/28, ... |
| always detected (100%) | PhUmidRecognizer 61/61, SePersonnummerRecognizer 35/35, ItPassportRecognizer 17/17, ... |
| raises | SgUenRecognizer (ValueError, also reported in #2356) |
The split follows implementation details: patterns using \d match any Unicode digit while [0-9] patterns do not, and some checksum code handles non-ASCII digits while some does not. So a credit card number written ٤٠١٢٨٨٨٨٨٨٨٨١٨٨١ passes through unredacted, while other identifiers in the same text are caught.
Describe the solution you'd like
Translate every Unicode decimal digit (unicodedata category Nd) to its ASCII digit before pattern matching and validation in PatternRecognizer. Each digit is one code point mapped to one code point, so result spans are unchanged and no offset mapping is needed. IbanRecognizer has its own matching loop and needs the same line.
I have this working on a branch (19 lines plus a test):
- the audit above goes to 100% detection parity for all 90 recognizers, and the
SgUenRecognizercrash disappears; - the full analyzer test suite gives the same results before and after (3,344 passed; the remaining failures are optional dependencies missing in my environment and occur on
maintoo); - cost: the translation table (670 digits) is built once at import in about 0.05 s; translating a 4,650-character note takes about 3 µs.
This changes detection results for existing users (more detections on text with non-ASCII digits), so I'd like your view before opening the PR: should it be the default, or opt-in (e.g. a PatternRecognizer flag)?
Planned follow-ups for Arabic (each its own issue/PR, after this one):
- Arabic context words and clitics: Arabic attaches prefixes to words (و, ف, ب, ك, ل, ال), so
والرقمdoes not match the context wordرقم; the same family of problem as Korean in #2216 / #2341. I'd measure context hit rates on Arabic text first. - Recognizers for national identifiers of Arabic-speaking countries (e.g. UAE Emirates ID, Saudi national ID), each with its checksum verified against an official specification before submission.
- A documented Arabic NER configuration through the transformers NLP engine.
I prepared this with AI assistance and reviewed it; I speak Arabic and work on clinical NLP.
Following up on the Arabic-Indic / Persian digits gap: I released an open model that covers it, in case it's useful as an ML-side complement to the regex fix. decima-pii (140M, Apache-2.0, ONNX on CPU) tags PERSON_NAME, PHONE, EMAIL, NATIONAL_ID (Iran, Qatar, Saudi, UAE, Pakistan, Turkey, Egypt, Morocco, UK, US), IBAN, CARD, PASSPORT, ADDRESS, DATE_OF_BIRTH and IP_ADDRESS in Arabic, Persian, Urdu, Turkish and English, in any digit script. On MultiGraSCCo (outside, clinical letters) it scores 0.870 relaxed F1 against 0.117 for Presidio's English defaults, so I'm not claiming parity with a configured Presidio, only that the multilingual side is covered. If a RemoteRecognizer/transformers-recognizer example would help, I'm glad to write it.
@eliem08 This matches what I see in Saudi and UAE data. In #2588 (Saudi National ID, Iqama, Emirates ID) I handled Arabic-Indic digits inside each recognizer: the regex accepts [0-9٠-٩] and the validator translates the digits before the Luhn check. It works, but it is exactly the per-recognizer patchwork this issue describes, and it covers only U+0660-U+0669, not Persian digits.
If the central normalization you propose lands, I'll drop that code from #2588 so the new recognizers use plain [0-9] like the rest. Happy to rebase onto whichever is merged first.
One case worth a test either way: a value with mixed scripts, e.g. an Iqama typed as ٢٣٤5678904 after a copy-paste from an Arabic form. A one-to-one code point mapping handles it for free; per-recognizer character classes only do if they allow mixing.