pii redaction · llm security · gdpr · ai compliance · guide
PII redaction for LLM applications: the complete guide (2026)
Design an LLM redaction flow: detection, local mappings, reply restore, streaming limits and practical acceptance checks for your application.
In this article
- What is PII redaction for LLM applications?
- Why this became urgent in 2026
- Where to redact: library, gateway, or browser
- Detection: patterns, labels, and NER
- Not just PII: API keys and secrets
- The streaming trap: values split across chunks
- The tool landscape, honestly
- A minimal implementation
- Trusting the redactor itself
- The 10-point checklist
- Frequently asked questions
- Comments
Sether™ / Field notes
pii redaction
A useful task. Fewer exposed details.
A practical guide to the AI privacy boundary.
PII redaction for LLM apps detects supported personal details and secrets in prompts, then replaces matched values before the provider request. Reversible tokenization keeps a local token-to-original mapping so recognised tokens in the reply can be restored. It can run in an application library, a gateway, or a browser extension; each covers a different boundary.
- Map the actual data flow first: provider roles, contracts, retention and legal obligations depend on your use case. Installing a redactor is not a compliance certificate.
- Three places to redact: in-process library, proxy gateway, or browser extension. The library is the default for product teams.
- Detection is layered: validated patterns (email, card, IBAN) catch structured PII; label anchoring catches "name: Sarah"; NER catches names in free text.
- Reversible tokenization can keep replies useful while withholding matched originals. Unmatched details and identifying context can still pass through.
- Streaming breaks naive redaction: a value split across two chunks slips through unless the redactor holds back a safety window.
What is PII redaction for LLM applications?
A prompt is an application payload. If a user types "Hi, I’m Sarah Chen, my email is sarah@acme.com, calling about order 4532", those values reach the provider unless your application changes the payload first. HTTPS protects transport; it does not hide the values from the intended recipient. Redaction replaces supported matches before that request, with restoration later when the task needs the originals back.
SetherThe idea, illustrated
Your map. Your side.
Replace detected details before sending. Restore recognized replacements using the matching retained map.
Fictional example. Detection can miss values; review the edited text. Follow one prompt step by stepKeep the replacement mapping on your side of the integration. The model can receive a token such as <EMAIL_uuid> in place of a matched email, and your app can restore that token from its vault. This is a reduction in disclosed detail, not proof that the remaining message is anonymous: an order reference or the surrounding story may still identify someone. The mechanics are in Reversible PII redaction: how redact-then-restore works.
Why this became urgent in 2026
An AI feature adds a data recipient and often another place where prompts, replies or logs can persist. Before launch, ask a concrete question: which fields does this task need, and which can remain in your application? Then review the resulting data flow with the people responsible for security, privacy and contracts. That produces a useful engineering requirement without relying on a blanket regulatory deadline or promising that redaction resolves every obligation.
If you are wondering whether your specific setup is a problem, start with Is it GDPR-compliant to send customer data to OpenAI? That post walks the actual legal reasoning instead of fear-mongering.
Where to redact: library, gateway, or browser
| Approach | Where it runs | Best for | Trade-off |
|---|---|---|---|
| In-process library | Inside your app, wrapping the LLM call | Product teams who own the code path | One integration per service |
| Proxy gateway | A separate service your SDK points at | Many services, one policy; polyglot stacks | New infrastructure to run and trust |
| Browser extension | The user's browser, watching the chat input | Employees pasting into ChatGPT/Claude/Gemini directly | Protects humans, not your API traffic |
These are complements, not competitors. A library protects your product's API calls; an extension protects the copy-paste habits of the humans in your company. We cover the human side in How to stop pasting sensitive data into ChatGPT.
Detection: patterns, labels, and NER
No single technique catches everything. Production redaction layers stack three:
- Validated patterns identify candidate structured values, with checks such as Luhn for cards and mod-97 for IBANs. These checks reject some invalid candidates; they do not prove a value belongs to a person or eliminate false matches.
- Label anchoring uses nearby cues such as "name: Sarah Chen" or "DOB: 12/04/1991". Coverage depends on the enabled labels, scripts and value formats.
- NER (named-entity recognition) can identify entities in free prose where shape and labels offer less signal. It adds model and evaluation costs. Known-term lists and custom detectors are other options for specific vocabularies.
Regex vs NER for PII detection explains coverage and evaluation choices. Local inference can avoid sending text to a separate detection service; it also adds model-loading and runtime responsibilities to assess.
Not just PII: API keys and secrets
The same pipeline that catches emails should catch sk-... OpenAI keys, AWS access keys, GitHub tokens, Slack tokens, Stripe keys, JWTs, and high-entropy strings. Developers paste config into AI chats constantly, and a leaked provider key is a worse day than a leaked email address. Sether ships this as a separate detector pack (8 detectors including a Shannon-entropy catch-all) that you enable alongside the basic pack.
The streaming trap: values split across chunks
Streaming introduces a second boundary: a detector may receive sarah@ac and me.com in different chunks. Scanning chunks independently can miss the joined email. Sether uses a configurable hold-back distance (safeDistanceBytes, default setting 256) and additional buffering guards. These are bounded safeguards, so test long values, custom detectors and actual transport framing rather than treating the default as a guarantee for every possible input.
The chunk-boundary discussion shows a reproducible example, partition-test design and the current implementation’s buffering limits. Use those examples to test the actual code path and retain the failing partitions as regression fixtures.
The tool landscape, honestly
| Tool | Language | Approach | Notes |
|---|---|---|---|
| Microsoft Presidio | Python | NER (spaCy) + patterns, analyzer/anonymizer services | Analyzer and configurable anonymization operators; reversible encrypt/decrypt is also supported |
| LLM Guard (Protect AI) | Python | Guardrail scanner suite; Anonymize is one scanner among many | Broad guardrails (prompt injection, toxicity) rather than a focused redaction layer |
| Sether | TypeScript + Python | Streaming redact/restore with a token vault; pattern + label + optional local NER packs | MIT SDK, one declared TypeScript runtime dependency; official tools have separate Free and Pro tiers |
| DIY regex | Any | Hand-rolled patterns in your request path | Fine for a prototype; typically falls to the streaming trap and lacks restore, validation, and tests |
Choose by integration shape and measured coverage. Presidio exposes configurable detection and anonymization operators, including a deanonymizer for reversible operations. Sether focuses on an in-process redact/vault/restore flow for TypeScript and Python. Compare both on representative prompts and deployment constraints; the longer Presidio comparison explains what to test.
A minimal implementation
In TypeScript (full walkthrough):
import { Sether } from '@raeven-co/sether';
import { Readable } from 'node:stream';
const sether = new Sether();
// Outgoing: pipe the prompt through redact() before it leaves
const safeForLLM = Readable.from([userMessage]).pipe(sether.redact());
// Incoming: pipe the model reply through restore() before the user sees it
const safeForUser = llmResponse.pipe(sether.restore());
In Python (full walkthrough):
from sether import Sether
sether = Sether()
safe = sether.redact_sync(user_message) # tokens out
reply = call_openai(safe)
restored = sether.restore_sync(reply) # real values home
Trusting the redactor itself
A redaction layer handles sensitive inputs, so inspect its source, dependencies, storage and network behavior. Review the exact version you plan to deploy, including optional models and wrappers. The supply-chain hardening account documents a historical scan, not a permanent security rating or certification.
Use a fictional support ticket as an acceptance fixture. Mark the email as a required replacement, leave the refund question readable, and make the model reply echo the token. Verify the outgoing payload, the restored reply and your error logs separately. A passing round trip proves the mapping works; it does not prove that every sensitive field was detected.
| Boundary | What to inspect |
|---|---|
| Before the provider call | Matched fields are replaced; unnecessary context is removed; raw prompts are absent from logs. |
| After the model reply | Only recognised mappings restore; unexpected tokens or fields are reviewed. |
| After the session | Vault retention and saved application data follow your chosen lifecycle. |
The 10-point checklist
- List every place your code sends text to an LLM provider (including background jobs and evals).
- Review provider roles, applicable agreements and any required customer disclosures for the actual data flow.
- Put a redaction layer in each request path (library or gateway).
- Enable structured-PII detectors with validation (email, phone, card + Luhn, SSN, IBAN + mod-97, IPs).
- Enable the secrets pack (provider keys, tokens, JWTs, high-entropy).
- Turn on label-anchored identity detection, multilingual if you serve non-English users.
- Add NER if your prompts carry free-text names (support tickets, chat, documents).
- Verify streaming safety: test a value split across chunk boundaries.
- Keep the matching vault available for the reply, with deliberate access, capacity and retention limits; test missing and expired mappings.
- Give employees a browser-side guard for direct ChatGPT/Claude/Gemini use.
Frequently asked questions
Does redaction hurt LLM answer quality?
It can change answer quality. Typed tokens preserve a hint about the field, but the model may omit, alter or misplace them, and some tasks need facts carried by the original value. Evaluate the actual task with tokenized fixtures, validate the result and restore only recognised replacements.
Is prompt redaction required by GDPR?
GDPR does not prescribe Sether or a particular redactor. Appropriate controls depend on the processing and risk. Redaction can support minimisation, but source inspection and a successful demo do not establish legal compliance. See the GDPR discussion and obtain advice for your circumstances.
Why not just use OpenAI's zero-retention or EU endpoints?
Provider retention controls and pre-request redaction address different parts of the data flow. Redaction withholds matched values; settings control the treatment of what you do send. Neither proves that all identifying context has been removed or that every legal obligation is satisfied.
What does Sether cost?
The full TypeScript and Python libraries, including decoy and restore, remain free under MIT with no Sether usage quota. Official tools offer Free scanning, masking, token replacement and all restore of known mappings. New licensed releases add optional Pro realistic decoys and custom watchlists in both tools, plus custom regex rules in Shield, for one person across Shield and the editor: $5 for one month or $48 for one year, manual renewal. The seven-day trial is opt-in after installing a compatible build, requires no card and does not charge automatically. Current store builds may retain legacy free features. See pricing for pilot availability.
Written by Godfrey Lebo
Founder of Sether. Ships production software for a living and reads every comment below. More about the team.
Comments
Emails and phone numbers in comments are hidden automatically. We take our own medicine.
No comments yet. Ask a question or share how you handle this. First comment gets our undivided attention.
Join the conversation
Questions, corrections and war stories are all welcome. Be kind, stay on topic.