Dev.to AI 🤖 Ai 👁 0 📖 5 min read

How to Send Documents to an LLM While Keeping Personal Data Local: A Hands-On Guide

Most teams already paste contracts, CVs and client letters into ChatGPT or Claude. The usual answer is a scrubber that removes personal data before the request. The problem is that a scrubber which misses one passport nu

Most teams already paste contracts, CVs and client letters into ChatGPT or Claude. The usual answer is a scrubber that removes personal data before the request. The problem is that a scrubber which misses one passport number in a contract has still sent that number to a third party.

This guide shows how to put a reversible scrubbing step in front of any LLM, and how to check how much a scrubber actually misses on documents that look like real work.

The idea: reversible pseudonymisation

Deleting personal data makes the model's answer useless: it cannot write a letter to "[REDACTED]". Reversible pseudonymisation keeps the structure instead.

  1. Each name, ID number, account number, address and phone number the engine detects is replaced with a typed placeholder, such as [PERSON_1] or [NHS_1].
  2. The mapping from placeholders to real values stays on your machine, in an encrypted vault.
  3. The model works on the placeholders and answers with them.
  4. The placeholders in the answer are replaced with the real values locally.

For example (illustrative), this input

Dear Frank Bond, your NHS number 943 476 5919 is on file.

goes to the model roughly as

Dear [PERSON_1], your NHS number [NHS_1] is on file.

The placeholder carries the type, so the model can still reason about the text: it knows [NHS_1] is an NHS number and [PERSON_1] is a person.

Step 1. Install

pii-roundtrip is open source (Apache 2.0) and installs from source with Python 3.12+ and uv:

git clone https://github.com/beskvladimir-create/pii-roundtrip.git && cd pii-roundtrip
uv sync --extra all
uv run pii-roundtrip download-models    # once, needs network

After the one-time model download, the engine runs offline. The all extra adds pii-guard and GLiNER Guard Omni; without extras only the rules run (checksum-validated identifiers, numbers, titled names and the vault).

If you prefer not to use a terminal, there is a desktop app: macOS (Apple silicon, macOS 14 or later), signed and notarised by Apple, and a Windows 10/11 build in beta whose installer is not signed yet. Installers are on the Releases page. On a Mac:

brew tap beskvladimir-create/tap && brew trust beskvladimir-create/tap
brew install --cask pii-roundtrip

Step 2. Clean the document

uv run pii-roundtrip anonymize -l en-GB -i letter.txt -o letter.clean.txt --vault letter.vault

-l en-GB is UK English; use -l ru for Russian. The vault password is read from --password-file, from the PII_ROUNDTRIP_PASSWORD environment variable, or asked interactively. The vault is encrypted with AES-256-GCM, with the key derived from your password by scrypt.

Open letter.clean.txt before you send it. A scrubber you have not looked at is a scrubber you are trusting blindly.

Step 3. Send it to any model

Send letter.clean.txt to ChatGPT, Claude, a local model or anything else. Save the answer as answer.txt.

Step 4. Restore the answer

uv run pii-roundtrip restore -i answer.txt -o answer.restored.txt --vault letter.vault

Restoration tolerates what models do to placeholders: changed case, extra spaces, a lost bracket, or a title written inside the bracket, such as [Mr PERSON_1].

Step 5. Or do it from Python

from pii_roundtrip import anonymize, deanonymize

clean, session = anonymize(text, "en-GB")
answer = call_your_llm(clean)          # the LLM sees only placeholders
print(deanonymize(answer, session))    # originals restored locally

Pass the same session to anonymize for follow-up messages, so that known people and numbers keep their placeholders across the conversation.

What breaks scrubbers, and how to test yours

I benchmarked five open-source tools (pii-guard, GLiNER Guard Omni, Microsoft Presidio, OpenAI privacy-filter and Prompt Anonymizer) plus a regular-expression baseline on 2,000 synthetic work documents, 1,000 in Russian and 1,000 in UK English. The final test set, its SHA-256 hashes and the decision rules were published before the first run, and every tool ran on it once.

Counting only the data types each tool claims to handle, the best results were still about one document in three with personal data left after cleaning: pii-guard on Russian documents at 31.5% [28.7; 34.4] and OpenAI privacy-filter on UK documents at 33.0% [30.2; 36.0] (95% intervals). This supported-types count is descriptive; it was not one of the pre-registered measures. On the same set, pii-roundtrip left an original value in 0.3% [0.1; 0.9] of Russian and 0.2% [0.1; 0.7] of UK documents. It was developed on documents from the same generator, which the other tools were not, so do not read that gap as the gap you would see on your own documents.

Typical misses were numbers in formats people really use but rules rarely expect:

  • a passport number written with dots, such as 97.09.710811;
  • an IBAN or National Insurance number split by dots;
  • a card number spelled out in words;
  • names with initials in the body of a contract.

About 40% of the benchmark documents contain such a number, because the generator puts them there. For pii-guard this explains almost every leak: in Russian documents with only ordinary formats it leaked in 1 of 603. OpenAI privacy-filter, GLiNER Guard Omni and Presidio still leaked in 30.5% to 40.8% of UK documents with only ordinary formats. That is why it is worth testing on your own data.

The quickest check is manual: take ten real documents of the kind your team sends, write numbers the way people actually write them, run your scrubber and search the output for every original value.

To reproduce the final held-out run, follow the run plan for set 7 in HOLDOUT.en.md. It needs Ollama with qwen3.5:9b and gemma4:12b and about 20 GB of disk. scripts/reproduce.sh reruns the earlier sets end to end; its round trip can take about a day. To add your own tool, write a runner in bench/runners/: a class based on Runner from bench/runners/base.py that implements detect(text, lang) and returns character spans with one of the types in TYPES, and register it in bench/eval/run.py. Reversible tools also implement anonymize() and deanonymize().

Limits worth knowing

  • All evaluation data are synthetic. The engine was not tested on real documents.
  • Russian name placeholders were restored correctly in only 94.6% of cases on the final set (version 0.5.0), below the 99% threshold. Version 0.5.2 reaches 99.3% on the same stored answers, for reference only, since the set had already been seen.
  • The round trip was tested with two local models, qwen3.5:9b and gemma4:12b. Large cloud models may treat placeholders differently.
  • I ran the benchmark myself, so the code, data, every tool's predictions and the raw model answers are published for anyone to re-check.

Links

If the engine misses data in a document of yours, please open an issue with a synthetic example of the same kind. Real data is not needed.

Vladimir Beskorovainyi, Enterprise AI Architect & CTO, author of the Amazon bestseller "Enterprise AI: The KATA Way", founder of Besk Tech (besk.tech)

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.