Applied concepts

Contextual PII and PHI detection in text

Find sensitive information in text with safe test data and careful review.

Start with purpose, context, and labels

Personally identifiable information concerns information that identifies or can help identify an individual, with definitions depending on the applicable policy or law. Protected health information has a specific contextual meaning under HIPAA: individually identifiable health information held or transmitted by covered entities or business associates, subject to applicable exclusions. Not every health-related word, organization, or anonymous statistic is PHI.

“The handbook discusses asthma” contains a health term but does not, by itself, identify a person's condition. “Patient [PERSON_A] received treatment for [CONDITION_A]” illustrates a potentially identifying health relationship in an appropriate regulated context. Even placeholders do not settle the legal status of a real record. The data holder, linkage possibilities, intended use, and surrounding metadata matter. Establish the processing purpose and authorized data scope before choosing a model.

Document-level classification answers “does this document need review?” It cannot reliably specify what to remove. Entity extraction predicts typed spans, such as PERSON, CONTACT, or RECORD_ID, with character start and end positions. A privacy workflow may combine document routing, span extraction, relationship/context rules, and human review. See text mining for the broader distinction between classification and sequence labeling.

Rules and named-entity recognition

A hybrid system uses format rules for structured identifiers and named-entity recognition for context-dependent entities. Rules can be transparent and precise for known formats, but punctuation changes and unfamiliar templates cause misses. Learned NER can generalize beyond rigid patterns, yet it can confuse ordinary words with names and fail on new document styles. Neither component is sufficient evidence of completeness.

For the synthetic text “Patient ALPHA arrived”, a simple token sequence might label Patient as O, ALPHA as B-PERSON, and arrived as O. In BIO tagging, B begins an entity, I continues that entity type, and O lies outside. A two-token placeholder name would use B-PERSON followed by I-PERSON. Specify how overlapping and nested entities are handled, since a single BIO sequence cannot naturally express every overlapping span.

Modern tokenizers may split one word into subwords. Align word annotations to subword positions explicitly: either train on the first subword and ignore subsequent pieces in the loss, or propagate labels consistently with the chosen BIO convention. Maintain tokenizer offset mappings back to the original text. Truncation can cut an identifier or discard the document tail; use overlapping windows and reconcile duplicate predictions before redaction.

Annotation and leakage-resistant splits

Create a written annotation guide with entity boundaries, contextual examples, ambiguous cases, and escalation rules. Have reviewers label a shared sample, discuss disagreements, and version the resolved guidance. Preserve uncertainty instead of forcing questionable cases into apparently certain ground truth. Synthetic development data should cover messy spacing, abbreviations, punctuation, unusual layouts, and ordinary non-sensitive text, not only easy positive examples.

Separate train and test by patient or person where authorized grouping is available, and by source/template family. Copies of one patient's note or lightly changed forms across partitions create data leakage. Include a held-out template set and, where possible, a later-time evaluation. Fit text preprocessing only on training data; freeze thresholds and rule versions before the final test. Follow data preparation and validation.

Measure spans and operational consequences

Exact entity precision is correctly typed, exactly bounded predictions divided by all predicted entities. Recall is those correct predictions divided by all labeled entities. If a synthetic test contains 20 gold entities, the system predicts 18, and 15 match exactly, precision is 15/18 ≈ 0.833 and recall is 15/20 = 0.75. Token accuracy can look excellent simply because most tokens are O; it is not the main privacy measure.

Partial-overlap metrics help diagnose boundary errors, but can conceal exposed characters. A prediction covering only part of an identifier is not successful redaction. Report exact and partial results separately, with explicit one-to-one matching rules, entity-type breakdowns, missed documents, and reviewer workload. False negatives may leave sensitive information exposed; false positives can remove useful clinical or business context. The acceptable operating point requires stakeholder approval, not an automatic preference for one metric.

Safe offsets and controlled handling

Store spans as half-open intervals [start, end) into the original text under a documented indexing convention. Unicode normalization, OCR correction, or whitespace cleanup can change offsets. Keep a reversible mapping where needed and test non-ASCII text. Merge overlapping removal intervals, then replace from right to left so earlier offsets remain valid. Re-scan rendered output and metadata; masking visible text alone may leave identifiers in filenames or hidden content.

Minimize retained data, use approved encryption in transit and at rest, restrict access with least privilege, and define retention and deletion rules. Audit logs should record authorized actions, versions, and review decisions without copying raw protected text. Never put raw protected data in debugging output, model examples, tickets, or public repositories. Treat trained artifacts and embeddings as potentially sensitive too. Route uncertain cases into restricted review, and document limitations in the release record.

Can a high recall score justify automatic public release?

No. Test recall is an estimate under a particular sample and labeling policy. New templates, rare identifiers, contextual linkage, and redaction bugs remain possible. Apply the approved disclosure process and required human review.

What tests would be most useful first?

Use synthetic fixtures for exact offsets, adjacent and overlapping spans, Unicode, long-document windows, negative health-language examples, and patient/template split isolation. Verify the final redacted output, not only model predictions.

Definition

View in glossary →