Back
Kevin Riedl

13 min read Β· 6 Aug 2026

Next
Made on your device, with no Instagram connection. We copy the post link for Instagram’s Link sticker.

PII Redaction Before LLM Prompts: Presidio, Privacy Filter, and a Production Pipeline

The safest prompt is not the one that tells an LLM to ignore personal data. It is the one that never contains data the model does not need. Put a deterministic privacy gateway before the model call, remove unnecessary fields, replace necessary identifiers with stable placeholders, and keep the re-identification map under your control.

This guide targets the practical search gap between a five-line Presidio demo and a broad GDPR policy. It shows the complete path for support tickets, documents, RAG, agents and internal assistants. It also compares the Microsoft-originated Presidio project with OpenAI Privacy Filter and managed cloud DLP services. Tool details were verified on 6 August 2026.

Need a privacy-safe AI data flow your security team can test?

 Plan the prompt gateway

What is the recommended PII redaction pipeline for LLM prompts?

Use seven boundaries: minimize, detect, classify, transform, call, inspect and selectively restore. Run detection inside your trusted environment before the prompt, attachment, retrieved passage or tool result crosses into the model provider's boundary.

  1. Minimize at the source. Select only fields required for the task. Do not serialize a complete customer record and redact it later.
  2. Detect in layers. Combine schema-aware field rules, checksums and secret patterns with a context-aware PII detector. One method will not cover both an IBAN and a name hidden in prose.
  3. Apply a policy per entity and purpose. Block forbidden content, drop unnecessary content and pseudonymize values the task still needs.
  4. Create unique typed placeholders. Replace values with tokens such as PERSON_001, EMAIL_001 and CASE_ID_001. Keep repeated references consistent within the authorized scope.
  5. Call the model with sanitized context. The model, tracing system and prompt cache receive placeholders, never the lookup table.
  6. Inspect the output. Detect new sensitive values, unexpected raw identifiers and unauthorized placeholders before any response, log or tool call leaves the gateway.
  7. Restore only at the final authorized boundary. Resolve an allowed placeholder for the intended user and channel. Never re-identify broadly inside logs, agent memory or a downstream tool argument.
trusted application
  -> field minimizer
  -> rules + contextual detector
  -> policy decision: block | drop | tokenize
  -> encrypted token vault
  -> sanitized prompt -> LLM
  -> output detector + authorization
  -> selective re-identification -> user

This gateway complements, rather than replaces, the object and field authorization described in our AI agent data-level access-control guide. Redaction limits what an approved request exposes. Authorization decides whether the request should access the record at all.

Redaction, masking, tokenization and anonymization are not synonyms

Choosing the wrong word creates a dangerous control gap. The difference is whether the value can be recovered and whether the remaining context still identifies a person.

TechniqueExample resultReversible?Best use
Redaction[REMOVED]No mapping by designData the task does not need
Maskingj***@example.comOriginal remains elsewhereUser interfaces and diagnostics
Pseudonymization or tokenizationPERSON_001Yes, with separate information or a keyLLM tasks that need entity continuity
AnonymizationNo person is reasonably identifiable from the result and available contextNoOnly after a defensible re-identification assessment

Under GDPR Article 4(5), pseudonymization requires the additional information to be kept separately and protected. The European Data Protection Board's 2025 guidance is explicit that pseudonymized data remains personal data when it can be linked back to a person. Replacing a name with PERSON_001 reduces exposure. It does not move the workflow outside GDPR.

Even irreversible string removal may not anonymize a prompt. A rare job title, exact event date and small town can identify somebody together. Treat the complete context, metadata, attachments and model output as the assessment unit.

Which PII redaction tool should you use in 2026?

Start with application-owned field minimization and deterministic rules. Add Presidio when you need an inspectable, extensible framework. Add a local contextual model when names and free text dominate. Use a managed DLP service only when sending raw input to that cloud is already approved.

OptionStrongest fitMain tradeoffRaw data boundary
Schema rules, regex and checksumsKnown fields, email, IBAN, phone and credential formatsWeak on names, context and unexpected formatsYour application
PresidioCustom recognizers, mixed rules and NER, explainable operators, Python servicesRequires language models, calibration and operations; detection is not guaranteedLocal or your infrastructure
OpenAI Privacy FilterContext-aware local filtering of long unstructured text and software secretsMore compute, eight fixed base categories, primarily English without adaptationLocal or your infrastructure
Azure AI Language PIIManaged text, conversation and native-document detection in an approved Azure estateThe service receives unredacted input; cost, region and operation-specific behavior applyAzure
Google Sensitive Data ProtectionManaged inspection plus cryptographic tokenization and referential integrityThe service receives unredacted input and key design needs careGoogle Cloud
Amazon Comprehend PIIAWS-native entity location and batch redaction workflowsLanguage and real-time redaction support differ by operationAWS

Is Presidio still a Microsoft tool?

Presidio was developed at Microsoft and many older results still call it Microsoft Presidio. In 2026 it is transitioning to the independent Data Privacy Stack organization. The project says it remains MIT licensed, its APIs continue, and new container images move from Microsoft's registry to ghcr.io/data-privacy-stack. Calling it Microsoft-originated is accurate. Treating current community governance as a Microsoft support contract is not.

The framework remains a strong default because its Analyzer and Anonymizer combine regex, deny lists, checksums, rules, named-entity recognition and contextual signals with replace, redact, hash and encrypt operators. You can add recognizers for Austrian social insurance numbers, German tax identifiers, Spanish DNI or NIE formats, Chinese identity numbers and your own customer IDs. Presidio's documentation also warns that automated detection cannot find every sensitive value. That warning belongs in your architecture, not only in the footnotes.

When does OpenAI Privacy Filter fit better?

OpenAI Privacy Filter, released in April 2026 under Apache 2.0, is a local bidirectional token classifier. The published model has 1.5 billion total parameters, 50 million active parameters and a 128,000-token context window. It detects eight categories covering private people, addresses, emails, phones, URLs, dates, account numbers and secrets.

That language understanding is useful when a regex cannot tell a private person from a public organization. It is not a universal policy engine. The model card says the base taxonomy is fixed, performance can fall on non-English or out-of-distribution text, and policy changes may need fine-tuning. It is a detector inside the pipeline, not the vault, authorization layer or compliance decision.

When is managed DLP the better buy?

Managed DLP is attractive when the organization already approves the cloud boundary, needs broad detector catalogs, and does not want to operate NLP models. Azure AI Language PII covers text, conversations and native documents. Google Sensitive Data Protection adds cryptographic one-way and reversible tokens with referential integrity. Amazon Comprehend PII provides entity location and asynchronous redaction.

The architectural catch is simple: a cloud detector must see the raw value to redact it. It can protect the downstream LLM provider while becoming a processor of the original data itself. Review region, retention, subprocessor, DPA and transfer terms as part of the EU AI data-residency decision.

Why typed placeholders beat a wall of REDACTED tokens

A model can still solve many tasks when it knows that two references point to the same customer, clinician or contract. Replacing every entity with [REDACTED] destroys that relationship. Typed, unique placeholders preserve it without revealing the value.

Raw:    Maria emailed Dr Chen about account AT00... twice.
Prompt: PERSON_001 emailed PERSON_002 about ACCOUNT_001 twice.

Scope token consistency narrowly. The same value may receive the same placeholder inside one request or approved conversation, but not across every customer and year. Global deterministic tokens create a new tracking identifier. Store mappings with tenant, purpose, expiry and authorized recipient. Encrypt them separately from prompt logs, and delete them when restoration is no longer needed.

Do not let the model invent placeholders that automatically resolve. The restore step should accept only tokens created by the gateway for this request, then verify the intended recipient and output channel. A placeholder copied into a tool argument, memory store or analytics event stays pseudonymized unless a separate policy explicitly permits restoration there.

Where should the gateway sit for chat, RAG and agents?

FlowRequired interception pointsCommon miss
Chat or support copilotUser input, retrieved customer fields, model output and tracesRedacting the typed prompt but not the CRM record added by code
RAGBefore indexing, after retrieval and before outputCleaning the final prompt after raw PII already entered embeddings and logs
Agent toolsTool arguments, tool results, model context, memory and final responseRestoring identifiers before an autonomous tool call
Documents and imagesOriginal file, OCR text, metadata, thumbnails and exportsCovering visible text while searchable layers or metadata retain it
ObservabilityPrompt traces, errors, eval samples, support bundles and analyticsSanitizing inference but logging the exception payload in full

For RAG, redaction does not replace per-user permissions. A clean passage can still reveal a confidential strategy, and a pseudonymized embedding can remain personal data. Use our RAG permissions architecture for the access problem and this pipeline for data minimization.

How do you test a PII gateway before production?

Do not approve it from a vendor benchmark or ten hand-written prompts. Build an authorized evaluation set that represents your languages, formats, error modes and business identifiers. Use synthetic examples for breadth and carefully governed labeled samples for realism.

  • Entity recall by risk tier: measure how often forbidden identifiers leak. A missed health identifier should not be averaged away by easy email matches.
  • Precision and utility: measure useful text removed, task success before and after sanitization, and whether entity relationships survive.
  • End-to-end leakage: test every input, retrieval, tool, output and logging path, not only the detector function.
  • Language and locale: include German compounds, Spanish names, Chinese scripts, transliteration, mixed-language prompts and local identifier formats.
  • Adversarial formatting: test spaces, OCR errors, Unicode lookalikes, identifiers split across fields and secrets embedded in code.
  • Restoration safety: attempt cross-tenant tokens, expired tokens, invented placeholders and restoration into a forbidden channel.
  • Operations: track p50 and p95 latency, timeouts, detector-version drift, vault availability and fail-closed behavior.

Set thresholds per workflow. A public marketing summarizer and a clinical case assistant do not share the same acceptable false-negative rate. In high-risk paths, uncertain detection should block or require review. In lower-risk paths, a false positive can be shown to the user for correction. Never silently fail open because the detector is slow or unavailable.

Kevin Riedl

"A PII detector is a sensor, not a security boundary. The boundary is the gateway that minimizes data, enforces policy, controls re-identification and fails safely when the sensor is uncertain."

Build, buy or combine?

DecisionChoose it whenWhat you still own
Build around PresidioYou need local processing, custom entities, inspectable rules and moderate model operationsEvaluation, scaling, vault, policies, language models and incident response
Run Privacy Filter locallyFree text and contextual names dominate, long inputs matter, and local inference capacity existsFine-tuning, non-English evaluation, transformation, vault and policy
Buy managed DLPYour cloud is approved and faster integration matters more than keeping detection on-devicePurpose rules, contracts, gateway logic, output control and verification
Use a hybridYou have structured identifiers plus multilingual free text and different risk tiersRouting, conflict resolution and one end-to-end evidence set

For most production systems, the hybrid is the honest answer: deterministic extraction for known fields, Presidio for configurable entity logic, a contextual model for ambiguous prose, and an application-owned token vault. A two-detector disagreement should become a policy signal, not a reason to pick whichever result is cheaper.

If you are buying an AI platform, add the gateway evidence to the EU AI vendor security questionnaire. If you are building it, Wavect's AI enablement service can map the data flow, implement one bounded workflow and leave your team with tests and operating documentation. Twinsoft AI shows the wider production discipline around an AI system, while AI enablement versus generic AI consulting helps decide whether you need implementation or advice.

Implementation checklist

  1. Inventory raw prompts, uploaded files, retrieval sources, tool results, outputs, caches and logs.
  2. Define which data classes are blocked, dropped, pseudonymized or allowed for each purpose.
  3. Remove unnecessary structured fields before text assembly.
  4. Deploy deterministic and contextual detectors inside an approved boundary.
  5. Create unique typed tokens and a tenant-scoped encrypted mapping store.
  6. Keep raw values and the mapping out of model context, traces and analytics.
  7. Inspect model output and authorize each restoration by token, recipient, purpose and channel.
  8. Test multilingual false negatives, utility, adversarial formats, latency and failure modes.
  9. Record detector versions, policy decisions and aggregate entity counts without raw content.
  10. Review the legal basis, DPA, retention, data-subject rights and DPIA need with privacy counsel.

Frequently Asked Questions

Should I redact PII before sending a prompt to an LLM?
Yes, when the model does not need the original identifier. Remove unnecessary fields and use typed pseudonyms when entity continuity matters. Redaction reduces exposure but does not replace lawful basis, authorization, retention controls or a DPA.
Is Microsoft Presidio good enough for production?
Presidio is a strong framework, not a guarantee. Production use needs custom recognizers, the right language model, an in-domain evaluation set, a fail-safe gateway and monitoring. The project itself warns that automated detection will not find all sensitive information.
Is Presidio still owned by Microsoft?
No longer in the simple sense implied by older search results. Presidio originated at Microsoft and is transitioning to independent community governance under Data Privacy Stack. It remains MIT licensed, and existing APIs are expected to continue.
Does pseudonymizing a prompt make it anonymous under GDPR?
No. If a controller or another party can link the prompt back to a person using additional information, the prompt remains personal data. Pseudonymization is a valuable safeguard, not an exemption from GDPR.
Should the gateway restore names in the LLM response?
Only when the intended user, purpose and output channel are authorized. Resolve only tokens created for that request. Do not restore them inside model memory, logs or autonomous tool calls by default.
Can a cloud DLP service protect data before a cloud LLM?
It can protect the downstream LLM, but the DLP service must receive the original data. Treat that service as part of the processing chain and verify region, retention, subprocessor, DPA and transfer terms.

Final thoughts

PII redaction before an LLM call is not one regex and not a compliance checkbox. Build an unavoidable gateway that starts with data minimization, combines deterministic and contextual detection, preserves only the relationships the task needs, and keeps its token vault outside model reach. Scan the way out as carefully as the way in. Then prove the system on your own languages and failure modes. Presidio, Privacy Filter and managed DLP can each supply a detector. Your architecture must supply the policy, authorization, restoration boundary and evidence.

Primary sources

Production AI help

Building an AI product and worried about inference cost, architecture, or production readiness? Wavect helps founders turn AI prototypes into reliable production systems.

Explore the service path:

Inbox, without the noise

Follow the work that matters to you

Get a short email when we publish something new. Follow the whole blog or only the problems you care about.

What would you like to receive?
Choose your topics

Free, double opt-in, no tracking pixels.

Back
Kevin Riedl

13 min read Β· 6 Aug 2026

Next

Get new posts by email

A short email when we publish. Free, no tracking.

Free, double opt-in, no tracking pixels.