The story is always a version of the same story. The pilot worked. The team shipped to production. Then a customer pasted a billing question into a support chat, complete with a credit card number and a date of birth. The model summarized the conversation into an internal ticketing system. The ticket got CC’d into a Slack channel. The Slack channel was archived into a vector store used for the next month’s RAG training. By the time anyone noticed, that credit card number existed in seven systems and three vendor logs.
PII in LLM pipelines is not a model problem. It is a data-flow problem. The model is one of a dozen places PII can land: in prompts sent to third-party APIs, in retrieved context, in logs, in traces, in vector embeddings, in eval datasets, in training corpora. The 2025 OWASP Top 10 for LLM Applications calls this out as LLM02 (Sensitive Information Disclosure) for exactly this reason: the leakage surface is the entire system around the model, not the model itself.
This guide is the architecture that holds up in production. It is the one we deploy when a team needs HIPAA, GDPR, or EU AI Act compliance and “we’ll just tell the model not to log PII” is no longer an answer.
What Counts as PII for LLM Pipelines
The legal definitions vary by jurisdiction. The engineering definition is broader than any of them: anything that, alone or in combination with other fields, can re-identify a person or expose regulated data. In practice, your detection coverage needs to span four categories.
| Category | Examples | Detection difficulty |
|---|---|---|
| Direct identifiers | Names, emails, phone numbers, SSN, passport, account numbers | Easy (regex + NER) |
| Quasi-identifiers | DOB, ZIP code, employer, IP address, device ID | Medium (context-dependent) |
| Regulated data | PHI (HIPAA), payment cards (PCI), financial accounts (GLBA), biometrics | Easy on patterns, hard on context |
| Free-text leakage | Diagnoses in clinical notes, salary in resumes, allegations in HR transcripts | Hard (LLM-assisted detection needed) |
Most teams handle the first two well, fail on the third in edge cases, and have no story for the fourth. A production redaction pipeline has to cover all four.
This is one of the system layers underneath the chat box that we wrote about in why your AI experiments are failing. The model is one piece. The pipeline is the rest.
Where PII Enters and Exits an LLM Pipeline
If you cannot draw the diagram, you cannot defend the system. The seven surfaces where PII typically enters or exits:
- User input. Direct user messages.
- Retrieved context. Documents, knowledge base articles, prior conversations pulled into the prompt.
- Tool returns. API responses, database queries, CRM records.
- Model outputs. What the model writes back, which may contain echoed input or hallucinated PII.
- Logs and traces. Application logs, LLM provider logs, tracing platforms (Langfuse, LangSmith, Arize, Datadog).
- Vector embeddings. Embedded chunks in a vector store, which preserve enough signal to leak the original text in practice.
- Training, fine-tuning, and eval datasets. Curated from production traffic and quietly inheriting whatever was in production traffic.
A production redaction pipeline addresses all seven. Most teams address one or two and then are surprised when an auditor finds PII in their LangSmith traces.
The Tiered Detection Stack
There is no single detector that is both fast enough and accurate enough across all PII categories. The architecture that works is tiered, with each tier optimized for a different latency-accuracy tradeoff.
Tier 1: Regex and Checksum (Sub-Millisecond)
The first tier catches everything that has a deterministic format: credit cards (Luhn-validated), SSNs, IBANs, passport numbers, phone numbers in major locales, email addresses, URLs, IP addresses. These are highly reliable and effectively free latency-wise.
This tier alone catches 50–70% of PII volume in most pipelines, simply because most PII has a structure.
Tier 2: Secret and Token Entropy (Single-Digit Milliseconds)
API keys, JWT tokens, SSH keys, and high-entropy strings need entropy-based detection. Tools like detect-secrets and entropy scoring catch the leakage class where a user pastes a credential into a chat, which is more common than teams expect.
Tier 3: Named Entity Recognition (Tens of Milliseconds)
NER catches names, addresses, organizations, and other entities that have no fixed format. Microsoft Presidio is the de facto open-source standard here: it uses spaCy or Stanza models by default, supports custom recognizers, runs on-prem, and has a configurable anonymization step. It handles English well; non-English coverage varies by model.
For higher accuracy on edge cases, GLiNER and the newer instruction-tuned NER models (purpose-trained on PII rather than general entities) outperform classical NER, at a small latency cost.
Tier 4: LLM-Assisted Detection for Free-Text Leakage (Hundreds of Milliseconds)
The hardest category, free-text leakage in clinical notes, HR transcripts, legal documents, requires an LLM-based classifier. You send the chunk to a smaller model with a prompt like “list any segments of this text that disclose personal health information, named individuals’ diagnoses, salary figures, or other sensitive personal data.”
This tier is expensive. Reserve it for high-compliance workloads (HIPAA, GDPR Article 9 special-category data) and run it asynchronously when possible.
Tier 4 needs its own data-handling policy
The LLM-assisted detector is itself receiving PII. Run it on a model and infrastructure that meets the same compliance bar as the rest of your pipeline. Sending PHI to a public API for redaction defeats the redaction.
Redaction Strategies: Mask, Tokenize, or Reverse
Detecting PII is half the job. What you do with it matters as much as whether you found it.
| Strategy | What it does | When to use |
|---|---|---|
| Mask | Replace PII with a placeholder ([REDACTED], <EMAIL>) | One-way flows: logs, vector embeddings, telemetry, training data |
| Pseudonymize | Replace with a stable but non-reversible synthetic value (e.g., John Smith → Person_a3f2) | When the model needs to track a referent across turns but never see the real value |
| Reversible tokenize | Replace with an opaque token, store the mapping in a secured vault, restore on the way out | When the user needs to see the original value but the model and downstream systems should not |
| Encrypt-then-summarize | Selectively encrypt PII fields, allow only authorized renderers to decrypt | When a tool return includes sensitive fields that some consumers see and others do not |
The reversible-tokenization pattern, sometimes called “PII proxy” or “privacy gateway,” is the most powerful for chat applications. The flow:
- User input enters the gateway.
- Detected PII is replaced with tokens (
<PERSON_001>,<EMAIL_001>) and the original values are stored in a short-lived encrypted vault keyed to the session. - The tokenized prompt is sent to the LLM. The model never sees real PII.
- The model’s response references the tokens.
- The gateway substitutes tokens back to real values before the response is delivered to the user.
Microsoft’s PII Shield, Skyflow, Private AI, and Nightfall implement variants of this pattern. The same architecture is straightforward to build in-house on top of Presidio plus a vault (HashiCorp Vault, AWS KMS, or a session-scoped Redis with encryption at rest).
Where in the Pipeline to Place the Filter
Two production patterns dominate. They have real tradeoffs.
Pattern A: Gateway-Side Redaction
A single proxy layer sits between your application and the LLM provider. Every prompt and every response passes through it. Detection and redaction happen once, in one place.
- Strengths: Single point of enforcement, easy to audit, easy to swap LLM providers without touching every call site.
- Weaknesses: Adds 50–300ms to every call depending on tier depth; concentrates a sensitive workload in one service; harder to apply use-case-specific redaction rules.
Pattern B: Application-Side Redaction
Each application call site does its own detection and redaction, often using a library like Presidio directly or Guardrails AI validators.
- Strengths: Lower latency per call (no extra network hop), use-case-specific rules are natural, easier to ship incrementally.
- Weaknesses: Easy to forget a call site; harder to audit; inconsistent across teams; PII still ends up in shared logs unless every team independently scrubs them.
The pattern that holds up in production: a gateway for the LLM call boundary plus application-side scrubbing for logs, traces, and persistent stores. The gateway handles “data sent to the model.” The application handles “data stored by the application.” Both layers are necessary; neither replaces the other.
This is also why multi-tenant AI applications need a gateway pattern at the tenant boundary: per-tenant policy is much harder to enforce when each service does its own redaction.
Don’t Forget the Telemetry Layer
The leakage we see most often in audits is not in the LLM call. It is in the trace.
LLM observability platforms (Langfuse, LangSmith, Arize, Helicone, Datadog LLM observability) capture full prompts, full responses, and full tool calls by default. That is exactly the data they need to be useful. It is also a complete copy of every piece of PII that traversed the pipeline.
Three controls that matter:
- Scrub before logging. Run redaction before the trace is emitted, not after. After-the-fact scrubbing is a regulatory disclosure waiting to happen.
- Sample for sensitive traffic. Full prompt/response capture for 1% of HIPAA traffic still creates an audit problem on the 1%. Sample with explicit consent or use redacted-only capture for those workloads.
- Vendor data-handling agreements. If you send unredacted prompts to a third-party trace platform, you have extended your compliance perimeter to that vendor. Make sure your DPA covers it.
For the broader observability picture, see AI agent observability and monitoring AI agents in production. PII handling is one of the dimensions an observability stack has to get right.
Ship a PII redaction pipeline that survives an audit
If your team is taking an AI application into a regulated environment, HIPAA, GDPR, EU AI Act, our engineering pods design and ship the gateway, vault, and telemetry pattern end-to-end. Start with an AEMI assessment to map your current PII exposure across the pipeline.
Compliance Hooks: HIPAA, GDPR, EU AI Act
Regulators do not care about your architecture diagram. They care about evidence. Each regime asks the same questions in different words: where does sensitive data live, who can access it, when is it removed, and how do you prove it.
- HIPAA. PHI sent to an LLM provider requires a Business Associate Agreement. Many production teams use tokenization specifically to keep PHI from ever traversing the provider boundary, which sidesteps the BAA question for that flow. Logs and traces still need de-identification per the Safe Harbor or Expert Determination methods.
- GDPR. Article 5 minimization principles favor the tokenization pattern over storing raw PII. Article 32 expects technical controls (encryption, pseudonymization) on personal data. Article 9 special-category data (health, biometrics, political views, etc.) typically requires Tier 4 detection coverage.
- EU AI Act. Enforcement powers for general-purpose AI model providers begin 2 August 2026. The transparency and risk-management obligations interact with PII handling: documented data flows, logged processing, and human oversight for high-risk uses. Under the omnibus amendments, high-risk AI systems have a transition period to 2 August 2028, but the GPAI obligations and transparency rules are live.
For sector-specific patterns, the deeper guide is AI agents in regulated industries, and for the broader security model, AI agent security architecture.
Embeddings are not redacted by redacting the source
A common failure mode: a team redacts user-facing text but stores the unredacted version as the embedding source. The embedding preserves enough semantic signal that the original text can be approximately reconstructed or memorized. Embed the redacted version, not the raw text. If you need raw text for retrieval relevance, store it encrypted and retrieve it post-vector-match through an authorized channel.
A Pragmatic Sequencing for Teams Shipping This Quarter
The architecture above is the target. The path to it:
- Week 1: Inventory PII surfaces. Map the seven surfaces in your pipeline. You cannot redact what you have not located.
- Week 2: Deploy Tier 1 (regex + checksum) and Tier 3 (Presidio NER) at the LLM gateway. This catches the majority of volume with low latency.
- Week 3: Scrub logs and traces. Configure Langfuse/LangSmith/Arize to receive pre-redacted payloads. Audit existing trace stores and purge what should not be there.
- Week 4: Switch the most sensitive flow to reversible tokenization. Build the vault. Run it for one use case end-to-end.
- Week 5: Embed redacted text in the vector store. Re-embed the existing corpus if needed.
- Week 6+: Add Tier 4 LLM-assisted detection for high-compliance workloads. Run asynchronously where you can.
The ordering matters. Most teams start at Tier 4 because it is the most impressive demo. They run out of latency budget and revert. Start with the cheap, deterministic tiers and add the expensive ones where they are warranted.
This is one layer of the system underneath the chat box, the gap between a model that demos well and a production AI pipeline that does not produce a regulatory disclosure on its first audit. metacto’s Operational AI practice exists for exactly this gap; for teams earlier in the journey, the AEMI assessment is the fastest way to find out which surfaces in your pipeline are currently exposed.
PII Redaction in LLM Pipelines: Frequently Asked Questions
How do I redact PII before sending data to an LLM?
Use a tiered detection stack at a gateway between your application and the LLM provider. Tier 1 is regex and checksums for structured PII (credit cards, SSNs, emails); Tier 2 is entropy detection for secrets and tokens; Tier 3 is Named Entity Recognition (Microsoft Presidio is the standard) for names and addresses; Tier 4 is LLM-assisted detection for free-text leakage in clinical or legal documents. The most powerful pattern is reversible tokenization: replace detected PII with opaque tokens, store the mapping in a secured vault, and restore the original values on the way back to the user. The model never sees real PII.
Is Microsoft Presidio enough for production PII redaction?
Presidio is the right starting point but rarely the whole answer. It handles regex, NER, and customizable recognizers well, runs on-prem, and integrates with vault and anonymization tooling. It does not, by itself, handle entropy-based secret detection, LLM-assisted detection for free-text leakage, or reversible tokenization at the gateway level. Production pipelines typically combine Presidio for Tier 1 and Tier 3 detection with additional tooling (or in-house code) for entropy detection, free-text classification, and the gateway + vault pattern.
Where should I redact PII in an LLM pipeline?
Two layers, both required. A gateway layer between your application and the LLM provider handles 'data sent to the model' and is the right place for the heavy detection stack and reversible tokenization. An application layer handles 'data stored by the application' and is the right place for scrubbing logs, traces, vector embeddings, and persistent stores. Forgetting the second layer is the most common failure: teams redact prompts but log unredacted prompts to their observability platform, which becomes the audit finding.
Does redaction hurt LLM accuracy?
It can, but less than teams expect. Replacing structured PII (cards, SSNs) with placeholders rarely matters because the model is not using the numeric value for reasoning. Replacing names with stable pseudonyms (`Person_a3f2`) preserves coreference across turns, which is what most chat applications need. The accuracy hit shows up in tasks where the model needs the actual value (computing distance between two ZIPs, formatting a real address). For those cases, reversible tokenization restores the value at the appropriate downstream step rather than the model step.
How does PII redaction support HIPAA and GDPR compliance?
Redaction supports both regimes by minimizing the data sent to and stored by systems that do not need it. For HIPAA, sending PHI to a third-party LLM provider requires a Business Associate Agreement; tokenization can keep PHI from traversing the provider boundary entirely, which simplifies the compliance posture. For GDPR, Article 5 minimization, Article 32 technical controls, and Article 9 special-category data handling all favor pseudonymization or tokenization. The EU AI Act's transparency and risk-management obligations (enforcement powers for GPAI providers from 2 August 2026) interact with PII handling through documented data flows and logged processing.
Should I embed raw text or redacted text in my vector store?
Embed the redacted text, with one caveat. Embeddings preserve enough semantic signal that the original PII can be approximately reconstructed or memorized by downstream consumers, so the embedding itself is a PII surface, not a safe representation. If you need raw text for retrieval relevance (e.g., matching on a specific name), store the raw text in an encrypted, authorized-access store and retrieve it through a permitted channel after the vector match. The vector index gets redacted text; the high-trust retrieval path gets the raw version.