PII¶
pygarble.screening.PIIDetector finds personal data by structure and, where the
format has one, a checksum. Findings carry the kind, span, confidence and
reason, never the value.
from pygarble.screening import PIIDetector
detector = PIIDetector()
report = detector.detect("call +14155550123 or mail jane@example.com")
assert [(f.kind, f.confidence) for f in report] == [
("phone", 0.9),
("email", 0.9),
]
uk = PIIDetector(locales=["uk"])
assert [f.kind for f in uk.detect("NI AB123456C, NHS 943 476 5919")] == [
"nino",
"nhs_number",
]
assert detector.detect("icon name@2x.png") == ()
Kinds¶
Kind |
Locale |
Shape |
Confidence |
|---|---|---|---|
|
all |
|
0.9 |
|
all |
E.164 ( |
0.9 |
|
all |
13 to 19 digits with a known brand prefix and a valid Luhn check |
1.0 |
|
all |
country code, valid mod-97 check and the country’s length |
1.0 |
|
all |
address structure |
0.7 |
|
us, uk, in |
national formats; US numbers follow the NANP rule |
0.8 |
|
us |
|
0.8 |
|
uk |
National Insurance number, |
0.9 |
|
uk |
ten digits with a valid mod-11 check; 0.9 with a keyword nearby, 0.8 when spaced without one |
0.8 / 0.9 |
|
in |
twelve digits with a valid Verhoeff check |
1.0 |
|
in |
Permanent Account Number, |
0.9 |
Locale packs¶
locales defaults to ("us", "uk", "in"). Each pack adds its national
phone format and identifiers: us adds ssn_us; uk adds nino
and nhs_number; in adds aadhaar and pan. Pass kinds or
exclude_kinds to select individual rules.
Matching rules¶
Bare NHS and Aadhaar digit runs need a keyword nearby.
Digit rules stop at word characters, so a number glued to letters, such as
order12345678, is not matched.A phone outranks a keyword-less NHS number on the same span, and a keyword-less NHS number nested inside a phone is dropped.
Names, postal addresses and free-text dates of birth are not detected.
Implementation and optional coverage¶
Native patterns and checksums live in pygarble/screening/pii/. Existing
pygarble.pii imports remain compatibility pointers to the same objects.
The phonenumbers backend adds numbering-plan validation; stdnum adds
selected identifier validators. Enable them on
pygarble.screening.Scanner; constructing PIIDetector continues
to run native rules only. See Standalone screening and optional backends for supported
formats and the difference between native locales and backend region.