Skip to main content

Personal data masking

Pishtaq finds personal data in every request before the request leaves for the model provider, and swaps each value for a fake value or a placeholder. The provider never sees the real data. When the reply comes back, Pishtaq puts the real values back, so the person or tool on the other end sees them as if nothing had happened.

Putting values back works on /v1/chat/completions, /v1/messages, and /v1/responses, with and without streaming, and inside tool calls and tool results. This is how coding agents such as Claude Code read and edit files.

Secrets such as API keys and passwords are handled by the same guardrails. See Secret detection.

What it finds​

TypeWhat matchesSent to the provider as
PINFL14 digits with a valid birth date, within 40 characters of a word such as JSHSHIR, PINFL, or ПИНФЛA placeholder such as <PINFL_3f9a1c2b7d40>
Passport and ID cardTwo Latin capitals and seven digits, such as AA1234567A fake with series ZZ
Driver licenceThe same shape near a word such as guvohnoma or водительскоеA fake with series ZZ
INN9 digits near STIR, INN, СТИР, or ИННA placeholder
Phone+998 or 998 and nine digits, with spaces, dashes, dots, or bracketsA fake with operator code 00
CardUzcard, Humo, Visa, and Mastercard numbers that pass the Luhn checkA fake of the same scheme, with zeros in the issuer digits
Bank account20 digits near a word such as hisob raqami, счёт, р/с, or MFOA placeholder
EmailAny email addressA fake at example.invalid
Car plateUzbek plates such as 01 A 123 BC and 01 123 ABCA fake with region 00

Fakes keep the layout of the original and come from ranges that no real person, card, or vehicle holds. Placeholders are used where a fake could mislead the model into a wrong conclusion, such as a birth date worked out from a fake PINFL.

The same real value always gets the same replacement, so a conversation stays consistent from turn to turn and provider prompt caching keeps working. The replacement depends on the masking key, so it differs between deployments.

Which requests are covered​

Masking covers the text fields of a request: messages, system prompts, instructions, tool results, documents, and tool call arguments, including values inside JSON. It runs on:

  • /v1/chat/completions
  • /v1/messages, including /v1/messages/count_tokens
  • /v1/responses
  • /v1/completions and /v1/embeddings, where the prompt and input fields are masked

These are not masked in this version:

  • Names and addresses.
  • Text inside images and files.
  • The provider pass-through routes, such as /anthropic/*, which forward requests untouched.

Set it up​

Generate a key once for each deployment and keep it secret, because it decides which fake each real value gets. It must be hex and at least 32 bytes long.

openssl rand -hex 32

Set the result as the environment variable PISHTAQ_MASKING_KEY. Then list two guardrails in config.yaml. Masking must be the first guardrail and restoring must be the last, so every other guardrail, including your own and any outside service, sees only masked text.

guardrails:
- guardrail_name: pishtaq-mask
litellm_params:
guardrail: pishtaq_ee.masking.guardrail.PishtaqMaskGuardrail
mode: pre_call
default_on: true
# your other guardrails go here
- guardrail_name: pishtaq-restore
litellm_params:
guardrail: pishtaq_ee.masking.guardrail.PishtaqRestoreGuardrail
mode: post_call
default_on: true

When Pishtaq refuses to start​

Pishtaq stops at startup, and the log says how to fix it, in these cases:

  • The key is missing, is not hex, or is shorter than 32 bytes.
  • Only one of the two guardrails is listed.
  • Either guardrail lacks default_on: true.
  • Masking is not first among the pre_call guardrails, or restoring is not last among the post_call guardrails.

If a guardrail added later through the admin UI lands in front of masking or after restoring, Pishtaq moves its two guardrails back into place, refuses the one request that noticed with a 503 and a message asking the sender to try again, and writes a warning to the log.

A guardrail with scan_raw_request: true reads the request before any masking, so it sees real personal data. Pishtaq writes a warning to the log that names it.

What gets logged​

Logs, logging integrations, and stored request records keep the masked text, never the real values.

If masking fails for any reason, Pishtaq refuses the request with a 503 and does not send it to the provider. The log records only the type of the error, not the request.