ReleaseInsight · On RadarHabr AI→ original

Support Agent Hides Names and Card Numbers from an External LLM: 30+ Data Types

A tech support agent reads employee emails that contain full names, passport numbers and card numbers. Sending such text to an external LLM without precautions risks violating Russia's Federal Law 152-FZ. The author replaces every value with a tag such as <PERSON:1e0da62146> and keeps the "tag–value" table on their own side. Rules detect 30+ data types, and a local Qwen3.5-9B catches what the rules miss. That is why, in agent systems, masking has to happen before any request goes outside.

AI-processed from Habr AI; edited by Hamidun News
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Rules search for 30+ data typesfull names, phone numbers, passports, cards, IP addresses
Name dictionaryabout 426 thousand word forms based on OpenCorpora
Key metric #3Fine for a personal data leak since 30.05.2025: up to 15 million rubles

Picture an AI agent that processes the internal tech support mailbox. An employee writes: "My name is Ivan Petrov, I can't log into my account, card 4276…, phone +7…"

The company has no language model of its own, so the email goes to an external LLM provider (a large language model in the cloud). The author of the Habr write-up solved this problem as follows: before sending, every piece of data that can identify a person — full names, phone numbers, passports, card numbers, IP addresses — is replaced with a tag, while the real values stay inside the company. The "30+" in the headline means the author's search rules cover more than thirty types of such data.

The model needs the meaning of the email, not the identity of the author. This is exactly the question lawyers and the security team ask first: what leaves the company?

Why you can't just send the email

Even a good provider (Yandex AI Studio, GigaChat, or a foreign model) does not close the question. Passing data to a provider counts as an instruction to process personal data under Part 3 of Article 6 of Federal Law 152-FZ "On Personal Data", and the employee who wrote to support usually did not consent to such a transfer. If the provider learns from the requests, it stops being a processor and becomes an independent data operator. A foreign model adds cross-border transfer: Roskomnadzor must be notified in advance. And since May 30, 2025, the fine for a leak reaches 15 million rubles, while repeat violations carry a turnover-based fine.

The scheme is simple: each value is replaced with a tag, and the "tag–value" table stays inside. The model replies with text containing the same tags, after which the values are restored in place. The approach even has a name in regulation: Roskomnadzor order No. 140, effective September 1, 2025, describes the method of introducing identifiers. Data is replaced with codes, and the key is stored separately.

How to find the data

The main work is done by rules, without a model: they are fast, free, and predictable. Accuracy relies on checksums and context: a random 16-digit number is not counted as a card, and 10 digits are recognized as a passport only when the word "passport" or "series" appears nearby.

Names are the hardest part: "Roza", "Lev" or "Sokol" can also be non-person words. To handle this, the author built a dictionary of roughly 426 thousand word forms: 231 thousand surnames, 116 thousand patronymics, 67 thousand first names, and 13 thousand ambiguous names. The basis is the open OpenCorpora corpus, and all grammatical cases were generated in advance, so "Ivanu Petrovichu" is found just like "Ivan Petrovich". Next, combination rules apply: a first name combined with a patronymic or surname counts as a full name, an ambiguous first name is matched only next to a surname, and after "ul.", "pr." and "metro" no full name is searched for at all.

For sending to the model, a hash tag is used. The same value gets the same tag in every field, so the sender's email and the email in the text look to the model like one address.

Two mistakes that break the protection

The first: sending the entire record to the model. It contains a report with the actual values, and the protection disappears. Only text fields, the subject and the body of the email, should go into the request.

The second: the model tries to "help" with the tags by inflecting them, translating them, or removing the brackets. Four rules were added to the system prompt: copy the tag character for character, do not guess what is hidden behind it, and do not invent new tags. Without them, the reverse substitution fails.

The substitution itself is done by a small function. It builds a table from the report and replaces the tags in the response. Tags that were not in the input are collected in an unknown list, and such a response is better shown to a human. Returning everything is also not necessary: in a test, the substitution returned the full card number, although the client does not need it. Now the name and login are returned in full, the card only with its last four digits, and document numbers are not returned at all.

A local model for what rules can't catch

An address, a date of birth, or a diagnosis is hard to describe with a rule, and every company has its own sensitive items: contract numbers, discounts, deal amounts. For these, a small local model runs after the rules; it sees the text with names, phones and cards already replaced. The author tested Qwen3.5-9B: in 4-bit quantization it takes about 6 GB and runs on a Mac mini or an inexpensive server with a GPU. Sensitivity criteria are set in plain words.

In the test, the model found an address, a date of birth, a sentence about sick leave with diabetes, and "a 15% discount". The request takes about 1,900 tokens, roughly 4 kopecks through the cloud; locally, it is just server time. The model missed a contract number. It cannot invent data, because the code discards findings that do not appear verbatim in the text, but it can miss things. Conclusion: the model complements the rules rather than replacing them, and critical data with a recognizable format is better added to the dictionary.

Among local options, the author names models with 7–9 billion parameters, open weights, and function-calling support. They can be run with Ollama, LM Studio, llama.cpp or vLLM on a server; all expose OpenAI-compatible APIs, so only the address changes.

Takeaways

Before launch, the scheme was shown to lawyers and security staff using live examples, then run on several thousand real emails and checked by hand. According to the author, there have been no depersonalization errors since launch. This is the experience of one company, not an independent audit, and Russian regulation is key here. But the practical lesson applies broadly: masking must come before any step that sends text outside, and a clear scheme with tags overcomes objections faster than presentations do.

Story

Key Questions Answered

Why you can't just send the email?

Even a good provider (Yandex AI Studio, GigaChat, or a foreign model) does not close the question. Passing data to a provider counts as an instruction to process personal data under Part 3 of Article 6 of Federal Law 152-FZ "On Personal Data", and the employee who wrote to support usually did not consent to such a transfer. If the provider learns from the requests, it stops being a processor and becomes an independent data operator.

How to find the data?

The main work is done by rules, without a model: they are fast, free, and predictable. Accuracy relies on checksums and context: a random 16-digit number is not counted as a card, and 10 digits are recognized as a passport only when the word "passport" or "series" appears nearby. Names are the hardest part: "Roza", "Lev" or "Sokol" can also be non-person words.

What are the key details on Two mistakes that break the protection?

The first: sending the entire record to the model. It contains a report with the actual values, and the protection disappears. Only text fields, the subject and the body of the email, should go into the request. The second: the model tries to "help" with the tags by inflecting them, translating them, or removing the brackets. Four rules were added to the system prompt: copy the tag character for character, do not guess what is hidden behind it, and do not invent new tags.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
What do you think?
Loading comments…