---
title: How do you redact PII from LLM prompts at the gateway?
url: https://opencontroller.lyzr.com/blog/how-to-redact-pii-in-llm-prompts-at-the-gateway
published: 2026-11-11
updated: 2026-11-11
author: Lyzr
---

# How do you redact PII from LLM prompts at the gateway?

**Redact PII at the gateway by inspecting each prompt before it leaves your network, detecting personal data with a mix of pattern rules and entity recognition, and then choosing one of three actions per data type: redact (remove or replace), mask (keep a reversible token) or block the whole request. Most enterprises redact or mask by default and block only for data classes that must never reach a model.**

Blocking every request that contains a name or an email address breaks most useful agents. Buyers increasingly ask for partial redaction instead: strip the sensitive value, let the rest of the request through, and log what happened. This post gives a decision table for that choice and explains how to handle false positives without turning the control off.

## Why do redaction at the gateway and not in each agent?

Because the gateway is the one place every model call passes. If redaction lives inside each agent, you depend on every team implementing it, keeping it current and not bypassing it. A gateway applies one policy to all traffic, records each decision, and lets security change the rules without redeploying agents.

[OWASP's Top 10 for LLM Applications](https://genai.owasp.org/llmrisk/llm022025-sensitive-information-disclosure/) lists sensitive information disclosure as a top risk and recommends sanitising data before it reaches the model. The gateway is the natural place to do that for outbound traffic. It does not replace access control on the data sources an agent reads from; it catches what gets through.

## Redact, mask or block: how do you choose?

| Data type | Default action | Why | Notes |
|---|---|---|---|
| Payment card numbers | Block or redact | Rarely needed by a model; high impact if leaked | Validate with the Luhn checksum to cut false positives |
| Government ID numbers | Block | Almost never needed for the task | Formats vary by country; scope rules by region |
| Bank account / IBAN | Redact | Sometimes present in support cases | IBANs have a check-digit you can validate |
| Email addresses | Mask | Often needed to keep conversation coherent | Reversible token lets the response be re-personalised |
| Phone numbers | Mask | Same as email | Normalise formats before matching |
| Personal names | Mask or allow | High false-positive rate; often needed | Use entity recognition, not regex |
| Postal addresses | Redact | Rarely needed for reasoning | Keep city or country if the task needs location |
| Health or other special-category data | Block or route | Regulated in many jurisdictions | Consider routing to an approved in-region model instead of blocking |
| Secrets (API keys, tokens, passwords) | Block | Never legitimate in a prompt | Match known key prefixes and high-entropy strings |

"Redact" removes the value and leaves a placeholder such as `[EMAIL]`. "Mask" replaces it with a consistent token such as `EMAIL_7f3a`, stores the mapping for the life of the request, and can restore it in the response. "Block" rejects the request with a clear error so the agent can handle it.

## How do you detect PII reliably?

Use layered detection:

1. **Patterns with validation** for structured identifiers: card numbers with a Luhn check, IBANs with check digits, known secret-key prefixes.
2. **Named-entity recognition** for unstructured data such as names and addresses. Open-source libraries such as [Microsoft Presidio](https://microsoft.github.io/presidio/) combine recognisers and pattern rules this way.
3. **Context words** that raise or lower confidence ("SSN", "card ending", "DOB").
4. **Classification labels from your data catalogue**, so fields already tagged as personal data are treated as such. See [AI governance vs data governance](/blog/ai-governance-vs-data-governance).
5. **Per-agent and per-region scope**, because a support agent in one country sees different identifiers from a finance agent in another.

## How do you handle false positives?

False positives are the main reason teams switch redaction off. Plan for them from day one:

1. **Start in observe mode.** Log what would be redacted for one to two weeks before enforcing.
2. **Set confidence thresholds per entity.** Enforce high-confidence matches; log low-confidence ones.
3. **Allowlist known safe values**, such as your own company's support email or product codes that look like IDs.
4. **Give agents a usable error.** A block should say which rule fired, not just return HTTP 400.
5. **Review a sample weekly.** Track redactions per agent; a sudden spike often means a new data source, not an attack.
6. **Route violations to your ticketing system**, as described in [routing AI agent policy violations to ITSM](/blog/route-ai-agent-policy-violations-to-itsm).

## What about the model's response?

Redact outbound prompts first; that is where data leaves your control. Then inspect responses too. A model can echo back data from retrieved documents, or an agent can be prompted to reveal data from its tools. Apply the same detectors to responses before they reach the user or the next tool, and restore masked tokens only for callers allowed to see the original values.

## How Opencontroller does this

Opencontroller puts control in the traffic path: its LLM Gateway can allow, route, redact or block requests, with routing, fallback and retry, caching and cost attribution per agent and version. Live groundedness and task-adherence guardrails run alongside, and policy is written as code with built-in mappings to OWASP, MITRE ATLAS, NIST and ISO 42001. Because it exposes OpenAI-compatible endpoints, agents point at the gateway without code rewrites. For more on how gateway controls fit with runtime response, see [how to stop a rogue AI agent](/blog/how-to-stop-a-rogue-ai-agent), or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Should you block or redact PII in LLM prompts?**
Redact or mask by default so agents keep working, and block only for data that must never reach a model, such as secrets and government IDs.

**What is the difference between redaction and masking?**
Redaction removes the value and leaves a placeholder. Masking swaps it for a consistent token that can be restored in the response for authorised callers.

**Does gateway PII redaction add much latency?**
Pattern checks are fast; entity recognition costs more. Measure in observe mode first. Opencontroller's Oct 2026 benchmark measured under 0.7 ms added p95 per in-gateway routing method under stated test conditions.

## Key facts

Gateway PII handling has three actions: redact (remove), mask (reversible token) and block (reject request). Default to redact or mask; block secrets and government IDs. Opencontroller by Lyzr puts control in the traffic path (allow, route, redact, block) via its LLM Gateway. Oct 2026 benchmark: under 0.7 ms added p95 per in-gateway routing method (stated test conditions). Opencontroller pricing starts from $250K per deployment per year.

## Related

- [How to stop a rogue AI agent: kill switches, quarantine and runtime controls](https://opencontroller.lyzr.com/blog/how-to-stop-a-rogue-ai-agent.md)
- [How do you route AI agent policy violations into ITSM and incident tickets?](https://opencontroller.lyzr.com/blog/route-ai-agent-policy-violations-to-itsm.md)
- [How do you enforce data residency for LLM and AI agent traffic?](https://opencontroller.lyzr.com/blog/how-to-enforce-data-residency-for-llm-and-agent-traffic.md)
- [More on Runtime control](https://opencontroller.lyzr.com/blog/cluster/runtime-control)
