The structured values are easy and a pattern will find them. The names are the hard part, and the names are usually the reason you are doing this.
Start with what regex is good at
A lot of what you need to remove has a shape, and matching a shape is cheap, deterministic and easy to test:
- •Email addresses
- •Phone numbers, in the formats you actually receive
- •Card numbers — with a Luhn check, or half your matches are order references
- •IBANs and account numbers
- •Postcodes and ZIP codes
- •National insurance and social security numbers
- •API keys and internal hostnames, which people paste more often than they admit
This is worth doing first because it is most of the volume and none of the difficulty.
Then the part that does not have a shape
A name is a word. Marta Kowalczyk and Northgate Supplies are the same shape, and so is half the English language. There is no pattern that finds one without knowing something about the words around it.
Two approaches work, and they fail differently:
- •Cues. A label in front of the value — Customer:, Patient name:, Dear, Sincerely. Reliable on records, forms, invoices and letters. Useless in a sentence, which is the honest limit and worth knowing before you build on it.
- •A model. A small named-entity model finds names in prose. It costs latency, it is probabilistic, and you have to decide what happens when it cannot answer — which is a real decision, not an edge case.
If you run a model for this, run it somewhere that does not defeat the purpose. Sending text to a third-party API to work out what to hide from a third-party API is a circle.
Substitute, do not mask
This is the decision that determines whether the output is usable.
Replace Marta Kowalczyk with [NAME] or a row of asterisks and the model writes about a placeholder. Pronouns stop agreeing, sentences bend around the gap, and you spend the saved time repairing the reply.
A model given a name writes a sentence. A model given [NAME] writes about [NAME].
Replace it with a different plausible name and the model writes an ordinary paragraph about somebody who does not exist. Then you reverse the mapping on the response and the reader sees the real name.
Rules the mapping has to follow
- •Stable within a conversation. The same person must get the same stand-in every turn, or the model sees two strangers where there was one.
- •Same shape as the original. A two-word name becomes two words. A UK number stays a UK number. Change the shape and you change what the model infers.
- •Never longer than what it replaced. A substitution that adds a town where the original had none collides with the words still standing either side of it.
- •Yours to hold. The mapping is the table that turns redacted text back into real people. If a third party holds it, you have moved the problem rather than solved it.
What breaks at scale
- •Streaming. Restoration has to happen inside the stream, before it reaches the caller, or the first tokens arrive with stand-ins still in them.
- •Logs and traces. Your observability captures the prompt. Make sure it captures the redacted one.
- •Caching. A response cache keyed on the original text holds the original text.
- •Retries. A retry with a freshly generated mapping is a different conversation from the model’s point of view.
Or do not build it
All of the above is a few days to get working and a long tail to keep working. If that is not the product you are trying to build, we sell exactly this as an API: one call takes the people out and returns a mapping, another puts them back, and a proxy endpoint does all three steps around your own model key so your code changes by one line.
The developer documentation is here. There is also an MCP server, so an assistant can do it without anybody writing the calls at all.
Common questions
Is this the same as anonymisation?
No, and it is worth being precise. This makes text non-identifying for the purpose of sending it to a model. Formal anonymisation is a higher bar and concerns the data you keep, not the copy you transmit.
What about data already in the model’s context?
Redact on the way in, every turn, including the history you replay. A conversation that was clean on turn one and replayed raw on turn six has sent everything anyway.
Does it work for code?
Partly. Keys, hostnames, IPs and connection strings have shapes and are found reliably. Names inside identifiers and comments are the same problem as names in prose, with fewer cues to go on.