Blog / Security and privacy

How do you filter PII in a RAG or enterprise search API?

By the troveGEN team · Updated 11 November 2026 · 3 min read

Short answer

To filter PII in a RAG or enterprise search API, detect sensitive values before they are indexed, replace them with tokens kept in a separate vault, enforce permissions inside every query, and make sure prompts and logs never contain the raw values. One layer is not enough, because PII can leak at several points.

With troveGEN

troveGEN filters PII at the source: high-risk identifiers become tokens before anything is embedded, real values stay in an encrypted vault, and restoring one is permissioned and audited.

See what troveGEN provides ↓

Where PII leaks in a search API

  • In the index: passages copied from documents carry the raw values.
  • In the vectors: embeddings can carry traces of the text they encode.
  • In results: a search response returns text to whoever asked.
  • In prompts: retrieved passages are sent to a language model, possibly hosted by a third party.
  • In logs and caches: questions and passages are often written down for debugging.

Layers that work together

  • Ingestion: detect structured identifiers with patterns and checksums, and use a model for names and addresses.
  • Indexing: replace values with stable tokens such as [ACCOUNT_1], and keep the real values in an encrypted vault outside the index.
  • Query time: enforce who may see which documents inside the search, and decide who, if anyone, may restore a token to its real value.
  • Output: check answers and results before they leave the system.
  • Logs: record that a value was masked or restored, never the value.

Block, mask or tokenize

Blocking removes a document or passage from search entirely. Redaction deletes the value. Masking shows part of it. Tokenization keeps a placeholder that stays consistent, so the same account number is always the same token and search still works, while the real value sits in a separate store. Tokenization usually keeps the most usefulness.

The accuracy trade-off

Over-redaction hurts retrieval. If every name, number and address is removed, passages lose what makes them findable, and harmless values such as product codes may be removed by mistake. Redact the high-risk identifiers reliably, and handle lower-risk contact details according to policy.

Questions to ask of any search API

  • Is sensitive data protected before it is embedded, or only when it is displayed?
  • Can a caller restore a masked value, who decides, and is each restoration logged?
  • Does deleting a document remove its vault entries and vectors?
  • What do the logs contain?
  • Which values does detection miss, and what covers that gap?

Key takeaways

  • Protect PII before indexing, then enforce permissions inside every query.
  • Tokenize rather than delete when you still need search to work.
  • Keep raw values out of prompts and logs, and make restoration permissioned and audited.

How troveGEN helps with PII filtering in search

troveGEN detects high-risk identifiers such as account numbers, card numbers, national IDs and medical record numbers before embedding and replaces them with tokens, with the real values held in a separate encrypted vault. This applies on every plan. Search results and model prompts carry tokens; restoring a value is permission-gated and audited; contact details can optionally be masked as well; and deleting a document removes its vault entries. This is a technical control, not legal advice.

What troveGEN provides

  • Detection of account, card, national ID and medical record numbers before embedding
  • Tokens in the index, search results and model prompts
  • Permission-gated, audited restoration of real values
  • Optional masking of contact details such as email and phone
  • Deletion that also removes the document's vault entries

See how data is protected Start free — 500 pages a month

Frequently asked questions

What is a search API with PII filtering?

A search API that finds and protects personal data before or during retrieval, so results and prompts do not expose raw identifiers to people or models that should not see them.

Is filtering at display time enough?

Usually not. The raw value would still sit in the index, the embeddings and perhaps the logs. Protect it before indexing and add access control on top.

Can a model hallucinate PII?

It can repeat values it was shown, which is why prompts should carry tokens instead of raw values wherever possible.

Does this make me compliant?

It supports compliance but does not guarantee it. Take legal advice for your jurisdiction and data.

How does troveGEN help with PII filtering in search?

troveGEN filters PII at the source: high-risk identifiers become tokens before anything is embedded, real values stay in an encrypted vault, and restoring one is permissioned and audited. It provides: Detection of account, card, national ID and medical record numbers before embedding; Tokens in the index, search results and model prompts; Permission-gated, audited restoration of real values; Optional masking of contact details such as email and phone; Deletion that also removes the document's vault entries.

Keep reading