# PII masking at the LLM gateway: log the redaction, not the PII

> Source: <https://dev.to/ramazangulsen/pii-masking-at-the-llm-gateway-log-the-redaction-not-the-pii-4alf>
> Published: 2026-11-20 08:39:48+00:00

**Recommendation:** Mask PII at the gateway before prompts reach the model, block secrets by default, and log only redaction events with a hash chain rather than retaining original prompts.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

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.

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:

`TCKN 100***** 46`, `***4567`
`<TELEFON_1>`, the real value is put back in the answer`[REDACTED:TC_KIMLIK]`
`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`.

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).

`pii.detection`), and audit records are linked with a SHA-256 chain so a changed record is visible
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](https://llm.baseinteractive.com.tr/en/docs/data-masking)
