Skip to content

Security and governanceGuide

PII in LLM prompts: detect, redact or block before the provider

Personal data reaches model providers through more doors than the chat box: retrieved documents, tool results, pasted logs, and the request logs you keep yourself. Here is where to look, which detection method catches what, and why no detector should be described as complete.

By INFRO Editorial

Published

6 min read

A stream of amber text-like lines on a dark ground passing through a glass filter, with a few segments dimmed into blank blocks, representing redacted personal data

In short

To keep PII out of LLM prompts, first minimise what you send, then detect what remains with the right method for each data type: patterns with checksums for structured identifiers such as card numbers, IBANs and keys; named-entity recognition for names and addresses; and model-based classifiers for context. Choose an action per rule — block, redact to a placeholder, or flag — check responses as well as prompts, and apply the same policy to your own request logs. Every automated detector misses something, so treat redaction as risk reduction, not a guarantee.

Key takeaways

  • PII enters prompts through user input, retrieved documents, tool results and pasted logs; your own request logs are a second copy.
  • Use patterns with checksums for structured identifiers, NER for names and addresses, and model-based classifiers for context-dependent cases.
  • Pick an action per rule: block secrets, redact identifiers to placeholders, flag what you only need to measure.
  • Check responses too: a model can repeat or reconstruct personal data from its context.
  • No detector finds everything; Presidio's own documentation says so. Minimise data first and describe redaction as risk reduction.

How do you keep personal data out of LLM prompts? Send less of it in the first place, then detect what remains with the method that fits each type of data — patterns with checksums for card numbers, IBANs and secrets; named-entity recognition for names and addresses; model-based classifiers for context — and apply an action per rule: block, redact to a placeholder, or flag. Check the model's responses as well as the prompts, and hold your own request logs to the same rules. Then describe the result honestly: every automated detector misses things.

OWASP lists sensitive information disclosure as LLM02 in its 2025 risks for LLM applications, and recommends input validation to filter sensitive data and least-privilege access to it1. This guide turns that into a working design.

Where personal data enters a prompt

The chat box is the obvious door and rarely the largest one:

  1. User input. People paste emails, contracts, screenshots and log lines.
  2. Retrieval. A RAG pipeline puts whatever the index holds into the prompt, including customer records nobody intended to send.
  3. Tool results. An agent that calls your CRM, ticket system or database pastes the results into its next turn.
  4. System prompts and examples. Few-shot examples built from real data carry it into every request.
  5. Your own logs. If you log prompts and responses, you have a second copy of everything above, often kept longer and seen by more people. A prompt and payload logging policy covers that side.

Minimisation beats detection. Retrieve fields, not whole records; pass an internal id instead of a name where the model does not need the name; strip signatures and quoted threads from emails before they reach a prompt.

Three detection methods, and what each catches

MethodGood atMissesCost
Patterns with structure and checksum testsCard numbers (Luhn), IBANs (mod-97), formatted national ids, API keys with known prefixes, emails, phone formatsNames, addresses, dates of birth, anything unformatted or splitMicroseconds, deterministic
Named-entity recognitionPerson names, locations, organisations in proseRare names, context-dependent identifiers, other languages without modelsMilliseconds, probabilistic
Model-based classifiersContext: "this message contains medical history", injection attemptsExact spans; can be wrong confidentlyA model call per check, latency and cost

Open-source tools combine the first two. Microsoft's Presidio, for example, uses named-entity recognition, regular expressions, rule-based logic and checksums with relevant context, across languages, and de-identifies what it finds with configurable operators. Its documentation is explicit about the limit: "there is no guarantee that Presidio will find all sensitive information," and it recommends additional protections2.

Two implementation details catch most bypasses:

  • Normalise before matching. Fullwidth digits, zero-width characters and soft hyphens let a card number slip past a naive pattern. Unicode normalisation (NFKC) and stripping invisible characters first closes that gap.
  • Inspect structured content. Tool-call arguments and JSON tool results carry data too. Parse them and check the string values, rather than matching against serialised JSON.

Choose an action per rule

DataTypical actionWhy
API keys, private keys, passwordsBlockThere is no legitimate reason to send them to a model
Card numbers, bank details, government idsRedactThe model rarely needs the value; a placeholder keeps the task working
Emails, phone numbersRedact or flagDepends on the task; support summaries can work with placeholders
NamesFlag, or redact with consistent placeholdersDetection is probabilistic; blocking on it causes false refusals
Terms specific to you (project codenames, client names)Block or redactYour own deny list catches what generic detectors cannot

Redact with consistent placeholders. Replace each distinct value with the same token throughout a request — [EMAIL_1], [EMAIL_2] — so the model can still refer to them. If your application must restore the values in the answer, keep the mapping in your application, never in the prompt, and restore only into output that goes back to the user who supplied them.

Know what you cannot do on redacted text. Validating an address, matching a name against a list or answering "what is my account number" all need the real value. Those tasks need a different design — a tool the model calls that looks the value up inside your system — not a weaker redaction rule.

Check the response too

Models repeat what is in their context and can reconstruct values from fragments. Run output checks on responses, at least for the strictest rules: a response containing a card number or a key should be blocked or redacted before it reaches the user or your logs. With streaming, an output rule needs the whole answer before it can decide, which delays delivery; apply output checks to the streams that need them rather than all of them.

Where to run the checks

  • In the application: closest to the data and its meaning; must be built into every service.
  • In a gateway in front of the providers: one policy for every service and every provider, applied before the request leaves your control; it sees the prompt but not your business context.
  • At the provider: some offer their own guardrails, but the data has already left by the time they run.

Most teams use two layers: minimisation and domain-specific rules in the application, and a uniform policy at the gateway as the backstop. LLM guardrails at the gateway covers the gateway layer in depth.

A rollout plan

Keep a short exception process: a team that genuinely needs to send a class of data to a model should get an approved path with a named owner, not a quiet workaround.

Measure it

Flag before you block. Run new rules in flag mode for a week, count matches per rule and per service, sample them for false positives, then switch the precise rules to redact or block. Keep counts — not the matched values — on every request, so you can show a reviewer how often each rule fired.

Guardrails in INFRO

INFRO's guardrails check the text of chat completion requests and responses, the prompts of image and video requests, and Claude Code and Codex traffic on its Messages and Responses endpoints, before INFRO sends the request to your provider. Detectors run inside the gateway with no outside service: email, phone, card numbers (issuer prefix and Luhn), IBAN (mod-97), US Social Security numbers, IP addresses, secrets with known prefixes (OpenAI, Anthropic, AWS access key ids, GitHub, Slack, Stripe live keys, Google API keys, JWTs, PEM private keys) and your own deny terms. Text is NFKC-normalised and invisible characters removed before matching, and tool-call arguments are checked inside the parsed JSON. Each rule blocks with 403, redacts to a placeholder such as [EMAIL], or only flags, on input, output or both. Optional classifier checks for prompt injection, jailbreaks and off-topic requests run on your own decision-model connection. Guardrails come with the Business plan, and INFRO's documentation says plainly that detection is pattern-based and can miss things: names, addresses and numbers written in words are not detected.

Summary

Minimise what reaches the prompt, detect the rest with the method that fits each data type, choose block, redact or flag per rule, check responses and logs as well as prompts, and run rules in flag mode before you enforce them. Describe the result as reducing what reaches your provider, because no detector finds everything.

Questions readers ask

How do I remove PII before sending prompts to OpenAI or Claude?
Minimise the data you put in the prompt, then run detection on everything you send — user text, retrieved documents and tool results — and replace matches with placeholders such as [EMAIL] or block the request. Do it in your application or in a gateway in front of the provider, and apply the same rules to the response and to your own logs.
Is regex enough for PII detection?
For structured identifiers with checksums, such as card numbers, IBANs and many API keys, patterns are precise and fast. They do not find names, addresses or dates of birth reliably; those need named-entity recognition or a model-based classifier, which are probabilistic and slower.
Can a model still work with redacted data?
Often yes, if placeholders are consistent: replacing each distinct email with the same token lets the model refer to it. Tasks that need the actual value, such as checking whether an address is valid, cannot be done on redacted text and need a different design.

From the team that builds it

Where this shows up in INFRO

INFRO is a control plane in front of the provider accounts you already hold. The capabilities below are the parts of it this article touches, each with the documentation that defines its behaviour.

  • Guardrails

    Available with a plan

    Pattern-based checks on chat completion prompts and responses: block, redact or flag email addresses, phone numbers, card numbers, IBANs, US Social Security numbers, IP addresses, API keys and your own terms, plus optional classifier checks on your own connection to a decision model's provider. Detection can miss things. Included from the Business plan.

    Read the documentation for Guardrails
  • Classifier guardrail checks

    Available with a plan

    Yes/no checks for prompt injection, jailbreaks, harmful, self-harm and off-topic requests, answered by Jev on your own TypeSafe connection or by any other decision model you connect, with a block and a flag threshold each. Prompts only; the text is never stored. Included with guardrails, from the Business plan.

    Read the documentation for Classifier guardrail checks
  • Request traces and payload logs

    Available with a plan

    Per-request timing detail, with prompt and completion logging off by default and a retention window you choose.

    Read the documentation for Request traces and payload logs

INFRO accounts are self-serve. Provider usage is billed to you by your providers; INFRO charges a software subscription and takes 0% of model spend. See plans.

Sources

Numbered in order of first citation. Each was opened and checked against the claim on the date shown.

  1. 1.LLM02:2025 Sensitive Information Disclosure (opens in a new tab) — OWASP GenAI Security Project. Accessed Oct 20, 2026.
  2. 2.Presidio (opens in a new tab) — Presidio. Accessed Oct 20, 2026.

About this article

Detection approaches are described from Microsoft Presidio's documentation and OWASP's 2025 LLM risk entry on sensitive information disclosure, opened on 2026-10-20. INFRO's guardrails are described from its documentation. No detector was benchmarked. Written by the team that builds INFRO.

Last checked against its sources on . The next review is due by . No separate named reviewer is recorded for this article.

How articles are written, sourced and corrected is set out in the editorial standards.