In this article
Use regex for fixed formats in one language, an open-source detector when you have engineers to own the pipeline and read languages its models cover, and a model built for the job when the text is free and spans many languages. Many teams combine them.
You want to hide private data before a prompt reaches a language model. Three routes exist, and each one is the right answer for some apps. This is how to tell which one is yours.
The three routes in one paragraph each
Regex. You write patterns for the formats you know: a card number, an email, a tax number with a check digit. Python's re module is enough to start.
An open-source detector. A library such as Presidio bundles patterns, checks and a language model for names. You install it, pick its recognisers and run it on your servers.
A model built for the job. A trained model reads the sentence and marks private and sensitive data in context. You call it as a service or run it on your own servers. Opami Protect is one of these.
What each one catches
| Regex | Open-source detector | Model | |
|---|---|---|---|
| Fixed formats (card, email, tax number) | Yes, with a pattern per format and country | Yes, with built-in recognisers | Yes |
| Names | No: a name has no format | Yes, through its language model | Yes |
| Addresses and free text (a diagnosis, a lawyer's name in a sentence) | No | In part, depending on the recognisers you add | Yes |
| Many languages | One pattern set per country | One model and recogniser set per language | One model for all its languages |
Regex is exact on a format and blind to the rest. "ana.silva@lusomar.example" matches, "Ana Silva called from the Lisbon office about her mother's heart surgery" matches nothing. That sentence holds a name, a place and a health detail.
Upkeep
A regex needs a person when a format changes, a country is added or a false hit shows up. A detector needs the same, plus updates of the library and the language models it loads. Both fail without a sound: a detector that no one updates misses a new format and raises no error.
A model run as a service moves that work to the vendor. If you run it on your own servers, you update the version and the rest is the vendor's.
Speed
A handful of patterns run in microseconds. A detector with a language model adds model time to each request and depends on your hardware. A model service adds a network call, and Opami Protect takes about 14 ms per 1,000 characters. For a chat reply that streams to a user, 14 ms is small next to the model call that follows it. For a batch job over millions of texts, run the three routes on a sample and time them on your hardware.
Cost
Regex costs engineer time. An open-source detector has no licence fee for the software and costs servers and engineer time, which you see once you list the hours: setup, recognisers per language, tests and the loop that swaps details back after the answer. A model service charges by volume. Opami Protect charges €2.00 per million characters at the first step and €0.20 at the highest.
Count the hours once, then compare them with the invoice.
Where the text goes
Regex and a detector on your own servers keep the text inside your network. A model service sends it to the vendor's servers, so ask where they are, who handles the text and what they keep. Opami Protect processes in the EU (Sweden, with a fallback in Germany) or on your own servers, and keeps neither your text nor what it found.
When each one is enough
Regex is enough when your data has fixed formats in one language: order numbers, internal IDs, invoice numbers, a card number in a payment form. If no free-text field holds a name, a pattern is fast, cheap and easy to audit.
An open-source detector fits when you read English or a few languages that its models cover, you have engineers who like owning the pipeline, and you want full control over each rule. It also fits when the text must not leave your network and you prefer to run the whole stack yourself.
A model earns its place when the text is free: tickets, chats, contracts and emails that mention people, places and health details in many languages. It pays off when you would otherwise write and test recognisers for each language, or when you do not want a filter to maintain.
Many teams combine them. A regex catches internal IDs that no model knows, and a model handles the names and sentences.
Test before you choose
Whichever route you pick, each one misses some private data, and hidden data is still personal data under EU law. Run each candidate on 200 of your own texts and count what it misses. The alternatives pages set the options side by side, and the AI apps use case shows the hide-and-restore flow around a model call.


