Skip to contentRedact PII for your data. Get a quote

Blog

Keeping personal data out of your chatbot

Redact every message before the model sees it, keep placeholders consistent and put real values back in the reply.

By Saul Martin · · 4 min read

People paste things into chatbots. An ID number to check a booking, an IBAN for a refund, an email to update an account. If the chatbot calls a hosted model, every one of those values leaves your system and lands in someone else’s logs.

The model rarely needs the value itself. It needs to know that there is an ID, and which one the user means. This post shows how to give it exactly that, and how to get the real values back for the user.

Redact each message before the model sees it

Put redaction between your app and the model. OpenAnonymizer takes the whole chat request, a list of {"role", "content"} messages, and returns the same request with every value it finds replaced by a placeholder, plus a table of what each placeholder stands for.

Python: redact a chat request
from openanonymizer import Redactor

r = Redactor()  # build once, share across requests

messages, info = r.redact_messages([
    {"role": "user", "content": "my DNI is 4821"},
    {"role": "user", "content": "3067F"},
])
# messages: "my DNI is <ES_DNI_1>", "<ES_DNI_CONT_1>"
# info["placeholders"]: what each placeholder stands for

Send messages to the model and keep info in your process. The model never sees the values, and the table never leaves your side.

Values split across messages

Users do not always type a value in one go. They send half an ID, hit enter, then send the rest. Redacting each message on its own would see two harmless fragments and pass both through.

Because the whole request goes in as one call, the engine also looks across two consecutive user messages. In the example above, 4821 and 3067F together form a valid Spanish DNI. The first piece becomes <ES_DNI_1>, and the piece in the later message becomes <ES_DNI_CONT_1>, so the model can tell they belong together.

The same value keeps its placeholder

Within one call, the whole request shares one placeholder mapping. If the user gives the same email in the first message and again in the fifth, it is <EMAIL_1> both times. A different email is <EMAIL_2>.

This is what keeps the conversation usable. The model can say “I have updated <EMAIL_1>” and mean the right address, and it can tell two customers apart without knowing who either of them is.

Numbered placeholders restart in every call. The simplest pattern is to redact the full conversation on every turn, so the numbering stays stable. If placeholders must also match across separate calls or services, give the redactor a private key: Redactor(placeholder_key=...) gives each value the same tag wherever that key is used.

Restore values in the reply

The model answers with placeholders in its text. Before you show the reply to the user, swap each placeholder for its value from the table you kept.

Python: put the values back into the reply
reply = call_your_model(messages)  # your model client

for placeholder, entry in info["placeholders"].items():
    reply = reply.replace(placeholder, entry["value"])

The user sees their own data, and the model provider saw none of it. The same table is your audit trail of what was masked in each request.

One caution from the engine’s security notes: a chat call scans message content, the content string or the text of each content part. Tool-call arguments, tool results and other fields are copied through unscanned. If your agent forwards those to the model, redact each string yourself or drop it.

Runs on your CPU, with no API calls

Redaction runs inside your own process: no network, no GPU, no external service. In Fast, the default mode for chatbots, the median text takes 0.10 ms on one server CPU, so it adds almost nothing to a model call.

Fast uses rules and checksums only. On PIIMark v1 it finds 90.6% of structured personal data and masks something in 8.6% of harmless texts, which matters in chat, where a masked order number breaks the answer. Names are found where the text labels them, such as chat speakers and signatures; in Fast, names in running prose stay as written.

The same engine ships for Python (3.11 or later), Node.js, WebAssembly, Rust (1.88 or later), Go (1.26 or later) and C, with every detector and the same JSON in each. All but WebAssembly also run Full, which adds a small local model to judge candidates the rules left open and to find people’s names and organisations in running text; WebAssembly runs Fast. (Update 4 Dec 2026: the modes are now called Fast, formerly Precise, and Full, formerly Strict.)

Licence

OpenAnonymizer is source-available under the Business Source License 1.1. Production use is free if your organisation, with its affiliates, has both under USD 5M in revenue and under USD 5M in funding. Above either threshold, you need a commercial licence from us. Non-production use is free for everyone, and each version becomes Apache-2.0 four years after its release.

More patterns for assistants and agents are on the chatbots and LLMs page, and the full terms are on the licence page.