RAG PII redaction is the process of finding and removing personally identifiable information from the documents a retrieval system indexes, so that personal data never reaches a generated answer. A RAG pipeline that indexes raw support tickets, contracts or HR records will eventually quote a customer email address or an employee salary back to the wrong person. So how do you stop that happening? You redact PII before indexing, you verify the redaction with tests, and you treat any data that slips through as an incident to be fixed at the source.
Redaction is not a single tool or a one-off task. It is a layer in the pipeline that sits between your documents and your index, and it needs the same care as retrieval itself. Get it right and users can search freely across a knowledge base that contains no personal data at all. Get it wrong and every answer becomes a potential privacy breach.
Key takeaways
- Redact PII before indexing, not after retrieval — data in the index is data that can leak.
- Combine pattern matching for structured PII with named-entity recognition for names and free-text identifiers.
- Redaction is lossy: replacing values with tokens protects privacy but can weaken retrieval, so test both.
- Some PII cannot be detected reliably by rules alone, so sample and review real documents regularly.
- Log redaction decisions and keep an audit trail of what was removed, when and by which rule.
What counts as PII in a RAG corpus
Personally identifiable information is any data that can identify a person, directly or when combined with other data. The obvious cases are names, email addresses, phone numbers, postal addresses and government ID numbers. The less obvious cases cause most of the leaks: account numbers buried in support threads, salary figures in HR documents, medical record numbers in clinical notes, and IP addresses in server logs that were swept into the knowledge base by mistake.
Context decides what counts. A company name in a public press release is not PII. The same company name in a document that also lists its directors’ personal phone numbers sits in a very different category. Your redaction policy should name the data types you treat as PII for each source, rather than relying on a generic list. A support corpus needs different rules from a legal corpus, and both differ from an HR corpus.
Quasi-identifiers deserve special attention. A job title, a department and a start date may each look harmless, but together they can single out one person in a small team. Redaction that only removes names and email addresses leaves these combinations intact. If your documents describe small groups of people, treat combinations of attributes as PII too.
Where redaction belongs in the pipeline
The safest place to redact is at ingestion, before text is chunked or embedded. Once PII is embedded into a vector, removing it means deleting and re-indexing the affected chunks. Once it is retrieved, it can appear in an answer, a log or a cached response. Redacting early keeps personal data out of every downstream store at once: the index, the retrieval log, the prompt cache and the evaluation dataset.
That said, ingestion is not the only layer worth having. A second check at retrieval time catches anything the first pass missed, and it protects against documents that entered the index through a path that skipped redaction. A third check at generation time — scanning the draft answer for PII patterns before it is shown — is the last line of defence. Defence in depth costs little here, because each layer is cheap compared with the cost of a leak.
One design rule matters above the rest: never redact in place on the original document. Keep the source file intact in a controlled store, and redact only the copy that enters the RAG pipeline. Teams that overwrite originals destroy evidence they later need, and they lose the ability to re-run redaction with improved rules. The redacted copy is a derived artefact; the original stays under access control.
Redaction methods compared
No single method catches every kind of PII, so production systems combine several. Pattern matching with regular expressions is fast and precise for structured data such as email addresses, phone numbers, card numbers and national ID formats. It fails on names, job titles and anything that does not follow a fixed format.
Named-entity recognition fills that gap. A trained model can spot person names, organisations and locations in free text, including names that no pattern could describe. It is less precise than pattern matching, and it can miss unusual names or flag ordinary words as people. The trade-off is acceptable when the alternative is no coverage at all.
Dictionary and lookup approaches work well for known identifiers: employee lists, customer account numbers, internal project codenames. They are precise but brittle, because they only catch what is already on the list. Use them as a supplement, not a foundation.
| Method | Best for | Weakness |
|---|---|---|
| Pattern matching | Emails, phone numbers, card and ID numbers | Misses names and free-text identifiers |
| Named-entity recognition | Person names, places, organisations | False positives and missed unusual names |
| Dictionary lookup | Known account and employee identifiers | Only catches what is already listed |
| Manual review | High-risk documents and edge cases | Slow and does not scale |
| Large language model review | Context-dependent PII and quasi-identifiers | Costly and can itself leak data |
Large language models are increasingly used as a redaction pass, because they understand context well enough to spot quasi-identifiers that rules miss. Treat that pass with caution: sending unredacted documents to an external model for redaction can itself be a disclosure. Run such a pass on infrastructure you control, or accept that it belongs only in the ingestion stage under strict data handling rules. For a broader view of privacy-preserving techniques, see our guide to AI data anonymisation techniques.
Replacement strategies: what to put in place of PII
Removing PII leaves a hole in the text, and what fills that hole affects both privacy and retrieval quality. Deleting the value entirely is simplest, but it can break sentence structure and confuse the model. Replacing it with a generic label such as [EMAIL] preserves the shape of the sentence while removing the value.
Consistent tokenisation goes a step further: the same person always becomes the same token, such as [PERSON_1], across a document. This preserves co-reference — the model can tell that two mentions refer to the same individual — without revealing who that individual is. It is the best option when the document’s reasoning depends on tracking people across paragraphs, as support threads often do.
Hashing and format-preserving replacement are tempting but risky. A hash of an email address is still a stable identifier that can be matched against other datasets, and format-preserving replacements can be reversed if the mapping leaks. For most RAG systems, labelled tokens are the right default: simple, auditable and genuinely irreversible without a mapping table that you should not keep.
Testing redaction before you trust it
Redaction that is never tested is a hope, not a control. Build a test set of documents with known PII, run them through the pipeline, and measure what survives. The metric that matters is recall: the share of PII instances that were actually removed. Precision matters too — over-redaction destroys useful content — but a missed email address is a breach while an over-redacted paragraph is an annoyance.
Test with adversarial examples, not just clean ones. PII appears in headers, footers, signatures, quoted replies, scanned attachments and tables. It appears with typos, split across lines and written in formats your patterns never anticipated. A test set built only from tidy documents will flatter your system and hide its real gaps.
Then test the live system, not just the redactor. Query the RAG system with prompts designed to surface personal data, and check whether any answer contains it. This is the test that catches the documents that bypassed ingestion entirely. Pair it with RAG access control testing, because redaction and access control are complementary: redaction removes data that should never be in the index, while access control limits who can see what remains.

When redaction is not enough
Some documents should not enter a RAG index at all, redacted or not. Highly sensitive records — medical files, unredacted legal discovery, raw HR complaints — carry risks that redaction cannot fully remove, because context itself can identify people. For these sources, the right control is exclusion: keep them out of the general index and serve them through a separate, tightly controlled system.
Redaction also struggles with documents whose entire purpose is personal. A performance review with names removed is still a performance review of one identifiable person if the team is small. A customer complaint with identifiers stripped can still be traced back through its details. In these cases, summarisation or aggregation is a better tool than redaction: store the lesson, not the case.
Finally, remember that redaction does not fix consent. Data protection law in many jurisdictions, including the UK GDPR, requires a lawful basis for processing personal data — and indexing personal data into an AI system is processing. Redaction reduces the risk, but the legal analysis of whether the data should be processed at all still has to happen. Our guide to AI data privacy architecture covers how to structure that analysis.
Redaction checklist for your RAG pipeline
- Define which data types count as PII for each source corpus, including quasi-identifiers.
- Redact at ingestion, before chunking and embedding, and keep originals intact under access control.
- Combine pattern matching, named-entity recognition and dictionary lookups.
- Replace PII with consistent labelled tokens rather than hashes or format-preserving values.
- Measure redaction recall on a test set that includes messy, adversarial examples.
- Probe the live system with prompts designed to surface personal data.
- Log what was redacted, by which rule, and review a sample of real documents each month.
- Exclude sources that are too sensitive to index, even after redaction.
Frequently asked questions
What is RAG PII redaction?
RAG PII redaction is the removal of personally identifiable information from documents before they are indexed into a retrieval-augmented generation system. It prevents names, contact details, account numbers and other personal data from appearing in AI-generated answers.
Should I redact before or after indexing?
Before indexing, at ingestion. PII that reaches the index can surface in answers, logs and caches. Redact the copy that enters the pipeline, keep the original under access control, and add retrieval-time and generation-time checks as extra layers.
Does redaction hurt retrieval quality?
It can. Removing names and identifiers strips out terms that queries sometimes match on, and heavy over-redaction degrades chunk meaning. Consistent token replacement limits the damage, and measuring retrieval quality before and after redaction shows whether the trade-off is acceptable.
Can redaction catch every kind of PII?
No. Rules catch structured data reliably, named-entity recognition catches most names, and neither is perfect on unusual formats, typos or quasi-identifiers. That is why testing, sampling and exclusion of high-risk sources matter as much as the redactor itself.
Is redacted data still personal data under GDPR?
It depends on whether the redacted output can still identify a person. Properly redacted text with no mapping back to individuals is generally not personal data, but pseudonymised data that can be re-identified with additional information still counts as personal data under the UK GDPR. Treat borderline cases as personal data.
How often should redaction be reviewed?
Review a sample of real ingested documents every month, and re-test the full pipeline whenever rules change, new sources are added or a leak is found. Redaction quality drifts as document formats and content change, so a one-off setup quietly degrades.







