Engineering

PII redaction for AI pipelines: techniques, trade-offs and where to put it

For AI pipelines, combine rules and entity detection to mask unneeded personal details before indexing and model calls, then test what the redaction misses.

Erik Salo AkimovErik Salo Akimov Co-founder · EngineeringPublished · Updated · 5 min read

Key takeaways

  • Combine rules (IDs, phones, IBANs) with an NER model for names and places.
  • Redact at ingestion, and again before inference.
  • Measure recall on your own data, not on a benchmark.
  • Log what was redacted, never the original values, and remember that redacted data can still be personal data.

Redaction reduces risk, but it is not automatically anonymisation

Combine format rules for identifiers with named entity recognition for names and contextual details. Redact personal data the task does not need before indexing and before model calls, including user prompts. Test on your documents and transcripts. Masking reduces exposure, but GDPR still applies if someone can identify a person from the remaining text or a separate mapping.

Techniques

ApproachGood atMisses
Regex / rulesIDs, phones, emails, IBANsNames, free-text context
Rules with validationIBANs checked by their checksum, Spanish DNI and NIE checked by their control letterAnything without a fixed format
NER modelNames, places, organisationsRare formats, domain codes
Dictionary lookupKnown names, departments, product and clinic codesAnything not in the list
HybridBothNeeds tuning per domain

How to replace what you find

StrategyExampleUse when
Plain mask[REDACTED]The value is not needed for the task
Typed placeholder[PERSON_1], [IBAN]The model needs to know what kind of thing was there
Consistent tokenThe same person is always [PERSON_1] in a documentThe model must follow who did what
GeneralisationA birth date becomes a year, a postcode becomes a regionSome detail is useful but the exact value is not
Synthetic replacementA realistic fake nameText must read naturally, but beware of mistaking fakes for real people

Where redaction belongs

Redact once when data enters the system, and again right before any call to a model. The second pass catches whatever a user typed straight into a prompt.

  • At ingestion, before documents are chunked, embedded and stored.
  • Before every model call, on the prompt as well as on the retrieved passages.
  • In logs and traces, so that monitoring does not become a second copy of the raw data.
  • On outputs, where a model might repeat something it should not.

Why speech pipelines are harder

In speech, the identifiers are spoken. A phone number arrives as a string of digit words, an ID is read out letter by letter and a name may be misrecognised before any redaction rule sees it. The sensible order is to transcribe first, redact the text, and only then pass it to a language model. Test the redaction on transcripts, not on typed text, because the errors are different.

How to measure whether it works

  1. Assemble a labelled sample of your own documents or transcripts, in every language you handle.
  2. Mark every personal detail a person would want removed.
  3. Run your redaction and compare, entity by entity.
  4. Track recall first, because a missed name is a leak, and precision second, because over-redaction destroys meaning.
  5. Rerun the test whenever you change a model, a rule or a language.
  6. Sample real outputs in production every week and add what you find to the test set.

Log what was redacted, such as the entity type and position, but never the original values. A redaction log full of the original names defeats its own purpose.

Common failures

FailureCauseFix
A rare or foreign name slips throughNER trained mostly on common namesAdd a dictionary for known people and test per language
A drug name is replaced as if it were a personOver-eager NERAdd a domain allow-list and review false positives
An ID split across two lines survivesRules applied line by lineNormalise whitespace before matching
Personal data in file names, metadata or URLsOnly the body text was redactedRedact metadata and sanitise names on ingestion
Raw text in logsLogging happens before redactionMove redaction ahead of the logger

Tell us which documents, languages and identifiers your pipeline handles. We can design and test redaction before data reaches your model or logs.

Discuss your redaction pipeline

FAQ

Can redaction be reversed?

Only if you keep a mapping. Store it separately with tighter access, or don't store it at all.

Is redacted data anonymous?

Not automatically. If the remaining text could still be linked back to a person, it remains personal data under the GDPR, so keep the other safeguards in place.

Do we still need redaction if the model is hosted in the EU?

Yes, in most regulated work. EU hosting settles where the data is processed. Redaction limits what the model, its logs and its operator ever see, which lowers the damage of any mistake.

Sources

  1. Regulation (EU) 2016/679 (GDPR), Article 4(1) and (5) and Recital 26
  2. European Data Protection Board, Guidelines 01/2025 on pseudonymisation
  3. OWASP Top 10 for LLM Applications, sensitive information disclosure
Erik Salo Akimov

About the author

Erik Salo Akimov · Co-founder · Engineering

Erik runs engineering at ESADEX. He designs the platforms, infrastructure and security controls that sit behind client systems.

Build your compliant AI or software project

Tell us your workflow and compliance requirements. We reply within four business hours and usually prepare a scope and architecture document in about five days.