Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
Personal data
stays home.
The moment you send a prompt to a hosted model, whatever's in it — including a customer's email, a patient's record, a support ticket full of names — leaves your systems. For regulated data that can be a violation; for everything else it's exposure you didn't have to take on. The fix is a pattern with a satisfying invariant: replace the personal data with placeholders before the model ever sees it, let it reason about the shape of the request, then swap the real values back into the answer. The provider only ever sees [PII_0]. Here's how to make that airtight.
The boundary problem
Every hosted-model call crosses a trust boundary: your prompt travels to a third party's servers, where it may be logged, cached, or — depending on the terms — retained. Anything personal in that prompt goes with it. For data governed by regulation (health records under HIPAA, personal data under GDPR, and their kin) that transfer can be unlawful without the right agreements; even where it's permitted, it enlarges the set of places your users' data lives and the number of ways it can leak.
The principle is straightforward: personal data you don't send can't be exposed. So the goal is to let the model do its job without ever seeing the actual PII. You can't just strip the data and hope the request still makes sense — a support summarizer needs to know that there's a customer and an email, even if it doesn't need the real address. The trick is to preserve the structure while hiding the values, and that's exactly what redact-before-send does.
Replace every piece of PII with a stable placeholder before the prompt reaches the model, restore the real values in the response — so the provider only ever sees placeholders, never personal data.
Redact before send
The redact-before-send pattern is a round trip. On the way out, you detect PII in the prompt and mask each value — swap it for a placeholder token like [PII_0] — keeping a private mapping from placeholder back to the real value. You send the masked prompt; the provider sees only placeholders. On the way back, you restore: replace the placeholders in the model's response with the real values from your mapping, inside your own trust boundary.
The model reasons about a request that's structurally intact — "email [PII_0] asked about their order" — and produces an answer that references the placeholders, which you rehydrate into "email jane@acme.com asked about their order." The whole exchange with the provider is placeholder-only. The invariant you're enforcing is that the outbound text contains no original PII — that's the property to test, and the math makes it exact.
Consistent placeholders
A subtlety makes the pattern actually usable: the same value must map to the same placeholder. If a prompt mentions one email twice, both occurrences become [PII_0], so the model understands they're the same entity and its reasoning stays coherent — and you can restore them together. Map them inconsistently and the model would think one person is two, garbling the answer.
Equally, distinct values get distinct placeholders ([PII_0], [PII_1], …), preserving the relationships in the text — who emailed whom, which id belongs to which record. So the mapping is a bijection between the real values and the placeholders: consistent within a value, unique across values. That's what lets a masked prompt carry all the structure the model needs while carrying none of the content that's sensitive. Get the mapping right and the model can't tell it's working on redacted data — except that it never learns anything it shouldn't.
The invariant
Masking maps each token through a substitution: PII values become placeholders, everything else passes through. The mapping m is a bijection from the PII values to fresh placeholders. The property that matters is the leakage invariant: the masked, outbound text contains none of the original PII:
Every detected PII value is replaced, so nothing on the deny-list survives into the text you send. That empty set is the guarantee.
And because the mapping is a bijection, masking is reversible — restore composes with mask to recover the original exactly:
So you lose nothing: the provider sees placeholders, you keep the ability to reconstruct the real answer. The runnable version below masks PII, checks the leak invariant is empty, and round-trips the restore.
Mask, send, restore
Redact-before-send is a reversible substitution. Masking replaces each PII value with a stable placeholder and records the mapping, so the outbound text contains zero original PII — that's the leak invariant, an empty set. The same value always gets the same placeholder (so the model treats it as one entity), and distinct values get distinct placeholders (preserving relationships). Because the mapping is a bijection, restore round-trips the masked text back to the original exactly. Change the tokens or the PII set and confirm nothing leaks.
Defense in depth
Redaction is powerful but not sufficient alone — because detection is imperfect. Combine it with other controls:
| Control | What it adds |
|---|---|
| Redact before send | Mask PII to placeholders so real values never reach the provider — the primary control. |
| Data minimization | Send only the fields the task needs; the best-protected data is the data you never transmit. |
| Contract (BAA / DPA) | A business-associate or data-processing agreement, with training-on-your-data disabled. |
| Local / private model | For the most sensitive data, a local model means nothing leaves at all. |
| Output guardrails | Scan responses for leaked PII too (a guardrail) — model or tools can surface it. |
| Human review | Route high-risk flows past a person before anything sensitive is sent or shown. |
Structured PII — emails, phone numbers, card numbers, IDs — is easy to detect with patterns and reliable to redact. The hard cases are names, addresses, and context-dependent identifiers, where even good detectors miss some. So layer the controls: redaction as the main line, minimization to shrink the surface, contracts and (for the most sensitive data) local models to bound the worst case, and output scanning to catch anything that slips through. This is the same defense-in-depth logic as everywhere in security — no single control is perfect, so you stack independent ones.
Pitfalls
The core limitation to internalize: a missed entity is a leak. Redaction is only as good as detection, and no detector catches every name or oddly-formatted identifier — so treat it as strong risk reduction, not an absolute guarantee, and back it with minimization and contracts. A related trap is redacting too aggressively and destroying the task: strip so much that the model can't understand the request, and you've traded a privacy win for a broken feature. Preserve structure with consistent placeholders rather than blanking everything.
Two more. Leaking through the response or logs: your own logs, traces, and prompt-caches can store the un-redacted prompt if you're not careful — apply the same discipline to observability data, and restore PII only at the last moment, inside the boundary. And PII in unexpected places: it hides in free-text fields, file uploads, image content, and tool results, not just the obvious form fields — scan everything that becomes part of a prompt. Done well, redact-before-send lets you use hosted models on real-world data without handing that data away — the personal parts simply never leave.
Redaction is only as strong as detection — a missed name or odd identifier is a real leak, so redaction is risk reduction, not a guarantee. Layer it with data minimization, a BAA/DPA (training disabled), local models for the most sensitive data, and output scanning — and keep your own logs and caches redacted too.
Worked example: one support ticket through the round trip
An invented ticket: “Hi, this is Jane Doe, jane@acme.com, phone 555-0142. Order 88213 never arrived. My husband mark already emailed about it.” The detector runs regex for emails and phone numbers and a name model for people. Follow it through.
| Step | What happens | Text or state at this point | Crosses the boundary? |
|---|---|---|---|
| 1 | Detect | email, phone and “Jane Doe” found; lowercase “mark” missed | No |
| 2 | Mask | “this is [PII_0], [PII_1], phone [PII_2] … My husband mark …” | No |
| 3 | Store the map | {[PII_0]: Jane Doe, [PII_1]: jane@acme.com, [PII_2]: 555-0142} | No: this map is the PII |
| 4 | Send | masked prompt: 3 placeholders, plus one real first name | Yes: “mark” leaks |
| 5 | Model replies | “Hi [PII_0], we’ll email [PII_1] once order 88213 is traced.” | Back inside |
| 6 | Restore | “Hi Jane Doe, we’ll email jane@acme.com once order 88213 is traced.” | No |
| 7 | Log | store the masked prompt and reply, never the restored text | No |
Three of four entities were caught, and the fourth went out anyway. That is the page’s “a missed entity is a leak” in one line: the invariant holds only for what the detector saw. Step 3 matters as much as step 2: the mapping is now the most sensitive object in the pipeline, so it lives in memory or an encrypted store for the length of the request or session, and never in logs. The order number was left alone on purpose. On its own it identifies no one, and the model needs it to answer.
Cost and trade-offs: detectors and placeholders
Read Time as the work added per request, and Space as what the approach catches or keeps. No detector catches everything; they differ in what they miss.
| Case | Time | Space | Why |
|---|---|---|---|
| Regex patterns | One linear scan; negligible | Emails, phone numbers, ids with a fixed format | Precise for structured PII, blind to names and addresses. |
| Regex + checksum | The same scan plus a check digit | Card numbers that pass the Luhn check | Cuts false positives: a 16-digit order number usually fails the checksum. |
| Named-entity model | One model pass per request | Names, places, organisations in free text | Misses lowercase, nicknames and unusual names, as in step 1. |
| A local LLM as detector | A full generation per request | Context-dependent identifiers (“my neighbour, the vet on Elm St”) | Best recall on hard cases, highest cost, and not deterministic. |
Opaque placeholders [PII_0] | None | Reveals nothing about the value | The model may not know [PII_1] is an email it can write to. |
Typed placeholders [EMAIL_0] | None | Reveals the entity type only | Usually better answers; a small, deliberate leak of structure. |
| Realistic fake values | A generator plus the same map | Reveals nothing, reads naturally | Smoothest output, but a fake that collides with a real word in the reply breaks restore. |
Most pipelines stack the first three: regex and checksums for structured data, a name model on top, and typed placeholders so the model knows what it is handling. The local-LLM detector earns its cost on free-text-heavy flows such as medical notes.
Where this shows up in production and interviews
- Off-the-shelf detectors
Microsoft Presidio is an open-source detect-and-anonymise library that combines patterns, checksums and NER. Google Cloud Sensitive Data Protection and Amazon Comprehend offer PII detection as managed services. All of them are the detect step; mapping and restore are still yours.
- Healthcare de-identification
HIPAA’s Safe Harbor method lists 18 identifier types to remove, from names and dates to device serial numbers. It is a useful checklist for what a detector must cover, well beyond emails and phone numbers.
- RAG and agent pipelines
PII reaches the prompt through retrieved documents and tool results, not just the user’s message. Redact at ingestion before chunks are embedded and stored, and again on every tool result that enters the context.
- The interview version
In “design an LLM support-ticket summariser”, draw the trust boundary first. Then place detect, mask and restore on your side of it, say where the mapping lives and for how long, and say how you measure detector recall on a labelled sample.
Check yourself
A ticket says “Jane Doe” once and “Jane” twice. Your mapper gives them different placeholders. What breaks?
The model sees two people where there is one, so a reply can address “[PII_0]” and refer to “[PII_1]” as someone else. Consistency has to be per entity, not per exact string: link name variants to one placeholder, or the bijection the page relies on is over the wrong things.
Detector recall is 95%. Over 1,000 tickets with 4 entities each, how many entities leak, and how many tickets?
1,000 × 4 × 0.05 = 200 entities. A ticket is clean only if all 4 are caught, 0.95⁴ ≈ 0.81, so about 185 tickets leak at least one (assuming misses are independent). 95% sounds high per entity and is not per ticket.
The model replies with “[PII_3]”, but your map only has [PII_0] to [PII_2]. What should restore do?
Leave it unrestored and flag the response. The model invented a placeholder, so there is no real value behind it; guessing one would put the wrong person’s data in the answer. Check too that every placeholder survived intact: a reply that writes “PII_0” without brackets silently skips restore.
In a multi-turn chat, should the placeholder map be rebuilt for every message?
No. Keep one map per conversation. Rebuilt each turn, Jane can be [PII_0] in turn one and [PII_2] in turn three, and the model loses track of who is who. The map then lives as long as the session, so expire it with the conversation and never write it to logs.
Quick answers
What's the risk of PII in prompts?
Sending a prompt to a hosted model transfers any personal data in it to a third party, which can be a compliance violation and always widens exposure.
What is redact-before-send?
Detect PII, replace it with placeholders before the model sees it, and restore the real values in the response — the provider sees only placeholders.
Why consistent placeholders?
Mapping the same value to the same placeholder lets the model treat it as one entity, keeping its reasoning coherent and the restore correct.
Is detection enough alone?
No — detectors miss some names and identifiers, so pair redaction with minimization, contracts, local models, and output scanning.
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The Agentic AI Interview HandbookTwenty topics every senior AI engineer should be able to reason about live — from eval pipelines to reliability patterns for generative systems.Read →
- The Agent Evaluations HandbookA self-contained handbook on evaluating AI agents — theory, interactive widgets, and practical guidance. Trajectory evals, tool-use scoring, LLM-as-judge, observability, and reliability for PMs, engineers, and founders.Read →
- The Agent Patterns HandbookThe design patterns behind every LLM agent — the ReAct Thought–Action–Observation loop, tool/function calling, plan-and-execute, reflection, memory, multi-agent orchestration, and the failure modes (loops, hallucinated tools, recovery, human-in-the-loop) that break agents in production.Read →
- The Model Context Protocol (MCP) HandbookThe open standard connecting AI agents to the outside world — why M×N bespoke integrations collapse to M+N, the host/client/server roles over JSON-RPC, the three primitives (tools, resources, prompts), the connect→discover→call session lifecycle, when MCP earns its keep, and the security sharp edges (a server's output is untrusted input).Read →
- The Loop Engineering HandbookStop prompting your agents — design the system that prompts them for you. The inner vs outer loop, the four loop types (heartbeat, cron, hook, goal), the six building blocks (automations, worktrees, skills, MCP connectors, subagents, external memory), stopping conditions and the verification split, state across runs, cost engineering, and the six failure modes that burn tokens at 3am.Read →
- The Context Engineering HandbookThe discipline that replaced prompt-tweaking: curating everything the model sees under a finite attention budget. The anatomy of a production context window, the three taxes on an overstuffed one (context rot, cost, behavioral drift), the four operations (write, select, compress, isolate), agent-specific patterns like compaction and just-in-time retrieval, six production habits, and where it sits in the prompt → context → loop → harness stack.Read →