short · 3 min
PII handling
Keeping personal data out of prompts, logs and training data where it doesn't belong.
updated 29 Sept 2026
A common first plan for personal data in an LLM app goes like this: add a masking step to the logs, and we're covered. Let's see how far that gets us.
A user writes: "Hi, I'm Priya Shah, my card 4111 1111 1111 1111 was charged twice." Follow that sentence. It goes to the model provider inside the prompt. It lands in our trace store if we capture messages in LLM tracing. And since traces turn into eval cases and review examples, it can spread from there into datasets.
The mask sits on one of those paths. So handling PII really means making a choice for each place: what goes in, what gets masked, and how long it stays.
Our traces
The simplest move is to not capture the text at all. The OpenTelemetry conventions for LLM spans leave the prompt and reply off by default, because they're likely to hold personal data. Token counts, timing and cost don't need the text.
When we do need messages (and for debugging we will), we mask before they
leave our app. Langfuse's tracing SDK, for example, takes a masking
function that runs on our side at export time. A first version is a regex:
anything that looks like 13 to 19 digits becomes [REDACTED CREDIT CARD],
and the same idea for emails and phone numbers. Keep it fast, since it
runs on every export, and make sure it can't throw. If it does, the whole
batch of traces gets dropped.
So the card number is gone. What about "Priya Shah"?
A regex can't find it. Names have no shape. For names, places and ID numbers we need a detector. Presidio is an open-source one: it mixes named-entity recognition, regexes, rules and checksums, looks at the surrounding words, and then replaces, masks, hashes or encrypts what it found. And even Presidio's docs say plainly that there's no guarantee it finds everything. So detection is one layer. The others are capturing less, limiting who can read traces, and deleting old ones.
One more catch. A masking hook on one tracing SDK only cleans what that SDK sends. If the same spans also go to a second backend, they go there unmasked. With plain OpenTelemetry, mask in the collector, so every backend gets the clean copy.
The provider
Masking our traces does nothing to what we already sent the model. That's up to the provider's data policy, and policies differ. As of 2026-09, OpenAI doesn't train on API data unless you opt in, keeps abuse-monitoring logs for up to 30 days by default, and offers zero data retention only with its approval. Every provider we send to needs that check, including a fallback provider that only gets traffic on a bad day.
Could we mask the prompt too, before the model sees it? Sometimes. But if Priya asks "did you charge the card ending 1111?", masking takes away the thing the model needs to answer. Masking traces is usually safe. Masking prompts has to be checked feature by feature.
The datasets
The last path is the easy one to forget. A trace that becomes an eval case or a shared example carries whatever slipped past the mask, so it's worth checking those for names before anyone shares them. Which brings us back to the first plan. The mask on the logs was a good start, and it covered one path out of three.
Further reading
- Presidio, Data Privacy Stack (formerly Microsoft). How detection and anonymization work, with an honest note on what gets missed.
- Masking sensitive data, Langfuse docs. A masking hook with regex examples. Read the caveats.
- Semantic conventions for generative client AI spans, OpenTelemetry GenAI SIG, status Development. Why message content is opt-in on LLM spans.
- Data controls in the OpenAI platform, OpenAI docs. One provider's training and retention rules, as an example of what to look for.