The decision
- Context
- Some of the documents our AI application grounds answers in carry personal and sensitive data. Whatever reaches the index can reach a prompt and an answer, and an embedding is not anonymisation, so sensitive values had to be found and removed before chunking and embedding.
- Options weighed
- Hand-written pattern rules in the pipeline
- A managed PII detection API, called from the pipeline
- Presidio, run inside the ingestion pipelines chosen
- Consequences
- Sensitive values are masked before chunking and embedding, before anything reaches the index.
- Documents are cleaned where they are processed; nothing is sent to another service for detection.
- Detection is probabilistic, so it has to be tuned and measured rather than assumed.
- What is masked in the index stays masked; a use case that needs the original value reads it from the source system, under that system's permissions.
Context
Some of the documents our AI application answers from carry personal and sensitive data. Retrieval does not know what is sensitive: whatever sits in the index can be retrieved into a prompt and repeated in an answer. Embeddings do not hide it either. Morris and colleagues showed in 2023 that short texts can be recovered almost word for word from their embeddings. So the place to remove sensitive values is before chunking and embedding, in the ingestion pipelines.
Why Presidio
It runs where the documents already are. Presidio is an open-source library, so it runs inside our ingestion pipelines as one more step before chunking. Documents are cleaned where they are processed instead of being sent to another service for detection.
Detection that can be extended. Presidio's analyzer combines a named-entity model with pattern recognisers, checksums and the context words around a match. Custom recognisers cover identifiers specific to one organisation, next to the built-in ones for names, emails, phone numbers and the like.
Masking chosen per entity. Its anonymizer replaces, redacts, masks, hashes or encrypts each finding. Replacing a name with a typed placeholder such as <PERSON> keeps the sentence readable for retrieval, where redaction leaves a hole the embedding model has to guess around.
What it costs
Detection is probabilistic, so it has to be tuned rather than trusted: measure what gets masked and what gets missed on representative documents, and adjust recognisers and thresholds. The two kinds of error are not equal. A false positive masks a product or a place name and quietly makes retrieval worse; a miss leaves the value in place. So favour recall for the entities that matter most, and watch precision through retrieval quality.
Every document also pays for one more processing step, and masking at ingestion is final for the index: a use case that needs an original value reads it from the source system, under that system's own permissions.
When it is the wrong layer
If some users must see the unmasked text, masking at ingestion cannot serve them. Their access has to be enforced at retrieval instead, with per-document permissions on an index that holds the original.
Key takeaways
- Clean sensitive data before chunking and embedding. An embedding is not anonymisation.
- Run detection where the documents are already being processed.
- Measure detection on your own documents, and tune for recall where a miss costs more than a false mask.
About this decision note
- Format
- Decision note
- Level
- Architect
- Read
- 1 min read
- Published
- Oct 17, 2026
- Disciplines
ADR-style: context, options, the call, consequences.
More on these topics
Checklist · · 18 checks
When to bring in a compliance review
The changes that should pull legal, privacy or compliance into an AI project early, and what to have ready when you do. Not legal advice; a way to ask at the right time.
Checklist · · 29 checks
Security review checklist for an AI feature
What to check before an assistant, RAG app or agent goes in front of real users. Grouped by area, ticked off locally; progress stays in your browser.
Explainer · · 2 min read
You cannot instruct a model into data protection
Minimise what enters context, watch the paths data can leave by, and keep the evidence an incident will demand.
Discussion