If you put an LLM gateway in front of your models, sooner or later someone pastes a customer record into a prompt. Masking it is the easy part. The harder question is what you write to your own logs.
A common mistake is to keep the original prompt "for audit". Then your audit log holds the exact personal data you wanted to protect.
This is how we handle it in BaseLLM, the self-hosted AI gateway we build at Base Interactive.
Scan before the request leaves the network
The gateway scans the text before it reaches the model. Detection is rule based and runs on the server, so the text is not sent to another service for checking. Settings are per project.
There are five modes:
- Report only: the request goes through and the detection is logged
- Mask:
TCKN 100*****46,***4567 - Placeholder: the model sees
<TELEFON_1>, the real value is put back in the answer - Redact:
[REDACTED:TC_KIMLIK] - Block:
403 pii_blocked, the request never reaches the model
Secrets (API keys, tokens, connection strings) have their own 29 rules and are blocked by default with 403 secret_blocked.
Check digits matter
Regex alone masks too much. An 11 digit order number looks like a Turkish ID number. So we validate check digits for Turkish ID and tax numbers, IBANs, license plates, and Luhn for cards. In our own test set of 22 realistic samples, 20 were detected with no false positives. Names and addresses can't be found with patterns, so they are out of scope (you can add your own patterns).
What goes to the log
- The raw value is never stored
- Only the masked sample, counters and where it was found
- Every detection is an audit event (
pii.detection), and audit records are linked with a SHA-256 chain so a changed record is visible - Detection events are kept 90 days by default, configurable from 0 to 3650 days
So the log proves the masking happened, without becoming a second copy of the data.
Masking is one technical measure, not full compliance by itself. But it is the part security teams ask about first.
Details: https://llm.baseinteractive.com.tr/en/docs/data-masking
Top comments (1)
Logging the redaction instead of the original prompt is the right call, and the check-digit validation is what keeps false positives manageable. One edge to test is placeholder mode: if the model echoes a placeholder like in a different form or splits it across tokens in streaming, the restore step can miss it, so I'd run the un-masking on the fully assembled response and also unit-test streamed chunks. It could also help to store a keyed hash of each detected value, so repeated leaks of the same record can be correlated without keeping the raw data.