Twenty-four of the 71 card numbers in this lesson’s demo corpus went straight through stock Presidio. The detector wasn’t weak. Its credit-card regex only starts at 4, 50–55, 6, 1 and 3, and Mastercard’s 2-series range (2221–2720) has been in circulation since 2017. spaCy then saw sixteen unclaimed digits, labeled them DATE_TIME at 0.85 confidence, and the policy table said dates are safe to keep. Every component did exactly what it was built to do. The training set still got the cards.
What the pipeline actually does
PII masking for training is a batch transform between the raw data lake and the training jobs. Text comes out still teaching grammar, intent and structure, with specific people unrecoverable, and that output is the only thing a trainer may read.
Five stages, in order:
Detect. A NER model plus pattern recognizers emit candidate spans with a type and a score. Candidates overlap constantly. The bare number 3838016613 comes back as DATE_TIME (0.85), PHONE_NUMBER (0.4) and US_BANK_NUMBER (0.05).
Resolve. Collapse overlapping candidates into one decision per region of text.
Transform. Redact (
<CREDIT_CARD>) anything with no training value. Pseudonymize identities with a keyed hash (<PERSON_3fa9c2d1>), so the model still learns that the same customer wrote twice. Swap IPs for format-preserving surrogates inside 10.0.0.0/8, so the model stays fluent in the syntax but can never emit a routable address.Audit the output with something other than the detector.
Gate: release to the curated store, or hold in staging.
Resolution is where pipelines leak, and they leak quietly. The usual default is highest-score-wins: sort by confidence, drop anything that overlaps a winner. For that bare number, DATE_TIME outranks PHONE_NUMBER, DATE_TIME’s policy is keep, and the phone number ships. The fix is to cluster overlapping candidates and apply the most restrictive policy present anywhere in the cluster, covering the union of the spans that want masking. On the demo’s clean synthetic corpus (seed 2026), highest-score-wins leaked 3.37% of sensitive values. Most-restrictive leaked 0.66%. Same detector, same candidates.
The cost is over-masking: a real date overlapping a weak phone candidate gets pseudonymized. I’ll take that trade every time.
The step people skip is normalizing before hashing. “+1 (415) 555-0132” and “415.555.0132” must produce the same token, or one customer becomes two strangers.


