Description
ssn_filter.py and ein_filter.py compile the same regular expression, and each attributes it to
a different entity type.
phileas/filters/ein_filter.py:34:
_PATTERNS = [
# Canonical EIN: NN-NNNNNNN. A neighbouring hyphen makes it part of a longer
# identifier, not an EIN (philterd/phileas#343).
re.compile(r"(?<![\w-])\d{2}-\d{7}(?![\w-])"),
]
phileas/filters/ssn_filter.py:41:
# TIN: NN-NNNNNNN, the shape the ein filter also detects. Scored below the SSN
# forms so `ein` wins the span wherever both filters are enabled.
_TIN_PATTERNS = [
re.compile(r"(?<![\w-])\d{2}-\d{7}(?![\w-])"),
]
_TIN_CONFIDENCE = 0.90
The comment is candid about the duplication: the copy in the SSN filter exists only to be outscored
by the filter that already detects the same thing. Span.drop_overlapping_spans keeps the
highest-confidence span, and EINFilter runs at the default 1.0 against this 0.90, so the ein
span wins whenever ein is enabled. When it is not, a value matching NN-NNNNNNN is reported as an
SSN.
Why remove it rather than keep it as a fallback
PhiSQL's entity catalog declares no TIN entity type and describes NN-NNNNNNN as the EIN format.
It is: ITINs and ATINs are SSN-shaped (NNN-NN-NNNN) and PTINs are P followed by eight digits, so
the only taxpayer number written NN-NNNNNNN is an EIN. A span reported as ssn for that value is
mislabelled, gets the SSN filter's strategies applied, and reaches a reviewer as a Social Security
Number.
EINFilter already exists, is registered in _BUILTIN_FILTERS (filter_service.py:71), and its
pattern already carries the adjacent-hyphen boundary fix. Nothing has to be built: the fix is to
delete the copy.
Behaviour change to call out
A policy that enables ssn and not ein stops detecting NN-NNNNNNN. That is the intent, but it
is a detection regression for anyone relying on the current behaviour and needs a release note that
says so plainly.
Acceptance criteria
Related
philterd/phileas#390 does the same removal in the Java port, where the pattern also has to be
moved rather than deleted, because that port's EinFilter lacks the hyphen and wrap handling
this port's already has.
philterd/phileas-dotnet#95 covers the .NET port, which never carried the duplicate.
Description
ssn_filter.pyandein_filter.pycompile the same regular expression, and each attributes it toa different entity type.
phileas/filters/ein_filter.py:34:phileas/filters/ssn_filter.py:41:The comment is candid about the duplication: the copy in the SSN filter exists only to be outscored
by the filter that already detects the same thing.
Span.drop_overlapping_spanskeeps thehighest-confidence span, and
EINFilterruns at the default 1.0 against this 0.90, so theeinspan wins whenever
einis enabled. When it is not, a value matchingNN-NNNNNNNis reported as anSSN.
Why remove it rather than keep it as a fallback
PhiSQL's entity catalog declares no TIN entity type and describes
NN-NNNNNNNas the EIN format.It is: ITINs and ATINs are SSN-shaped (
NNN-NN-NNNN) and PTINs arePfollowed by eight digits, sothe only taxpayer number written
NN-NNNNNNNis an EIN. A span reported asssnfor that value ismislabelled, gets the SSN filter's strategies applied, and reaches a reviewer as a Social Security
Number.
EINFilteralready exists, is registered in_BUILTIN_FILTERS(filter_service.py:71), and itspattern already carries the adjacent-hyphen boundary fix. Nothing has to be built: the fix is to
delete the copy.
Behaviour change to call out
A policy that enables
ssnand noteinstops detectingNN-NNNNNNN. That is the intent, but itis a detection regression for anyone relying on the current behaviour and needs a release note that
says so plainly.
Acceptance criteria
_TIN_PATTERNSand_TIN_CONFIDENCEare removed fromphileas/filters/ssn_filter.py, andSSNFilter.detectreturns only the SSN forms.NN-NNNNNNNproduces a span typedein, neverssn.EINFilteris unchanged: it already covers the shape and already excludes an adjacent hyphen.ssndoes not detect12-3456789, and that oneenabling
eindoes.pattern.
documentation is the place the
NN-NNNNNNNform is described.RELEASE_NOTES.mdrecords the change, stating that a policy enabling onlyssnno longerdetects
NN-NNNNNNN.Related
philterd/phileas#390does the same removal in the Java port, where the pattern also has to bemoved rather than deleted, because that port's
EinFilterlacks the hyphen and wrap handlingthis port's already has.
philterd/phileas-dotnet#95covers the .NET port, which never carried the duplicate.