Masking PII is the easy part. The hard part is what you log
· Ramazan Gülsen
If you put an LLM gateway in front of your models, sooner or later someone pastes a customer record into a prompt. Masking that record is the easy part. The harder question is what you write to your own logs about it. This post explains how we handle both in BaseLLM.
The common mistake
Security teams want proof that masking really happened. The first idea is usually to keep the original prompt somewhere "for audit".
But then the audit log holds the exact personal data you wanted to protect. The national ID number you kept away from the model now sits in your log table, in your backups and in every system you forward logs to. You add a protection layer and end up with one more copy of the data.
Scan before the request leaves the network
BaseLLM scans the text inside the gateway, before it reaches the model. Detection is rule based and runs on your own server. The text is not sent to another service for checking. Applications need no change, because they already call the gateway's OpenAI-compatible endpoint.
Rules are set per project. A legal project can block a request with personal data while a call center project masks the same data. There are five modes:
| Mode | What happens |
|---|---|
| Report only | The request goes through, the detection is logged |
| Mask | TCKN 100*****46, phone ***4567 |
| Placeholder | The model sees <TELEFON_1>, the real value is put back in the answer |
| Redact | TCKN [REDACTED:TC_KIMLIK] |
| Block | 403 pii_blocked; the request never reaches the model |
Placeholder mode is the most useful one for many teams. The user sees the full text and the model does not. The model answers "call the customer at <TELEFON_1>", and the real number is put back in the answer the user gets.
Secrets such as API keys, access tokens, passwords and database connection strings go through a separate scan. It has 29 rules and blocks by default with 403 secret_blocked.
Why check digits matter
Masking with regular expressions alone masks too much. To a regex, an 11-digit order number looks just like a Turkish national ID number (TCKN). The model loses useful context, and users start asking to turn masking off.
The last two digits of a TCKN are computed from the first nine. Take 10000000146: the digits in odd positions add up to 2 and the digits in even positions add up to 0. (2 × 7 − 0) mod 10 = 4, so the tenth digit must be 4. The first ten digits add up to 6, so the eleventh digit must be 6. A random order number rarely passes both checks.
So BaseLLM validates check digits for TCKN, Turkish tax ID, IBAN and Turkish license plates, and uses the Luhn algorithm for card numbers. It also catches numbers written with spaces and dashes, such as +90 (532) 123-45-67 or TCKN 100 000 001 46.
What we write to the log
The raw value is never stored in any record. When something is detected, we keep:
- A short masked sample. This is a per-project setting and can be turned off; then only the type and count remain.
- How many values of each type were found.
- Where in the text they were found.
Every detection is written to the audit log as a pii.detection event. Audit records are linked with a SHA-256 chain. If someone changes an old record, the chain breaks and the change is visible. Detection events are kept for 90 days by default. You can set this from 0 to 3650 days, and events can also go to your SIEM.
So the log proves that masking happened without becoming a second copy of the data. The security team can see how many times, in which project and what type of data was caught. They don't see the data itself.
Responses are scanned too
Personal data doesn't only come from the prompt. A model can carry it into the answer from a document it was given or from earlier messages. BaseLLM scans the answer before it reaches the user. In block mode the sensitive part is removed and the rest is delivered. For streaming answers the detection is logged but the text is not changed.
Masking alone is not compliance
Masking is a technical measure. Full compliance with data protection law (KVKK in Turkey, GDPR in the EU) depends on your own legal review. But the first question security teams ask before approving an AI project is always the same: "What happens if someone pastes customer data into a prompt?" Without a good answer to that, the project usually doesn't move.
Details are in the data masking and audit log docs. The 30-day evaluation is the easiest way to try it on your own infrastructure.