Guide · Layer 05 · Guardrails
A de-identification layer for regulated AI
The reason AI stalls in healthcare, finance, legal, and insurance work is rarely the model. It is that the input contains identifiers that must not reach anything outside a defined boundary, and a policy document is doing the job an architecture should do. A de-identification layer moves that guarantee into the system: identifiers are found and replaced before a model sees the text, and put back only inside the boundary. This guide sets out how to build one.
- Series
- 09 of 09
- Sections
- 06
- Updated
- Sep 14, 2026
- Reading time
- 10 min
- Written for
- Developers + operators
The boundary problem
Every regulated workflow has a line around it: inside the line, identified data may be processed by systems the organization controls under its own policies; outside it, only data that has been de-identified, or a counterparty under contract, may see anything. A public API is outside the line. So is a logging service, an analytics tool, a vendor's support console, and any model whose weights might later be trained on what it saw.
Running the model locally moves inference inside the line, which is the first and largest step. But a local model does not by itself prevent identifiers from reaching a log file, an evaluation set, a fine-tuning corpus, or a screenshot in a bug report. The de-identification layer is what makes the guarantee hold across the whole path, not just at the model call.
What counts as an identifier
The answer is set by the regulation, not by intuition. Under HIPAA, the Safe Harbor method lists eighteen categories of identifiers that must be removed for data to be considered de-identified: names, geographic subdivisions smaller than a state, all elements of dates except year (for people, and all ages over 89), telephone and fax numbers, email addresses, Social Security numbers, medical record numbers, health plan beneficiary numbers, account numbers, certificate and licence numbers, vehicle identifiers, device identifiers, URLs, IP addresses, biometric identifiers, full-face photographs, and any other unique identifying number, characteristic, or code. The alternative, Expert Determination, requires a qualified expert to document that re-identification risk is very small.
Other regimes draw the line differently (GDPR's notion of personal data is broader; financial regulations name account and card numbers specifically), and a layer should be configured per regime rather than hard-coded to one. The categories above are a good default list for any document that describes a person.
The layer, end to end
┌──────────────── inside the boundary ────────────────┐
raw text ──► detect ──► replace ──► [pseudonymized text] ──► model ──► output
│ │ │
│ vault: token ↔ original │
│ └──────────────── re-identify ◄───────────────┘
▼
audit log (what was found, what was replaced, by which rule)Detect
Detection is two mechanisms working together. Rules catch anything with a shape: Social Security numbers, phone numbers, email addresses, dates, medical record numbers with a known format, account numbers with a check digit. They are fast, deterministic, and easy to audit. A named-entity model catches what has no shape: person names, organizations, locations, ages written in prose. Open-source toolkits in this space (Microsoft's Presidio is the reference example) combine both and run entirely locally; the NER component is a small transformer or a spaCy pipeline that runs on CPU or any GPU. Both mechanisms must run on the local box; a de-identification service that calls out to a cloud API has moved the boundary, not enforced it.
Replace
There are two choices for what goes in the identifier's place, and the model's task decides between them:
| Method | What the model sees | Use when |
|---|---|---|
| Redaction | [NAME], [DATE], [MRN] | The identity is irrelevant to the task: classification, coding, summarization of a single document |
| Pseudonymization | PATIENT_4821, DATE_2, consistent within a session | The task needs to track the same person or date across a document or set: reasoning about a timeline, comparing records, extraction with cross-references |
Pseudonymization preserves structure the model needs: it can tell that the same patient appears twice and that one date is thirty days after another (date shifting, which offsets all dates by a consistent random interval per record, keeps intervals while destroying the actual dates). The mapping between surrogate and original lives in a vault inside the boundary, encrypted at rest and keyed per session or per record, and it is the only place re-identification is possible.
Re-identify
The model's output refers to surrogates. Inside the boundary, the vault maps them back so the result can be filed against the real record. This is the step that lets the workflow be useful rather than merely safe, and it is the step to guard hardest: re-identification is a privileged operation, logged, and available only to the component that files the result, not to the interface a person reads the model's answer in.
Audit
Every document that passes through the layer produces an audit record: which detectors ran, what categories were found and how many, which replacement method was used, and a hash of the input and output. The record contains no identifiers itself. It is what lets a compliance reviewer verify the layer did its job without reading the data, and it is what turns "the policy says" into "the log shows".
Where the layer sits in a local stack
- Before [retrieval](/local-ai/private-rag) indexing. Chunks are de-identified before embedding, so no vector encodes an identifier and the index can be treated as de-identified data.
- Before [fine-tuning](/local-ai/fine-tuning). A training set is de-identified before it is written to disk. Models memorize; an identifier in the weights is an identifier that can be prompted back out.
- Before evaluation sets and logs. The two places identifiers most often leak in practice are the eval set a developer keeps locally and the debug log that captured a prompt.
- At every model call, even a local one, so that the guarantee does not depend on remembering which path is which.
Testing the layer
- Never test on production data. Build a synthetic corpus: generated documents with known planted identifiers of every category, in the formats and prose styles the real corpus uses. A handful of libraries generate realistic fake records; the plant list is the ground truth.
- Measure recall per category. The number that matters is how many planted identifiers the layer missed, by category. Precision matters less; an over-eager detector that redacts a drug name as a person's name is a nuisance, and a detector that misses one Social Security number is a breach.
- Test the edge shapes. Names inside email addresses, dates written as words, record numbers with a prefix the rule did not expect, identifiers split across a line break in a scanned document.
- Run the suite on every change to a rule, a model, or a document format. Recall is the regression metric.
- Test re-identification separately. Round-trip a synthetic document through pseudonymize and re-identify and confirm the output is byte-identical to the input. Then confirm that the same call fails, and is logged, from outside the boundary.
# Recall per category on a synthetic corpus with known plants.
from collections import defaultdict
found, planted = defaultdict(int), defaultdict(int)
for doc in synthetic_corpus: # each has doc.text and doc.plants
spans = deidentifier.detect(doc.text) # [(start, end, category), ...]
for plant in doc.plants:
planted[plant.category] += 1
if any(s <= plant.start and e >= plant.end for s, e, _ in spans):
found[plant.category] += 1
for cat in planted:
print(f"{cat:<12} recall {found[cat] / planted[cat]:.3f} ({found[cat]}/{planted[cat]})")What the layer does not do
It does not make a system compliant on its own. Compliance is a property of the whole program: access controls, business associate agreements with any vendor inside the line, breach procedures, training, and documentation. The layer is the technical control that makes one specific guarantee true (identifiers do not reach the model or anything downstream of it) and provable (the audit log). It is necessary for AI in regulated work, and it is not sufficient.
Strygon architects this layer as part of local and private AI deployments for healthcare, insurance, and other regulated operators, and it is the engine underneath its own products. It is scoped in writing before anything is built.