Chatbots and LLMs
Keep personal data out of your chatbot
Redact each user message before it reaches the model. The model sees placeholders, the conversation still reads, and the mapping comes back to you so the reply can show the real values.
How it works
Redact the request.
Pass the whole chat request, the array of
{"role", "content"}messages, in one call. It comes back with placeholders in place of the values, plus the mapping.Send the redacted request to the model.
The model gets
<EMAIL_1>and<PHONE_1>instead of the address and number. It can still follow the conversation and refer to them.Restore the values in the reply, if you need them.
The mapping from each placeholder to its value is returned to you. Swap the values back into the model’s reply before you show it, or leave them out. The library never stores the mapping.
[{"role":"user","content":"my DNI is 4821"},{"role":"user","content":"3067F"}]{"messages":[{"role":"user","content":"my DNI is <ES_DNI_1>"},{"role":"user","content":"<ES_DNI_CONT_1>"}],
"findings":[...],"placeholders":{"<ES_DNI_1>":{"type":"ES_DNI","value":"48213067F"},...},"texts":2,
"complete":true}One value, one placeholder, across the chat
A whole request is redacted with one mapping, so a value gets the same placeholder in every message. A value the user splits across two messages in a row, like the ID above, is still found: the piece in the later message becomes <TYPE_CONT_n>.
Numbering restarts with each call. To keep the same placeholders across the turns of a long conversation, redact the full history in each call, or reuse one shared mapping. To keep them across sessions or services, use a key.
With a private key of your own, each placeholder becomes <TYPE_hex>: by default 12 lowercase hex digits (8 to 16 if you set the length) of an HMAC-SHA256 of the type and value. The same value with the same key gets the same tag in every call, file and machine.
Keyed output is still personal data. Whoever holds the key can re-identify a value by hashing guesses, which is fast for small spaces such as national ID numbers or dates of birth. Keep the key apart from the output, and use one key per purpose. More on the GDPR.
What it scans, and what it leaves
- It scans each message’s string
contentand thetextof each content part. - Tool-call arguments, tool results and other fields pass through unscanned. If your gateway forwards them, redact those strings with the single-text call, or drop them.
- In Fast, the default, names are found by rules where the text labels them: form fields, letter greetings and signatures, and the speakers of a chat or transcript. A name in running prose stays as written. Full’s model also finds people’s names and organisations in running text. How a match is decided.
- It masks IDs and tax numbers, phone numbers, emails, cards and IBANs, addresses, secrets and API keys, dates of birth, and IP addresses and device IDs that belong to a person. Formats by country.
It runs where your chatbot runs
The library runs in your own process, with no API calls, so messages are never sent anywhere to be redacted. Use it in your backend, your gateway, or with WebAssembly in the browser before a message leaves the user’s device.
Packages for Python (3.11 or later), Node.js, WebAssembly, Rust (1.88 or later), Go (1.26 or later) and C all ship every detector and return the same JSON. All but WebAssembly also run Full, with the model; WebAssembly runs Fast only.
There are two modes. Fast, the default, uses rules and checksums and loads no model. Full adds a small local model: it confirms or rejects the numbers, codes and street names the rules left open, and finds people’s names and organisations in running text. On PIIMark, Fast takes a median of 0.10 ms per text on a CPU with no GPU. Full, which adds a local model, takes 5.8 ms.
On all 80,575 test items of PIIMark v1, in 34 languages, Fast mode finds 90.6% of structured personal data (IDs, phone numbers, emails, cards, IBANs, addresses and more) and masks something in 8.6% of harmless items. See every tool on the same items.
Licence
This summary is not the licence. Where they differ, the licence text applies.
Free in production under both thresholds
Production use is free if you and your affiliates have both under USD 5M in revenue over the last 12 months and under USD 5M in external funding.
A commercial licence above either one
Reach USD 5M in revenue or USD 5M in funding and production use needs a commercial licence from us. Talk to us or ask on the dataset cleaning page.
Non-production use is free for everyone
Copying, modifying and testing it are free whatever your size.
Source-available under BUSL-1.1
The code is source-available under the Business Source License 1.1. Each version becomes available under Apache-2.0 four years after its release. Read the full terms.
Need a commercial licence?
If you are above either threshold, or not sure whether you are, tell us about your product.
Talk to us