Home
›
Articles
›

Better PII Redaction

Better PII Redaction

By Ibi Hasanli

·

·

4 min read

PII redaction looks simple until real text arrives. Names appear without labels, account numbers resemble harmless identifiers, phone numbers come in many formats, and business documents mix structured facts with free-form language. A reliable redaction pipeline needs more than one detector.

A practical approach is to combine Microsoft Presidio with GLiNER. Presidio gives you a mature framework for detecting, scoring, explaining, and anonymising sensitive entities. GLiNER adds flexible named-entity recognition that can identify custom categories from natural-language labels without training a new model for every project.

Why Presidio?

Presidio is useful because it treats redaction as an engineering system, not just a model call. It includes recognisers for common data types such as email addresses, phone numbers, credit-card numbers, IP addresses, URLs, and national identifiers. It also provides an analyser engine, confidence scores, context-aware detection, and an anonymiser engine for replacing, masking, hashing, or encrypting detected values.

This makes Presidio a strong foundation for compliance-heavy workflows. You can inspect why something was detected, tune thresholds, add deny lists, define custom recognisers, and apply different anonymisation strategies depending on the entity type.

Where GLiNER helps

Rule-based and pattern-based detection works well for structured identifiers, but it can miss soft PII: people, organisations, locations, job titles, patient names, customer references, or internal project names. This is where GLiNER is valuable.

GLiNER can detect entities based on labels you provide, such as person name, company name, medical condition, bank name, or internal employee identifier. That flexibility helps teams adapt redaction to their own documents without building a fully supervised NER dataset first.

A hybrid architecture

A robust pipeline usually looks like this:

  1. Normalise input: extract text from PDFs, emails, tickets, logs, chat transcripts, or documents.
  2. Run Presidio recognisers: detect structured PII such as emails, phone numbers, card numbers, IPs, URLs, and known identifiers.
  3. Run GLiNER: detect contextual entities such as names, organisations, addresses, projects, departments, or domain-specific sensitive terms.
  4. Merge spans: deduplicate overlapping detections and keep the strongest confidence score or most sensitive entity type.
  5. Apply redaction policy: replace entities with tags such as <PERSON>, mask partial values, hash identifiers, or remove them entirely.
  6. Log safely: store only metadata about the redaction process, not the original sensitive text.

Example detection strategy

Presidio should handle high-precision recognisers first. For example, emails, payment card numbers, phone numbers, and IP addresses are usually better detected with specialised logic than with a general NER model. GLiNER can then add broader semantic coverage for labels such as:

  • person name
  • home address
  • company name
  • customer identifier
  • medical record reference
  • financial institution
  • internal project name

The key is not to let every model output become an automatic deletion. Use confidence thresholds, entity-specific rules, and document context. A customer support ticket, a medical note, and a firewall log each need different redaction policies.

Handling overlapping entities

Hybrid detection creates overlaps. A phrase such as Jane Smith, Acme Bank might be detected by GLiNER as a person and organisation, while Presidio may also recognise part of the text through a custom recogniser. The redaction layer should merge overlaps before modifying the text. Otherwise, offsets can shift and produce broken redactions.

A simple policy is to sort spans by start position, prefer longer spans when confidence is similar, and preserve the most sensitive label when two detections overlap. For regulated data, it is usually safer to over-redact than to leak sensitive information.

Choosing anonymisation methods

Not every use case needs the same output. For analytics, replacing names with stable hashes may preserve useful grouping without exposing identities. For logs sent to an LLM, simple tags like <EMAIL> or <PERSON> may be enough. For documents shared externally, irreversible removal may be the safest option.

  • Replace: [email protected] becomes <EMAIL>.
  • Mask: +44 7700 900123 becomes +44 77** ***123.
  • Hash: identifiers become consistent pseudonyms for analytics.
  • Encrypt: sensitive values can be recovered by authorised systems only.

Testing redaction quality

Redaction should be tested like any other security-sensitive feature. Build a test set with realistic examples, edge cases, false positives, and false negatives. Include messy formats, OCR errors, abbreviations, international phone numbers, names with punctuation, and domain-specific identifiers.

Track precision and recall separately. Low precision means useful text is removed unnecessarily. Low recall means sensitive data leaks. Most organisations should optimise recall first, then reduce false positives through better recognisers, labels, thresholds, and allow lists.

Common pitfalls

  • Relying only on regex: patterns miss contextual PII such as names and organisations.
  • Relying only on NER: models can miss structured identifiers that deterministic recognisers catch well.
  • Ignoring offsets: redacting text in the wrong order can corrupt spans.
  • Logging raw input: debug logs can accidentally become a second PII store.
  • Using one policy everywhere: different document types need different thresholds and labels.

Final thought

Presidio and GLiNER are stronger together than either is alone. Presidio provides the redaction framework, explainability, and anonymisation controls. GLiNER adds flexible semantic detection for the sensitive entities that rules often miss. Together, they form a practical foundation for protecting data before it enters analytics systems, search indexes, support tools, or LLM workflows.

AI
Decision models

Jev vs Laya

Jev vs Laya for UK tech leads: when to call TypeSafe's hosted decision API and when to self-host the open-weight Laya model on your own infrastructure.

·

4 min read

AI
agents

AI Model vs Agentic Harness

AI Model vs Agentic Harness: the model is capability you call; the agentic harness is tools, loops, memory, and policy around it.

·

3 min read

AI
agents

Skills vs MCP vs RAG vs Memory

Skills vs MCP vs RAG vs Memory: how agent workflows, tool connectors, retrieval, and durable state differ.

·

4 min read

AI

AWS Bedrock

A practical guide to building secure generative AI applications without managing foundation model infrastructure.

·

2 min read

AI

LLM vs LRM vs LDM

A concise guide to three model families shaping language, reasoning, and generation.

·

2 min read

AI

Vector Databases

How similarity search works under the hood, what the index types trade against each other, and how to choose a store without over engineering the problem.

·

9 min read

AI

Securing AI Systems

The threats specific to language model applications, why prompt injection has no clean fix, and the architectural decisions that actually contain the damage.

·

9 min read

AI

LangChain and LangGraph

What each library actually does, where the split between them lies, when a framework earns its place in your stack, and when plain code is the better answer.

·

6 min read

AI

LLMOps in Practice

What it takes to run a language model feature in production: evaluation, versioning, cost control, observability, and the failures monitoring never catches.

·

7 min read

AI

How RAG Works

Retrieval augmented generation explained properly: what happens at each stage, why the retrieval half is where projects succeed or fail, and how to evaluate it.

·

8 min read