PII Redaction at the LLM Gateway Layer Before Provider Transmission
Redacting sensitive data at the gateway prevents it from ever reaching external model providers.

Sending a prompt to an external model provider is a data-sharing event, and it carries the same regulatory weight as any other third-party data transfer. The prompt an application sends to a model is rarely a simple question typed by a user. It's an assembled package: instructions, conversation history, retrieved documents, database records, and tool outputs, all stitched together into a single call to the model. Any one of those layers can carry a name, an account number, or a diagnosis, and neither the user nor the engineer who shipped the integration may ever notice it happened.
GDPR, HIPAA, and PCI DSS all place limits on where personal data, health data, and cardholder data can travel. Sending any of it unredacted to a third-party model API can itself be the violation. Once the request leaves the sending organization, control over what happens to that data belongs to the provider, not the sender. OpenAI retains API data for 30 days by default. Anthropic briefly shortened its standard API log retention window in September 2025, but then it reverted to a longer commercial baseline. Zero-data-retention terms exist, but they require separate approval for eligible API customers or enterprise accounts, and they are not what a pay-as-you-go account gets by default.
Even organizations that have negotiated zero-data-retention agreements are not covered the way they might assume. A zero-data-retention deal, the kind OpenAI offers at the enterprise tier, does not redact PII from the prompt before the model processes it. The model still needs the actual text to generate a response. Zero-data-retention only controls what happens to data after the call completes. It does nothing about what was inside the call itself. Redaction has to happen before the request ever leaves the sender's environment. The gateway layer is the enforcement point. An LLM gateway sits between the application and every provider: it applies PII policies after authentication but before transmission, so sensitive data never reaches the provider in the first place.
The regulatory clock is also moving. The EU AI Act's high-risk obligations under Annex III become enforceable on December 2, 2027, after a later EU regulation pushed back the original August 2, 2026 deadline. That extra runway is useful only for organizations that spend it building structured data controls at the point where requests actually leave for a model provider. For everyone else, the deadline arrives with the same exposure they have today, just with enforcement attached.
Application-layer redaction cannot hold the line across a real engineering organization
If you put redaction logic inside individual applications, the logic drifts apart over time, leaves gaps in coverage, and produces an audit trail you can't reassemble after the fact. Each team writes its own version of the same control, and each version ages differently.
Every new microservice, every new agent, every new team that wires up an LLM call is a fresh chance to skip the redaction step or configure it wrong. Nothing in the architecture stops this from happening. Only developer discipline does. Discipline doesn't scale the way infrastructure does, and it gives an auditor nothing to check.
Centralizing detection in a gateway creates one enforcement point that covers every application and every model provider, and it makes policy independent of any one SDK. The alternative is that every SDK integration becomes its own policy surface, each with its own chance to get it wrong. Application-layer redaction also leaves no unified audit trail: each service logs what it happens to log, in whatever format it chooses, with no central record of what was redacted, under which rule, and when. SOC 2 and GDPR audits ask for that central record.
Shadow AI makes the gap worse. If employees route requests through personal accounts or direct API keys, they bypass application-layer controls completely, because those controls were never in the request path to begin with. A control that doesn't live in the infrastructure layer isn't a control an organization can actually rely on. The common objection, that code review and CI checks can enforce the right standards without a gateway, breaks down at scale: agents, third-party integrations, and fast-moving iteration make it impossible to audit every path a prompt might take before it reaches production.
The gateway's position between every application and every provider makes consistent enforcement structurally possible
The gateway's position in the request path, after the caller is authenticated and before the request is routed anywhere, is what turns PII redaction from a policy on paper into something enforced on every single call. That position is also what makes redaction auditable. The gateway applies the same rule to every request regardless of which team or service sent it, and it records which detector fired and what action it took.
Input redaction and output redaction do different jobs. Input redaction protects the boundary with the provider: the provider only ever sees the sanitized version of the payload. Output redaction protects the caller on the way back, but it cannot undo data that has already been sent upstream, so the two hooks guard different things.
The flow is straightforward to describe without a diagram. An application or an agent sends a request. The gateway checks it against an input PII policy before anything is routed anywhere. Only after that check does the gateway route the request to a model provider. The response comes back, passes through an output PII policy, and only then reaches the caller. At every one of those stages, the gateway can deny the request, and every denial gets logged along with the reason it happened.
The gateway sits in front of every model call from every team, so a policy written once applies everywhere and no one has to remember to apply it. A new microservice or a new provider integration inherits the same rules the moment it starts sending traffic through the gateway, with no extra work from the engineer who built it. Concentrate is one production example of a gateway built around this pattern: a centralized layer sitting between applications and model providers, applying PII policy consistently across every team and every provider rather than leaving each integration to enforce its own version of the rule.
The gateway also checks what comes back from the model, not just what goes out to it. A model can echo sensitive data back from its own context window, or infer it from what it was given, so output inspection is a second, independent enforcement point rather than a repeat of the first one.
Detection mechanisms: how the gateway identifies PII before it routes the request
No single detection method covers everything a gateway needs to catch. No single detection method is sufficient; production redaction pipelines combine regex for structured identifiers with NER models for unstructured text, and the choice of combination determines both accuracy and latency.
Regex is fast and precise for data with a fixed shape, such as structured identifiers like credit card numbers and email addresses. It misses anything mentioned in free-flowing text. NER fills that gap by adding context, catching names, locations, and organizations, but it runs as a model inference step, which adds latency and introduces variance in accuracy that regex doesn't have.
Real implementations show the trade-off: the WSO2 AI Gateway ships a built-in guardrail called pii-masking-regex, and it's a regex-only detector. It catches a well-formed email address or phone number reliably, but it won't catch a sentence like "John Smith mentioned he lives on Maple Street". Catching that kind of free-text mention requires pairing the regex guardrail with a separate content-safety guardrail.
LangSmith's LLM Gateway, currently in beta, splits detection into two categories that can be turned on independently. Rule-based categories, matched by regex, cover emails, phone numbers, and SSNs, and they resolve faster to detect. Model-based categories, matched using Presidio, cover names, locations, nationality, religion, and political affiliation, and they take longer to resolve because they depend on model inference. A team can enable either category on its own, depending on what a given workload needs.
Secrets detection is handled as its own category, separate from PII, because the goal is different: anchoring to the recognizable shape of a token rather than to the meaning of a phrase. LangSmith's gateway redacts LangSmith API keys, OpenAI and Anthropic API keys, GCP API keys, Azure AD client secrets, Slack tokens, private keys, and PyPI and npm tokens. Keeping that detection narrow and shape-based means you don't get ordinary high-entropy prose flagged as a secret by mistake.
Accuracy variance deserves a direct statement rather than a footnote. A DeBERTa model fine-tuned on a fixed set of entity types performs well against the distribution it was trained on, but across broader benchmarks covering many entity types, even systems with strong reputations show significant drops in accuracy on data outside that distribution. Combining regex and NER, rather than leaning on a single headline accuracy number from any one vendor, is the practical approach.
Deterministic checks, meaning regex and other rule-based logic, behave the same way every time they run, which makes them easy to test and easy to defend in an audit. A probabilistic check that gives a different answer from one run to the next is much harder to justify to a compliance reviewer, and it carries a real risk of letting something through without anyone noticing. No off-the-shelf detector, regex or NER, will recognize an organization's own internal employee IDs, account numbers, or proprietary code names. Those require custom patterns built for that organization specifically.
Masking versus blocking: how to choose the right action for each data class
Masking and blocking solve different problems, and treating them as interchangeable defaults is where many redaction policies go wrong. The right choice depends on whether the AI task can still succeed without the original value, and whether a substituted value would make the prompt misleading or unsafe to act on.
Masking fits cases where the task doesn't need the real value to begin with. A support ticket summarizer doesn't need a customer's actual email address to do its job. Swapping it for a typed placeholder like [EMAIL_REDACTED] keeps the sentence structure intact and gives the model enough context, without ever putting the real address in front of the provider.
Blocking fits cases where a substitute value could cause real harm. A payment workflow that needs an exact account number to execute shouldn't be handed [BANK_CARD_REDACTED] and asked to proceed anyway, it should route to an approved path that doesn't involve a model at all. The same logic applies to credentials: if a private key or a credential appears in a prompt, blocking is the right call, because a masked version of a credential is still a security risk the moment the masking fails.
The choice between irreversible masking and reversible tokenization carries real regulatory weight: irreversible masking replaces the value permanently, with no way to recover it. Done correctly, GDPR treats the result as anonymized data, which falls outside the regulation's scope entirely. Reversible tokenization keeps a mapping in a secure vault so the original value can be restored later on the response path, but because the original still exists somewhere, the data stays classified as personal data and stays inside GDPR's scope.
For most LLM use cases, typed reversible placeholders, things like PERSON_1 or EMAIL_1, are the better fit. They preserve the sentence's structure well enough that the model reasons about it correctly, and the gateway can rehydrate the real values before the response reaches the caller. The provider itself only ever sees the token. LangSmith's gateway follows exactly this pattern: for successful responses, the gateway restores the placeholders to their original values before the response goes back to the caller. If trace content capture is turned on, the trace reflects what the provider actually saw, the redacted placeholder, not the restored original.
A centralized gateway creates one enforcement point and a unified audit trail of what was redacted, by which rule, and when, which is what SOC 2 and GDPR audits actually require and what application-layer approaches spread across microservices and teams cannot produce.
Some gateways support a monitor mode, which records what a detector would have matched without blocking or masking anything. That mode is for measurement and tuning, not for protection, and no data path running in monitor mode should be described to a compliance reviewer as protected. Actions should be set by detector and by workload, not applied as one global rule. An email address, an SSN, and a JWT do not share the same risk profile or recovery path, and a single "mask everything" policy will either over-block useful context or under-block genuinely dangerous content.
Three real implementations of gateway-enforced redaction in production
A major airline runs a customer-facing support agent that handles flight bookings, payment disputes, and account details, using Arthur AI's pre-LLM PII guardrail to scan every conversation before anything reaches the model. The guardrail redacts PII it identifies automatically, so sensitive customer data never makes it to the external model provider at all. The guardrail runs on every single request, with no interaction slipping past it. The compliance question that would ordinarily stall a launch like this got answered by the architecture itself, before anyone had to argue the case manually.
LangSmith's LLM Gateway, in beta at the time of publication, scans outbound requests before they reach the provider whenever a PII or secrets redaction policy is turned on. Redacted content stays redacted in the LangSmith trace as well, so sensitive data doesn't end up persisting inside observability tooling either.
Gravitee took a similar approach with version 4.11, introducing an AI-Powered PII Filtering Policy that inspects prompts as they arrive, identifies sensitive patterns across personal, financial, and healthcare data, and enforces the policy before the request ever reaches the model. The policy runs on both legs of the exchange, detecting and redacting sensitive information in requests on the way out and responses on the way back. WSO2 AI Gateway offers comparable mediation-layer PII redaction capability among gateway products.
The architectural position is the same in each case: before the provider, not after. The LLM gateway's position after authentication and before routing to any provider makes PII redaction enforceable rather than aspirational, applying one consistent rule to every request and recording the detector and action in a single audit trail that holds up across an entire organization, including teams that didn't write careful code.
Sources
- PII Redaction in an AI Gateway: Protect Sensitive Data Before It Reaches an LLM - API7.ai
- PII Redaction for AI Agents: A Pre-LLM Guardrail
- PII Redaction for LLMs in 2026: How to Strip Sensitive Data Before It Leaves Your Perimeter
- Data protection - Docs by LangChain
- PII Redaction for LLMs: How to Do It Right
- Prompt-Level PII Redaction at the Gateway Layer (Under 50ms, No Code Changes)


