Skip to main content

Software Sushi JournalHealthcare AI & privacy engineering

PII and PHI Redaction Before the LLM

Checksums, language-routed NER, fail-closed PDF parsing, and an offset-only PostgreSQL ledger inside your AWS VPC—with measured engineering numbers.

Deep olive archival binder separated by a fluted smoked-glass slab in an amber ceramic channel from clean botanical-green cards on clinical alabaster stone.

Interactive VPC boundary

What stays inside your VPC versus what crosses to the LLM

Step through the four stages of a customer-hosted redaction boundary. Every stage separates parsing, detection, policy action, and audit evidence.

Redaction pipeline stage

Accept text, JSON, PDFs, or LLM API calls inside your account

Documents enter over HTTPS, S3, or a drop-in OpenAI, Anthropic, Bedrock, or MCP proxy path inside your AWS VPC. Digital PDFs extract text locally; encrypted, malformed, or image-only PDFs fail closed unless an opt-in OCR sidecar or Textract is configured.

Stays inside buyer VPC
Raw text, PDFs, and caller metadata
Crosses the boundary
Nothing leaves during parsing

If you ask a language model to ignore sensitive fields, you have already sent those fields outside your boundary. A real privacy control runs inside your own VPC before a prompt, clinical note, or PDF reaches an external model API. It combines deterministic checksum validators with language-routed NER, applies an inspectable policy, and writes value-free audit evidence.

Software Sushi built and ships this boundary on AWS Marketplace across Redactor (v1.0.13 for text, JSON, S3, and PDF pipelines) and Redactor AI Gateway (a drop-in VPC proxy for OpenAI, Anthropic, Amazon Bedrock, and MCP tool traffic). Every benchmark cited below comes from our published Redactor evaluation and release records and states its synthetic corpus and limits.

Why prompt rules are not a data boundary

A BAA covers the contractual relationship with a model provider, not your application's error logs, tool arguments, or misconfigured retries. Before you even negotiate model retention, stripping identifiers that the task does not need shrinks the blast radius across prompts, caches, observability tools, and downstream APIs.

If your team is still mapping legal agreements and application readiness gates, pair this architecture guide with our six checks before sending PHI to an LLM and evaluating application readiness for PHI.

Checksums, NER, and detector agreement

Pure regular expressions miss unlabelled names and street addresses in clinical prose. Pure NER models hallucinate entity spans on structured headers and over-match arbitrary IDs. Production pipelines combine both layers and separate deterministic structure from probabilistic predictions.

In Redactor's bundled detector pack, checksummed and structure-anchored recognizers cover Luhn cards and labelled NPIs, mod-97 IBANs, VIN check digits, CPF, CNPJ, DNI/NIE, CURP, Dominican cédulas, HL7 v2 PID-5/NK1-2, FHIR HumanName fields, E.164 phone numbers, OCR line-wrapped SSNs, and CSV/TSV column headers. On our 1,900-document synthetic stress corpus, expanding these structured recognizers lifted regex-only recall from 55.2% (v1.0.1) to 89.8% (v1.0.3) and 91.8% (v1.0.4) while false positives dropped from 285 to 190, with zero false positives across 100 hard-negative documents. On the CSV stress corpus, header-aware column detection raised regex-only recall from 71.4% to 90.5% with zero false positives.

Adding Presidio NER catches unlabelled names and addresses, but detector confidence scores can mislead operators if you merge them carelessly. When one detector emits adjacent pieces of the same entity, keep that detector's strongest score (such as 0.85) instead of compounding it into false certainty (0.98). Confidence should rise only when independent detectors agree.

On the synthetic luna corpora (regex plus bundled analyzer, v1.0.5), corroborated spans claimed by two or more detectors were 97% to 100% accurate, whereas single-source spans were 71% to 94% accurate. No single confidence floor separated those groups without dropping valid regex matches. That is why policy rules work better when they match on detector agreement (corroborated versus single_source), and why evaluation should report both strict recall (exact label match) and protected_recall (any redaction covering the span so a name tagged as LOCATION is tracked as a label error rather than a leak).

Try the synthetic redaction sandbox

Use the browser sandbox below to switch between synthetic English notes, Spanish referrals, and prompts containing API credentials. Inspect how detector agreement, language routing, and gateway blocking change both the outbound payload and the value-free ledger record.

Interactive synthetic sandbox

Inspect detector agreement, language routing, and the offset-only ledger

Demo with synthetic notes and deterministic toy rules running in your browser. Not a clinical tool, production detector, or compliance check.

1. Synthetic input
2. Detector layer
3. Policy action
Inside VPC · original synthetic input

Structured labels, checksummed digits, and NER

Patient: Elena Vance | MRN-440219 | Email: elena.vance@example.org | Ref 9912041102185 (checksum fail) | Card 4532-0151-1283-0366.

Ref 9912041102185 fails the Luhn check and stays untouched, while 4532-0151-1283-0366 passes Luhn. Anchored labels corroborate NER on the patient name.

Outbound payload to LLM / destination

Patient: [PERSON_1] | [MEDICAL_RECORD_NUMBER_1] | Email: [EMAIL_ADDRESS_1] | Ref 9912041102185 (checksum fail) | Card [CREDIT_CARD_1].

In gateway mode, placeholders exist only in task memory for one request and are restored into the streamed answer before returning to your app.

Offset-only audit ledger · zero raw values

What PostgreSQL records for this item

Browser SHA-256 keyed demo digestcomputing…
EntityRune offsetsDetectorsAgreementActionWhy
PERSON[9, 20)checksum-regex + ner-encorroboratedreplaceAnchored by "Patient:" label and confirmed by English NER.
MEDICAL_RECORD_NUMBER[23, 33)checksum-regexsingle_sourcereplaceMatched by structured MRN keyword pattern.
EMAIL_ADDRESS[43, 66)checksum-regex + ner-encorroboratedreplaceMatched by email pattern and NER analyzer.
CREDIT_CARD[110, 129)checksum-regexsingle_sourcereplaceLuhn checksum verified; invalid 13-digit Ref 9912041102185 ignored.

Spanish routing, PDFs, and Unicode offsets

Real healthcare and LatAm/US bilingual pipelines rarely stay clean ASCII English. Three failure modes show up immediately when you leave English toy data:

  • Cross-language NER noise: passing Spanish text to an English NER model tags headings like "Historia clínica" as person names and misses Spanish names. Routing Spanish windows to the bundled Spanish model in Redactor v1.0.6–v1.0.7 halved false PERSON findings on the synthetic luna corpora (1,490 down to 766) without losing true names, lifting Spanish/Portuguese precision from 0.82 to 0.90 and recall from 0.916 to 1.000.
  • Fail-closed PDFs and mixed scans: local Go text extraction handles digital PDFs (up to 10 MiB PDF / 1 MiB extracted text) without sending bytes off-host, and refuses encrypted, malformed, or image-only PDFs with explicit error codes (such as 422 pdf_no_extractable_text) unless an opt-in VPC OCR sidecar or AWS Textract is configured. Remember that mixed PDFs with some extractable text bypass fallback OCR, so scanned pages inside mixed files need separate handling.
  • Unicode offset drift: Python NER models often return code-point offsets, JavaScript counts UTF-16 code units, and Go slices UTF-8 bytes. A 4-byte emoji or accented letter shifts every later span if units disagree. In our November 21, 2026 live AWS qualification against a SageMaker ml.m5.large endpoint running Software Sushi's Brazilian PII package on 40 synthetic PT-BR documents (480 labeled spans, including 4-byte emoji prefixes like 🏥 São José:), Unicode rune alignment removed 480/480 spans (100.0%) with zero invariant errors at 627 ms p50 and 902 ms p95.

Offset-only audit evidence and keyed digests

Compliance reviewers ask what the redactor detected, which policy version ran, and where the result went. If you answer that question by storing raw matched strings in an audit table, you just built a second unencrypted PHI store.

Overhead still life on alabaster stone showing a blank linen-bound rag-paper stack separated by an amber optical glass bar from a slim botanical-green strip with brass index pegs and a linked brass chain.
Conceptual still life: raw documents remain separated from an append-only, hash-chained ledger that records only entity types, Unicode offsets, and policy decisions.

An offset-only decision ledger stores entity types, Unicode rune intervals, detector provenance, policy version, and delivery outcomes in append-only PostgreSQL tables protected by a SHA-256 hash chain (verified out of band via redactor verify-ledger). Never store a plain SHA-256 of the raw document either: on low-entropy inputs such as a lone SSN or templated intake form, plain SHA-256 acts as a confirmation oracle. Use HMAC-SHA256 under a deployment-specific secret key instead.

Privacy engineering checklist

Design the boundary, not just the detector

  1. 01VPC ingressFail-closed PDFs & bounds
  2. 02Dual detectionChecksums + routed NER
  3. 03Policy gateCorroboration & secret blocks
  4. 04Offset ledgerHash chain, zero raw PHI
  • Separate strict recall (exact label match) from protected_recall (whether sensitive text was redacted under any label) when evaluating leakage.
  • Match policy rules on detector corroboration (corroborated vs. single_source) rather than relying on one confidence threshold.
  • Route non-English text windows to a matching language model so clinical headings like “Historia clínica” are not flagged as names.
  • Align spans in Unicode code points (runes) and test inputs prefixed with 4-byte emoji and accented characters before enabling remote NER endpoints.
  • Fail closed on encrypted, malformed, or image-only PDFs unless an opt-in VPC OCR sidecar or Textract path is explicitly approved—and handle mixed scanned pages separately.
  • Store only entity types, rune offsets, policy version, and a keyed HMAC-SHA256 content digest in an append-only ledger; never store raw matched values or plain SHA-256 digests.

Where latency went in Fargate load tests

Teams often assume NER inference is the only bottleneck in a redaction service. Our live ECS Fargate load tests across v1.0.8 through v1.0.11 showed that CPU prefiltering, worker scaling, and PostgreSQL write contention all mattered:

Measured Redactor engineering optimizations on synthetic corpora and live ECS Fargate tests
Change (release)Measured effectScope
Keyword prefilter on 29/70 regex patterns (v1.0.9)19–27% lower regex CPU, identical detectionsSynthetic corpora
Batched analyzer calls under contention (v1.0.9)17–38% higher analyzer throughput, identical detectionsBundled Presidio sidecar
One analyzer worker per task vCPU (v1.0.8)83 to 326 docs/sec (1 to 4 vCPU, near-linear)Analyzer alone, short docs
RDS resize db.t4g.micro to db.t4g.small (v1.0.10)+15% fresh / +37% grown throughput; p99 fell 2.4 s to 0.9 sLive Fargate (+~$12/mo us-east-1)
Shared ledger commits for delivery records (v1.0.11)5/9,200 lock timeouts to 16,768/16,768 recorded; 83–89 to 183 items/s (durable admission off)Heavy-load test & local benchmark

Batch pipeline vs. live AI gateway

Choose the runtime pattern that matches how sensitive text moves in your product:

  • Document and S3 pipelines (Redactor): best for clinical notes, PDFs, JSONL exports, and S3 ingestion feeding RAG indexes, analytics, or downstream review queues. Qualify locally on your own private corpus with redactor eval, which emits a strictly content-free JSON report.
  • Live LLM and agent traffic (Redactor AI Gateway): best when applications or agents call OpenAI, Anthropic, Amazon Bedrock Converse, or MCP tool servers directly. Point your SDK base URL at the VPC gateway, block credentials by default, replace PHI with per-request in-memory placeholders like [EMAIL_ADDRESS_1], and restore them in the streamed answer before returning to your app.

Both patterns pair naturally with separating model estimates from recorded clinical decisions and private, ACL-filtered RAG pipelines.

Further reading

These official public references cover de-identification standards and LLM application security. They do not endorse Software Sushi, Redactor, or this article.

Frequently asked questions

Is placeholder redaction the same as HIPAA Safe Harbor anonymization?

No. Replacing identifiers with restorable placeholders in an AI gateway is pseudonymization, not anonymization. Even batch redaction requires corpus qualification, organizational controls, and an actual-knowledge review under 45 CFR 164.514(b)(2).

Why measure both recall and protected_recall?

Strict recall requires the exact entity label (such as PERSON). protected_recall measures whether the span was redacted under any entity type. Separating them lets engineers track leakage independently from labeling accuracy.

What happens if a user uploads a scanned PDF without OCR enabled?

In Redactor, local extraction handles digital text PDFs without external calls. Image-only, encrypted, or malformed PDFs fail closed (422 error or failure queue) unless an admin explicitly enables a VPC OCR sidecar or AWS Textract.

Why use HMAC-SHA256 instead of plain SHA-256 in an audit ledger?

Plain SHA-256 on short or templated clinical inputs can be brute-forced or matched across submissions, acting as a confirmation oracle. Keying the digest with a deployment secret keeps verification possible for key holders without exposing cross-item linkage.

Qualify your redaction boundary on your own corpus

The reliable way to put LLMs beside clinical or sensitive workflows is to move the privacy boundary inside your own AWS account, qualify recall locally without exporting raw documents, and keep audit evidence value-free.

Inspect our self-hosted PII/PHI redaction case study, review healthcare LLM development and our fixed-scope healthcare AI pilot, or book a discovery call with our engineers.