In plain English
Personally identifiable information (PII) is any data that points to a specific human: a name, an email address, a phone number, a credit-card number, a passport number, a home address. The moment that data flows into an AI system — a prompt, a log file, a fine-tuning dataset — it becomes a liability. You now have to protect it, and in many places the law says exactly how.

Microsoft Presidio is an open-source toolkit that finds that personal data inside text (and images and tables) and then removes or disguises it. Think of it as a smart redaction marker: feed it a sentence like "Call John Smith at 555-0199," and it hands back "Call <PERSON> at <PHONE_NUMBER>." The meaning of the message survives; the personal details do not.
The everyday analogy is the black highlighter a government clerk runs over a declassified document before it goes public. The clerk reads each line, spots the sensitive parts — names, locations, dates — and blacks them out so the rest can be shared safely. Presidio is that clerk, automated and running at machine speed over millions of records. The name even nods to it: presidio is Spanish for a fortified outpost — a guard post for your data.
Why it matters
Once you build anything on top of an LLM, personal data leaks into places you did not plan for. A user pastes a customer email into a support chatbot. Your application logs the full prompt for debugging. You collect real conversations to build a golden dataset or fine-tune a model. Every one of those steps quietly copies someone's PII into a new system — your logs, your analytics pipeline, a third-party model provider.
That is a real problem for three overlapping reasons:
- Regulation. Laws like GDPR, HIPAA, and CCPA put hard rules on how personal and health data is stored, shared, and sent across borders. Shipping raw PII to an external API can break those rules on its own.
- Third-party exposure. When you call a hosted model, the prompt leaves your infrastructure. Scrubbing PII before the call means the provider never sees the sensitive part in the first place.
- Blast radius. Logs and datasets get copied, backed up, and shared widely inside a company. PII that sits in them is a breach waiting to happen. Redacting at the source shrinks how much damage any single leak can do.
Presidio matters because it turns "we should really scrub PII" into a concrete, reusable component you can drop into a pipeline. It is open source, runs entirely on your own infrastructure (so the data you are trying to protect never has to leave to be cleaned), and is extensible enough to recognize the domain-specific identifiers your business actually uses. That combination is why it shows up so often as the safety layer wrapped around LLM inputs, outputs, and logs.
How it works
Presidio splits the work into two stages that you can run together or independently: the Analyzer finds PII, and the Anonymizer acts on it. A separate Image Redactor extends the same idea to pictures, and there is dedicated support for structured data (tables, JSON, CSV).
The Analyzer: detecting PII
The Analyzer does not rely on a single trick. It combines several recognizers, and each piece of PII can be caught by whichever one fits best:
- Regex patterns for things with a predictable shape — credit-card numbers, email addresses, IP addresses, phone numbers.
- Checksums and validation to cut false positives, like running the Luhn algorithm to confirm a number really could be a credit card.
- Named-entity recognition (NER) from an NLP model to catch fuzzy, context-dependent entities like people's names, organizations, and locations that no regex can reliably match.
- Context words that boost confidence — the word "card" sitting next to a 16-digit number makes the credit-card guess more certain.
- Deny lists and allow lists for fixed sets of terms you always (or never) want flagged.
Each finding comes back with three things: the entity type (for example PERSON or CREDIT_CARD), the position in the text (start and end character), and a confidence score between 0 and 1. You set a threshold and decide how cautious to be.
The Anonymizer: acting on what was found
Once you have the list of findings, the Anonymizer applies an operator to each one. The operator is your policy choice, and different fields can use different operators:
| Operator | What it does | Good for |
|---|---|---|
| replace | Swap the value for a tag like <PERSON> | Readable logs, prompts to an LLM |
| mask | Hide some characters, e.g. ****-****-****-1234 | Keeping a usable suffix for support |
| redact | Delete the value entirely | Maximum stripping, no placeholder |
| hash | Replace with a one-way hash of the value | Linking records without the raw value |
| encrypt | Reversibly encrypt with a key | Restoring the original later (de-anonymize) |
The encrypt operator is the interesting one for LLM workflows: you can encrypt PII before sending text to a model, then decrypt the model's reply to put the real values back. The provider only ever sees ciphertext, but your end user still gets a personalized answer.
A worked example
Here is the smallest end-to-end run. The Analyzer locates two entities; the Anonymizer replaces them with type tags. This is the exact pattern you would put in front of an LLM call.
from presidio_analyzer import AnalyzerEngine
from presidio_anonymizer import AnonymizerEngine
text = "Hi, I'm Maria Lopez and my email is maria@example.com."
# 1) ANALYZE: find the PII.
analyzer = AnalyzerEngine()
results = analyzer.analyze(text=text, language="en")
for r in results:
# e.g. PERSON 0.85, EMAIL_ADDRESS 1.0
print(r.entity_type, round(r.score, 2))
# 2) ANONYMIZE: replace each finding with a tag.
anonymizer = AnonymizerEngine()
clean = anonymizer.anonymize(text=text, analyzer_results=results)
print(clean.text)
# -> "Hi, I'm <PERSON> and my email is <EMAIL_ADDRESS>."Notice the email scored 1.0 (a regex match with a validating pattern is near-certain) while the name scored lower (NER is a probabilistic guess). That score is the knob you tune when you decide how aggressively to redact.
Where Presidio fits in an LLM system
Presidio is not a model and not a guardrail framework — it is a focused PII engine you place at specific choke points. There are three classic spots, and serious systems use more than one.
- Inbound (pre-model). Scrub the user's prompt before it leaves your servers for a hosted model. The provider never receives the raw PII.
- Logging and observability. You almost always log prompts and responses for debugging. Run them through Presidio first so your log store is not a hidden PII database.
- Dataset preparation. Before you build an eval set or fine-tune on real conversations, de-identify the corpus so personal data is not baked into a dataset that gets copied around forever.
A subtle point: redaction can hurt the model's answer if you strip information it actually needs to reason. If a user asks "is this email address on the blocklist?", removing the email makes the question unanswerable. This is why the reversible encrypt operator and careful entity selection matter — scrub what is risky, keep what is load-bearing.
Common pitfalls
Presidio is easy to start with and easy to over-trust. The failures almost always come from treating detection as perfect when it is statistical.
- Assuming 100% recall. NER-based detection for names and locations is probabilistic — it will miss some PII, especially unusual names, transliterations, or text in a language you did not configure. Presidio reduces risk; it does not guarantee zero leakage.
- Ignoring false positives. It will also flag things that are not PII (a product code that looks like an ID, a common word that doubles as a surname). Over-redaction quietly destroys the meaning your downstream model needs.
- Forgetting the language. Detection quality depends on the NLP model and language you load. Defaults are tuned for English; other languages need the right model configured or recall drops sharply.
- Not adding custom recognizers. Out of the box it knows generic entities, not your identifiers. Skipping custom recognizers is the number-one reason real PII slips through.
- Treating hashing as anonymization for low-entropy data. Hashing a value from a small, guessable set (like a 5-digit ZIP or a phone number) can be reversed by brute force. Hashing is pseudonymization, not a magic shield.
Going deeper
The basic analyze-then-anonymize loop is only the entry point. A few directions worth knowing once the fundamentals click.
Beyond plain text. The Image Redactor combines OCR with the same Analyzer to find and black out PII inside screenshots and scanned documents — useful when sensitive data lives in images, not strings. There is also dedicated support for structured data, so you can de-identify specific columns in a table or fields in JSON while leaving the rest intact.
Reversible de-identification. Because encrypt is reversible with a key, you can build a full round-trip: anonymize on the way into an external service, then de-anonymize the response on the way back. This is the pattern that lets you use a hosted LLM on sensitive workloads without the provider ever holding the real values.
Pluggable NLP engines. The default uses classic NLP libraries, but you can swap in a different NER backend — including transformer models — to improve recall on hard entities, at the cost of more compute. Presidio is deliberately modular here: the detection engine and the entities it knows are both replaceable.
Where it sits among safety tools. Presidio is a specialist: it does PII, and it does it well. Broader guardrail frameworks bundle PII detection alongside prompt-injection defense, toxicity filtering, and output validation. Many teams use a guardrail layer for the wide net and Presidio specifically for serious, customizable PII handling. PII scrubbing is one concrete example of the larger distinction between AI safety and AI security: you are not changing what the model believes, you are controlling what sensitive data is allowed to reach and leave it.
The durable lesson is that PII handling is a tuning and testing problem, not a switch you flip. Detection is statistical, your identifiers are unique to you, and the right operator differs per field. Budget time to add custom recognizers, set thresholds against your own data, and measure what leaks — that ongoing work, not the install, is where the real protection comes from.
FAQ
What is Microsoft Presidio used for?
Presidio is an open-source toolkit for detecting, redacting, and anonymizing personally identifiable information (PII) in text, images, and structured data. It is commonly used to scrub PII out of LLM prompts, application logs, and training datasets so sensitive personal data is not exposed or sent to third-party services.
Is Presidio free and open source?
Yes. Presidio is a free, open-source project maintained by Microsoft and runs entirely on your own infrastructure. That self-hosted design is part of the point: the data you are trying to protect never has to leave your environment to be cleaned.
How does Presidio detect PII?
It combines several techniques: regex patterns for predictable formats (emails, credit cards), checksums to validate them, named-entity recognition (NER) from an NLP model for fuzzy entities like names and locations, and context words that boost confidence. Each finding returns an entity type, its position in the text, and a confidence score.
What is the difference between the Presidio Analyzer and Anonymizer?
The Analyzer finds PII and labels what kind it is, without changing anything. The Anonymizer then acts on those findings using an operator — replace with a tag, mask some characters, redact entirely, hash, or reversibly encrypt. You can run the Analyzer alone, for example just to flag risky records.
Can I add my own PII types to Presidio?
Yes, and you usually should. You add a custom recognizer — typically a regex plus a few context words — to detect identifiers specific to your business, like internal account numbers or a country-specific national ID. Registering custom recognizers is the most common Presidio customization and the main way to stop your own PII from slipping through.
Does Presidio guarantee that all PII is removed?
No. Detection of fuzzy entities like names is probabilistic, so it can miss some PII and over-flag other text. Presidio is a strong risk-reduction control, not a compliance guarantee. You still need to tune thresholds, add custom recognizers, test on your own data, and add human review for high-stakes cases.