← Back to the blog

AI & Local LLM • 2026-10-08 • 3 min read

Masking Personal Data Before It Reaches a Model

Redacting a prompt makes the answer useless. The proxy we run swaps personal data for stable placeholders, then puts it back in the response — and the detection runs in microseconds.

Masking Personal Data Before It Reaches a Model — AI & Local LLM

If you strip every name and number out of a support ticket before summarising it, you get a summary about "the customer" that cannot be acted on. Masking has to be reversible to be useful.

Placeholders, not redaction

Each detected entity is replaced with a typed, stable token: [PERSON_1], [EMAIL_2], [IBAN_1]. The mapping lives in memory for the duration of the request only. The model sees structure and can reason about it — "[PERSON_1] asked about the invoice sent to [EMAIL_2]" — and the response is un-masked on the way back.

Stability within a request matters. The same email must become the same placeholder every time it occurs, or the model will treat two mentions as two people.

What we detect, and how

Two layers.

Structured patterns — email addresses, phone numbers, IBANs, card numbers, national identifiers, IP addresses — are regular expressions with validation attached. A card number is only a card number if it passes a Luhn check; an IBAN only if the checksum holds. Validation is what keeps the false-positive rate low enough that people do not start disabling the proxy.

Known values — the customer names, account numbers and internal identifiers that exist in your own database — are matched with aho-corasick, which builds one automaton over all the terms and scans the text in a single pass. Tens of thousands of terms cost microseconds, and the cost does not grow with the number of terms the way a loop of contains does.

// rust
static DETECTORS: &[(&str, Detector)] = &[
    ("EMAIL", Detector::Regex(&EMAIL_RE)),
    ("IBAN", Detector::Checked(&IBAN_RE, validators::iban)),
    ("CARD", Detector::Checked(&CARD_RE, validators::luhn)),
];

let masked = masker.mask(&prompt);
let answer = upstream.complete(&masked.text).await?;
let restored = masked.restore(&answer);

Order of operations

Mask the longest matches first. Masking [email protected] after already replacing john with [PERSON_1] produces [PERSON_1]@acme.com, which is both wrong and no longer an email address to the next detector.

What it cannot do

This is the part worth being plain about. Pattern matching finds entities with a shape. It does not find "the manager who was in the Tuesday meeting", and it will never detect an identifier format nobody told it about. The proxy reduces exposure substantially; it does not make an arbitrary document safe to send somewhere untrusted.

Which is why it sits in front of a *local* model, as one layer among several, rather than being the thing that makes a public API acceptable. With inference running on your own hardware, masking is defence in depth. In front of a third-party API it would be the only thing standing between a support ticket and someone else's log file — and that is not a position any regex should be in.

Logging

The proxy logs that a request occurred, from which tenant, how many entities of each type were masked, and the token count. It never logs the prompt, masked or otherwise. A log line outlives the request, and a masked prompt in a log is still a document you now have to protect.

Read next

COOKIES // MEASUREMENT

We count page views through Google Tag Manager. Say yes and it may store a cookie in your browser; say no and it still counts the visit, without storing anything and without an identifier. Nothing here is used for advertising.

Cookie Policy — you can change this at any time from the footer of any page.