Privacy and preparation
Regex vs NER vs LLM redaction: which catches more PII in free text?
By SourceX Editorial · Updated
Short answer
Neither regex, NER nor LLM redaction alone catches the most PII in free text. Regex is strongest on structured identifiers such as card numbers, emails and API keys; NER models find names, organizations and places; an LLM pass catches contextual leaks the others miss. A layered pipeline, checked by human sampling, catches more than any one method alone.
Key takeaways
- Regex is precise and stable on structured identifiers but blind to names and context.
- NER models find person and organization names but struggle with lowercase chat, ticket shorthand and names that are also common words.
- An LLM pass finds indirect identifiers and sensitive context, at a cost in consistency, speed and data handling.
- Dictionaries built from your own employee and customer lists often beat every generic detector on known names.
- Human review of a random sample is the only way to know what the pipeline still misses.
Which method catches more PII in free text?#
No one method catches the most PII in free text, because regex, NER and LLM detection are built for different kinds of identifiers. The useful question is which combination leaves the fewest misses in your own records at a cost and speed you can accept.
Mature open-source tools already combine methods. Presidio, an MIT-licensed PII toolkit, combines named-entity recognition, regular expressions, rule-based logic and checksums with context. Its documentation also warns that automated detection gives no guarantee of finding all sensitive information and that additional systems and protections should be employed.
Presidio has moved from a Microsoft-owned project to an independent, community-governed one under the Data Privacy Stack organization on GitHub, a change recorded in a June 2026 release, and it remains MIT-licensed.
Decision matrix: which method fits which identifier#
A decision matrix assigns each identifier type to the method that handles it best, with the others as backup. The ratings below are qualitative and describe typical behavior on business text such as support tickets, email and CRM notes.
Read the matrix as a starting point, not a verdict. A support desk that pastes logs needs heavier secret rules, while a consulting firm's email needs stronger name and context handling.
| Identifier type | Regex | NER model | LLM pass |
|---|---|---|---|
| Card numbers, SSNs, bank account numbers | Strong, especially with checksums | Weak | Partial |
| Emails, phone numbers, URLs | Strong | Partial | Partial |
| API keys, tokens, passwords | Strong with secret rules | Weak | Partial |
| Person names in formal text | Weak | Strong | Strong |
| Names in chat shorthand or lowercase | Weak | Partial | Strong |
| Organization and place names | Weak | Strong | Strong |
| Indirect identifiers, such as a unique title at a named site | Weak | Weak | Partial to strong |
| Health, family or other sensitive context | Weak | Weak | Strong |
- 01Your work records
- 02Personal details removed
- 03You approve the release
- 04Licensed to AI developers
What regex does well and where it fails#
Regex does well on anything with a fixed shape: email addresses, phone formats, card numbers validated with a checksum, government ID formats, IP addresses and known key prefixes. It is deterministic, fast, cheap and easy to audit, and it behaves the same on next year's records as on this year's.
Regex fails on anything that depends on meaning. It cannot tell a person's name from a product name, and it over-matches numbers that look like IDs, such as order numbers, part numbers and invoice references. Over-matching quietly destroys useful content, so test every pattern against real records before running it at scale.
What NER adds, and what it misses#
NER, or named-entity recognition, adds the ability to find people, organizations and places from context, which regex cannot do. Cloud services offer the same idea as managed APIs: the Amazon Comprehend developer guide, in its June 2023 snapshot, listed 22 universal PII entity types, including NAME, ADDRESS, EMAIL and PHONE as well as credential types such as PASSWORD and AWS_SECRET_KEY.
NER models are often trained on clean, formal text, and business records are not clean. Lowercase names in chat, first names on their own, names that are also ordinary words, and agent or technician names inside templated signatures are common misses. Product and feature names are common false positives.
Test any model on a sample of your own tickets or emails before trusting it. Performance on news articles says little about performance on a dispatcher's shorthand or a support agent's macro.
What an LLM pass adds, and the risks it brings#
An LLM pass adds judgment about context: it can flag that the only site manager at a named depot is identifiable, or that a note about a caller's oxygen equipment is health information. Those contextual leaks are exactly the misses that regex and NER leave behind.
The risks are real. Output can vary between runs, models sometimes rewrite text they were asked only to inspect, and long archives make the pass slow and costly. Sending records to an external API also raises its own data handling questions before any redaction happens.
Use the LLM to return flagged spans with a reason, not to rewrite the record, and apply replacements with deterministic code. That keeps every edit auditable and lets a reviewer accept or reject each flag.
A layered redaction pipeline#
A layered redaction pipeline runs cheap, precise methods first and expensive, contextual ones last, then measures what is left with human review. Each layer reduces the load on the next.
The dictionary step is often underrated. Your directory of employees and your list of customer contacts name exactly the people most likely to appear, and an exact match on those lists catches names that generic models miss.
- Normalize text: strip HTML, extract text from in-scope attachments and keep record IDs.
- Run a secret scanner and rotate any live credential it finds.
- Apply regex rules with checksums for structured identifiers.
- Match exact names from your employee directory, customer list and vendor list.
- Run an NER model for remaining person, organization and place names.
- Run an LLM pass over residual text to flag indirect identifiers and sensitive context.
- Replace every finding with consistent placeholders using deterministic code.
- Review a random sample of processed records by hand and log every miss.
Illustrative: a field service software company tests three approaches#
Illustrative: a fictional company that sells field service software to HVAC and plumbing contractors wants to prepare years of Zendesk tickets. The tickets mix customer emails, agent replies, pasted error output and technician notes that customers forwarded.
A regex-only pilot removed emails, phone numbers and keys cleanly but left technician first names, customer company names and a ticket that described a homeowner by their medical equipment. Adding a dictionary of agent and customer names plus an NER model fixed most name misses. An LLM flagging pass, run on a model hosted inside the company's own cloud account, caught most of the remaining contextual cases.
The reviewers' sample showed far fewer misses with all layers than with regex alone, and the team documented which layer caught which category. That record answered counsel's first question about the method.
How SourceX approaches redaction methods#
SourceX treats the redaction method as part of the Preparation step in the SourceX five-step transaction, chosen per record family rather than one tool for everything. The supplier approves the method and the sample review results before Approval.
The layers used, the sample reviewed and the misses found are recorded in the privacy record of the SourceX Evidence Packet.
Frequently asked questions
Is an open-source tool like Presidio enough on its own?
Presidio combines regex, NER, rules and checksums, which covers a lot, but its own documentation says there is no guarantee it will find all sensitive information. Most teams add custom recognizers for their own identifiers, a name dictionary and human sampling. Treat it as a strong base layer, not a finished pipeline.
Can the LLM pass run without sending data to an outside provider?
Yes. Teams run open-weight models on their own hardware or inside their own cloud accounts, or use provider offerings with contractual data protections. Each route has trade-offs in cost, accuracy and setup effort, and the data handling terms deserve as much review as the model's accuracy.
How do we measure what the pipeline misses without labeled data?
Draw a random sample of processed records, have trained reviewers read them in full, and log every miss by type and by the layer that should have caught it. Repeat after each pipeline change. The miss log shows which layer to improve and gives counsel evidence of how the method performs.
Should findings be removed or replaced?
Replacing findings with consistent placeholders usually keeps more value than deleting them, because the text still reads naturally and relationships between people survive. Deletion suits secrets and content with no analytical value. The choice can differ by identifier type within the same pipeline.
Does a layered pipeline make preparation much slower?
It adds steps, but the cheap layers handle most findings quickly and the expensive LLM pass runs only on residual text or flagged records. The larger time cost is usually human review, which no method removes, so plan reviewer time from the start.
Sources
- Presidio is an open-source, MIT-licensed SDK for PII identification and anonymization in text and images. It combines named-entity recognition, regular expressions, rule-based logic and checksums with context. Source
- Presidio's own documentation warns that "because it is using automated detection mechanisms, there is no guarantee that Presidio will find all sensitive information. Consequently, additional systems and protections should be employed." Source
- Presidio has moved from a Microsoft-owned project to an independent, community-governed open-source project under the GitHub organization Data Privacy Stack. The move was recorded in release 2.2.363, dated 2026-06-28, and the project remains MIT-licensed. Source
- As documented in the Amazon Comprehend Developer Guide archived on GitHub in June 2023, Comprehend detects 22 universal PII entity types, including NAME, ADDRESS, EMAIL, PHONE, CREDIT_DEBIT_NUMBER, CREDIT_DEBIT_CVV, PASSWORD, AWS_ACCESS_KEY and AWS_SECRET_KEY. Source
Related resources
- IndustryBPO & contact centers data
- QuestionDo AI labs buy medical data?
- QuestionDo AI labs buy video of people working?
- InsightHow do I de-identify customer support transcripts for AI training?
- InsightHow do I de-identify IT service tickets for AI training?
- InsightPurpose limitation: can records collected for one purpose be licensed for AI?
See if your company qualifies
A short company assessment. No data uploads are needed.