blog · · 6 min read
Keeping customer data from the model without blinding the agent
An agent that does real work needs real data. To send a payment reminder it has to know who the customer is and where to write, so names, email addresses and IBANs end up in the prompt. Sending them to a model provider is a GDPR problem.
Privacy Guard is the service I built to sit between an agent harness and the model provider. It replaces personal data with tokens before the model sees anything, keeps the mapping in an encrypted vault per conversation, and puts the real values back at the tool boundary. It runs in production behind ecoai at Visma e-conomic and is open source. This post goes through how it works, one mechanism at a time.
01 / 09
Redaction stops the leak, and the work with it
The obvious fix is redaction: replace every name and email with a fixed marker before the model call. The model never sees the data, and it can no longer act on it either. When a tool result says who to remind and the model asks to send the reminder, the address it writes is the marker, and there is nothing to send.
What the agent needs is a placeholder the model can carry through its reasoning and copy into a tool call, and that the harness can turn back into the real value afterwards. That is pseudonymization with a way back.
one tool result through redaction and through reversible tokens · values illustrative, token format from the service 02 / 09
A service between the harness and the model
Privacy Guard is a Cloudflare Worker with two endpoints that matter.
/v1/anonymizetakes text, detects personal data and returns the text with tokens in its place./v1/deanonymizetakes text with tokens and returns the real values. The rest of the pattern lives in the agent harness: anonymize before every model call, and deanonymize tool arguments before every tool runs.Detection runs in Python containers behind the Worker. The mappings live in one Durable Object per vault, encrypted. As shipped, vaults are created under Cloudflare’s EU jurisdiction and the detector containers are pinned to a European region.
anonymize before the model call, deanonymize before the tool runs · layout illustrative 03 / 09
The caller decides what gets scanned
Only text between
__PG_ANON_START__and__PG_ANON_END__is processed. Everything outside the markers passes through unchanged, and the markers are removed from the output. A request can be a single text field or a whole chat message array, tool-call arguments included, so the harness can send the conversation as it is and mark only the parts that carry customer data.That keeps the system prompt, the tool schemas and the model’s own words away from the detector. They hold no personal data, and a detector that never sees an instruction can’t mistake one for a name.
one message array with two marked segments · markers from the service, content illustrative 04 / 09
Rules for structure, a model for names
Detection has two parts. Presidio pattern recognizers find structured values: email and IP addresses, IBANs, phone numbers, government IDs, and card numbers that pass a Luhn check. GLiNER, a small multilingual entity model, finds what a regex can’t: person names, addresses and usernames. It reads the text in 1,200-character chunks with 200 characters of overlap, and its spans count from a score of 0.62.
The two sets of spans overlap, so they are merged by rank. Rule spans have priority 100 and GLiNER spans 40; after that, higher confidence and then longer spans win, and a span that overlaps one already accepted is dropped. If GLiNER marks the name part of an email address as a person, the rule’s email span still wins and the whole address becomes one token.
one sentence, rule spans and GLiNER spans merged by rank · priorities and threshold from the detector, scores illustrative 05 / 09
One value, one token, stored encrypted
A detected value becomes a token of the form
__PG_{vaultTag}_{ENTITY}_{n}__. The tag is the first eight hex characters of the vault ID, andncounts per entity type, so the first email in a conversation isEMAIL_ADDRESS_1and the second isEMAIL_ADDRESS_2. The model can tell what kind of value it is looking at without seeing the value.Before a token is minted, the vault looks up the value’s fingerprint, a SHA-256 of a secret and the value. A known value gets its existing token. A new one is encrypted with AES-GCM under a fresh 12-byte IV and stored with its token, entity and fingerprint. The vault never holds plaintext.
minting a token, then meeting the same value again · record fields from the vault code 06 / 09
The same person keeps the same token
A conversation spans many model calls, and the model has to see the same token for the same person in every one of them. Before detection runs on new text, the vault replays every mapping it holds into that text as a plain string replacement, longest value first. Detection then only has to find what is new.
That turns consistency into string matching instead of detector recall. The detector has to catch a value once per vault, and every later mention is replaced even where the model would have missed it. Names that GLiNER found are replayed only at word boundaries, so a stored “Anna” doesn’t turn “Hosanna” into a token.
two turns against the same vault · values and tokens illustrative 07 / 09
Restore before the tool runs, and stop if you can’t
The model writes tool calls with tokens in their arguments. The harness sends the arguments to
/v1/deanonymizebefore executing, and the vault replaces every token it knows with its value. A token it doesn’t know stays as it is and is reported asUnresolved token preserved. That happens when the vault has expired, when the token came from another vault, or when the model damaged it while copying.In production the model damaged a placeholder in 0.61 percent of responses over a three-month sample. That is rare, but it tends to hit exactly the calls that do something, so a harness should treat the warning as fatal for any action with side effects. A cheap first response is to ask the model to regenerate and copy placeholders exactly, and to abort only if that fails too.
two tool calls, one with a damaged token · warning text from the service 08 / 09
A cold container doesn’t fail the conversation
The detectors run in four container shards. A request goes to the shard picked by an FNV-1a hash of its text, salted with the vault ID. Containers sleep after 20 idle minutes and need a while to load their models when they wake.
If a shard reports that it is starting, or doesn’t answer, the request moves to the next shard on the ring after a back-off of 250 ms, then 500 ms, 1 s and 2 s, for up to two passes around the ring. A restarting container costs some latency instead of a failed request.
four detector shards, one of them restarting · timing compressed 09 / 09
Vaults expire, and expired means gone
A vault lives as long as its conversation is in use. Every anonymize or deanonymize call extends a sliding 24-hour window, but never past seven days from creation. A Durable Object alarm deletes the vault’s state when the window closes. A caller that is done can delete it right away, or pass
deleteAfteron the last restore.There is no grace period. A request for an expired vault gets a 404, and any token from it stays unresolved, which the tool boundary already treats as a reason to stop. A vault can also only be read by the caller that created it.
two vaults’ lifetimes · window and cap from the vault code, access times illustrative