Named entity recognition (NER) finds PII by reading context: a trained model labels spans of text as people, organizations, locations, dates, or identifiers based on the words around them, not a fixed pattern. That lets it catch names and addresses in free text that regular expressions can't describe, while regex stays the better tool for rigidly formatted values like card or account numbers. NER still misses ambiguous mentions, domain-specific entities, and the link between mentions of the same person, which is why reliable de-identification layers it with patterns, verification, and consistent replacement.
How NER for PII detection works
Named entity recognition is a token-classification task. A model splits text into tokens (words or pieces of words), reads each token in the context of the tokens around it, and assigns it a label such as person, organization, location, date, or identifier. Neighboring tokens that share a label form a span: the exact stretch of text the model marks as one entity. Because the decision rests on context rather than on the characters themselves, the same string can earn different labels in different sentences. That context sensitivity is what makes NER the main detection method for de-identification of free text, where sensitive values rarely follow a format.
| Sentence | What a PII-focused model labels |
|---|---|
Jordan called about the Jordan account on Friday. | first "Jordan" → person · second "Jordan" → organization · "Friday" → date |
She's booking flights to Jordan in March. | "Jordan" → location · "March" → date |
The surrounding words do the work. "Called" signals a person, a proper noun before "account" suggests a customer or company, and "flights to" signals a place. No pattern can separate those three cases, because the characters are identical. A model learns these cues from labeled examples, so its training data decides what it can find.
That's also why a PII-focused model behaves differently from general-purpose NER. Open-source libraries such as spaCy ship models trained largely on news and web text, with label sets built for information extraction: PERSON, ORG, GPE (geopolitical entity), and similar. A model trained for personally identifiable information learns a finer, privacy-oriented label set (given and family names, street addresses, account and record numbers, birth dates) from examples annotated with exactly those categories. Tonic Textual takes this approach. Its proprietary NER models are built for domain text that general-purpose detectors handle poorly, such as clinical notes, legal documents, and call transcripts.
Detection is the first step of data de-identification, whether the source is a database export or unstructured data like emails, tickets, and notes. Nothing can be replaced, masked, or tokenized until it has been found, and anything the detector misses passes through untouched.
NER vs. regex for PII detection
Regex matches format and NER matches meaning, and each wins on a different set of entity types. A regular expression is a pattern over characters: sixteen digits in groups of four, a local part and a domain around an @ sign, four dot-separated numbers. For values with a rigid structure, that's hard to beat. A pattern is deterministic, fast enough to run over every line of a corpus, and when it fires, you can point to exactly why. Paired with validation, such as a checksum on a card number or the check digits on an IBAN, it's also precise.
The weakness is everything without a fixed shape. No pattern describes a person's name, an address written into a sentence, or a word whose PII status depends on context. Even formatted values drift: phone numbers vary across locales, dates appear as 03/04 or "the fourth of March," and identifiers pick up stray spaces and dashes. Patterns also misfire, since a nine-digit order number matches an SSN pattern as readily as a real SSN does. Each fix adds another rule, and a long regex list becomes its own maintenance project.
NER covers that contextual ground, but it's probabilistic. A model can miss a span, clip its boundary, or assign the wrong label, and running a neural model costs more compute than evaluating a pattern. Its decisions are also harder to trace than a rule match. Toolkits such as Microsoft Presidio, which is free, customizable, and ships with many built-in recognizers, combine both methods, though their reliance on patterns means contextual accuracy trails purpose-built NER.
So the practical question isn't which method to adopt but which entity types each should own. That decision belongs at the start of de-identifying a dataset, when you inventory which sensitive values exist and what shape they take. Tonic Textual reflects the same split: its built-in models cover common PII, and regex-based custom entity types handle your own fixed-format values.
| NER | Regex | |
|---|---|---|
| How it decides | A trained model labels tokens based on surrounding context | A pattern matches the characters of the value |
| Best-fit entity types | Names, organizations, addresses in prose, context-dependent values | Card numbers, IBANs, email addresses, IP addresses, fixed-format IDs |
| Typical failure | Missed or clipped spans, mislabels on unfamiliar text | Misses unformatted values; false positives on look-alike numbers |
| Explainability | Probabilistic; harder to trace a single decision | Deterministic; every match traces to a rule |
| Maintenance | Retraining or tuning when the text domain changes | A growing rule list that has to be kept consistent |
Why PII detection methods work best in layers
Production detection pipelines combine methods because each covers blind spots in the others. A common layering runs in order:
- Patterns for fixed formats. Regex with validation catches card numbers, email addresses, and similar values cheaply and precisely.
- NER for contextual entities. A trained model labels names, organizations, addresses, and other spans no pattern can describe.
- Verification. A rules pass or an LLM reviews the candidate spans, rejecting false positives and resolving ambiguous labels before anything is transformed.
The Tonic Advantage: NER for coverage, an LLM for judgment. Tonic Textual runs this architecture. Its NER models propose the candidate entities, and an LLM then checks them, discarding spans that turn out not to be sensitive and labeling the key-value pairs and form fields found in PDFs. Textual's NER model is a small, efficient encoder-based model rather than an LLM, so it's much faster and cheaper to run than using an LLM for PII detection.
Each layer is tuned against the tradeoff between precision and recall. Precision is the share of flagged spans that really are PII; recall is the share of the real PII that gets flagged. A detector can raise precision by flagging only what it's sure of, but for privacy, recall carries more weight. A false positive costs some usefulness in the output, while a missed mention leaves a real person's data in the text. So the early layers catch broadly, and verification cleans up after them.
Frontier LLMs can also serve as the detector on their own, and they're capable at it: they read context well, they're often already in the stack, and there's no new tool to approve. The constraint is cost: running a large general-purpose model over every document in a corpus is expensive, which is why LLMs often fit best in the verification role.
Against human-annotated data in Tonic.ai's PrivacyBench benchmark, Tonic Textual posted the two highest PII-detection F1 scores of any engine tested, 92.5% and 92.1%, ahead of frontier LLMs from OpenAI and Anthropic and the open-source tools Presidio and GLiNER2. F1 combines precision and recall into one score, rewarding a detector that catches broadly without flooding the output with false positives. Tonic.ai built the benchmark and published its datasets and scoring code, so teams can score their own detection pipeline against the same public datasets.
Where NER falls short in de-identification
Even accurate NER leaves gaps, and in data de-identification those gaps decide what survives into the output.
Domain shift
A model learns the language of its training data. One trained on news and web text meets unfamiliar ground in clinical notes full of abbreviations, legal filings with their own naming conventions, or call transcripts where speech-to-text has turned a surname into an ordinary word. Recall tends to drop exactly where the most sensitive text lives.
Ambiguity and span boundaries
NER can find the right entity and still clip its edges. If the model tags "Dr. Ana" but leaves "Ruiz" outside the span, the surname survives de-identification. Ambiguous mentions, like a surname that's also a street name, produce errors in both directions.
Quasi-identifiers
A quasi-identifier is a detail that names no one on its own but can identify a person in combination with others. "The only pediatric cardiologist in a town of 900, seen last Tuesday" contains no name, and NER will flag at most the date. NER labels entities; it doesn't assess combined identification risk, which is the mechanism behind re-identification.
No memory across mentions
NER labels each mention independently, so it doesn't know that "Ana," "A. Ruiz," and an aruiz@ email address are one person. Replace each separately and one patient becomes three people in the output. Consistent replacement covers part of this: Tonic Textual keeps replacements consistent across files, so the same value isn't replaced one way in one file and another way in the next. Recognizing that different forms of a name belong to one person takes entity resolution on top of detection. For de-identifying company data, Tonic.ai's de-identification service pairs Textual's detection models with Identity Synthesis, Tonic's proprietary approach to entity resolution and synthesis, which links every mention of a person or organization to the identity it belongs to and gives each one a unique synthetic identity used everywhere they appear.
Free text isn't optional, either: HHS guidance on de-identification states that meeting HIPAA's Safe Harbor method means removing identifiers from free-text fields, not only structured ones. And what you do with the detections shapes the result as much as finding them. Blanking every span leaves text that's safe but hard to use, while consistent replacement keeps it readable, which is the core difference between redaction and anonymization.
Tuning NER for your own entity types
Built-in entity types cover common PII, but every organization also holds sensitive values no general model knows about: internal account IDs, product codenames, claim or case numbers, the names of health conditions in a care-management system. In Tonic Textual, for example, the built-in entity types cover names of people and organizations, locations and addresses, and identifiers and account numbers, and anything outside that set needs custom entity recognition. The decision rule follows the NER-versus-regex split: values with a consistent format get a pattern, and values identified by context need a trained model. An account ID made of a fixed prefix and eight digits is a regex. Condition names scattered through free-flowing notes call for a model.
The model-based path works like a small annotation project:
- Write guidelines that describe the entity in plain language, including edge cases and what doesn't count.
- Confirm the true values in a small set of test files, so you have a definitive answer key.
- Refine the guidelines until detections on the test files match the confirmed values.
- Train on a larger set of data annotated against the refined guidelines.
- Review the model's detections against the test set before turning it on.
Most of the quality is won in the first three steps. A vague definition produces a model that's confidently inconsistent, and tightening the guidelines against confirmed values is cheaper than retraining after the fact.
The Tonic Advantage: custom entity types for both kinds of value. Textual supports both paths. Regex-based custom entity types handle fixed-format identifiers, while model-based custom entity types let you iterate on text guidelines against confirmed test values, then train models and select the one to activate. For values that have already been modeled, Textual also offers a library of pre-trained entity types you can import instead of building from scratch.
Detection then feeds whatever comes next. Replacing detected values through synthetic replacement, with realistic stand-ins rather than placeholder tags, keeps text readable and close to the original in structure. That matters for downstream work such as removing PII from fine-tuning data, where a model trained on placeholder-filled text learns to produce placeholders.