Keeping PII out of AI prompts
Why I couldn't use AI to find the PII in members' notes, how a passing test fooled me, and what I now check before any AI feature reads personal data.

If your app stores what people type, sooner or later someone asks for an AI feature on top of it. For us the client asked for something “like” a summary button. Keeping members’ private details away from the AI model wasn’t part of the request, and it turned out to be most of the work, so here’s how I did it and what went wrong on the way.
I work on a client’s app where personal assistants handle everyday tasks for members. Every task has a timeline of notes, and some of those timelines get long. “Summarize with AI” sends a task’s title and timeline to Gemini and gives the assistant a short summary, so they can catch up on a long task fast. Speed matters to them, which shaped a few choices later on.
What’s in the notes
The problem is what members write. Task notes can hold card numbers, logins, door and gate codes and Wi-Fi passwords, right next to the names of their kids, partners and pets. All of that is personally identifiable information (PII), and every AI call that reads it is one more place it could leak. So on November 6 I set one rule for every AI call that reads member text: it never gets the raw text. Some sources are never read at all, like the vault where members keep documents and cards, and payment data.
Why I couldn’t ask an AI to find it
The easy version would be to send the whole timeline to an AI model and ask it to mark the personal data. But that sends the personal data to an AI model, which is the exact thing the rule is there to stop. So the gate had to be plain code: rules that run in our backend (Xano) before anything leaves.
Rules are harder than they sound, because real notes aren’t neatly formatted. People write “pw” or “pass”, or they put the password on its own line under “Costco login”. A rule that catches every clean example in your test file can still miss the messy one a member actually wrote, and once a password is in a prompt you can’t take it back.
How the gate masks PII before the AI call
Before the AI call, the gate strips HTML, swaps names for tokens like “Member 1” and “Child 1”, and replaces private values with labels such as [phone], [email] and [number]. Lines that name a password, login, PIN, code, card, account or ID are hidden whole. When the summary comes back, a second step puts the names back, so the assistant reads “Emma” and not “Child 1”. Last names are masked too and never come back. If the gate blocks a text, the AI isn’t called at all, and there’s no fallback that sends the raw text instead.
Here’s a made-up note:
Hi, it's Dana Whitfield. Can you book a plumber for Thursday morning? Emma will be home after 3.
The gate code is 4482 and the wifi password is BlueOtter!19.
Pay with my Amex 378282246310005 exp 04/28.
Lucas has soccer at 5, so call me at 555-201-4477 or dana.whitfield@example.com if they run late.
And this is what the gate hands to the AI:
Hi, it's Member 1. Can you book a plumber for Thursday morning? Child 1 will be home after 3.
[private details hidden]
[private details hidden]
Child 2 has soccer at 5, so call me at [phone] or [email] if they run late.
The summary can still say there’s a plumber on Thursday, a kid home after 3 and soccer at 5, while the gate code and the card never leave our server.
I built the gate and its tests with Claude Code. I used it to write the rules, the test scripts and the made-up test cases. The calls on what had to be protected, and on when a pass wasn’t good enough, stayed with me.
“All tests passed”
I tested with made-up data only. Our staging server holds copies of real members, which means it doesn’t count as test data.
The first end-to-end test passed while a made-up password was still reaching Gemini, which means the test was telling me my samples were clean, not that the feature was safe. Two things were wrong. The test checked the AI log, and the log keeps only the first 1,500 characters of the prompt, so it never saw the timeline. And my sample timelines were hand-written, while the real admin panel puts > in front of every note line, and the rules for passwords on their own line didn’t allow for that.
20,178 made-up cases
After that I stopped trusting small sample sets. I generated 20,178 cases: each made-up value written many ways (26 phrasings for passwords alone), then placed in plain text, HTML, bullet lists and task timelines. 8,968 of them were rendered by the admin panel’s own timeline code, so the format was the real one. The first run found 6,626 leaks, and I fixed every one.
Then I added blind sets: phrasings written after the rules were tuned, run once before any fix. The first two came back 40 of 45 and 30 of 32 clean. Two more, written by Claude Code agents that had never seen the rules, came back 43 of 50 and 42 of 60.
Strict mode, and what it costs
That last result is why I stopped trying to catch every way of writing a password. Strict mode doesn’t need to understand the value. It hides any line that names a password, login, PIN, code, card, account or ID, plus up to four short lines under it, because that’s where people put the username and the password.
Blind sets after strict mode came back 74 of 80 and 72 of 80 clean on the first run. I fixed those misses too, but I report the first-run number, because after fixing, the score is always perfect on cases you’ve already seen and says nothing about the next one.
It costs something. Of 125 harmless notes, 9 were hidden whole. The summaries still work, because names, phones and emails are swapped right inside the sentence, amounts and times stay as they are, and an assistant catching up doesn’t need a gate code from a summary.
There’s a known gap as well: the rules only know English words, so “contraseña” or “şifre” won’t trigger them. We decided to leave other languages out for now, and I’d rather say that here than pretend the gate covers everything.
The checks also add time to every summary, and assistants want it fast, so lines with none of the keywords skip the heavy checks. In my tests that was 55% to 88% of all lines.
The bug that wasn’t a leak
The end-to-end test now compares the exact length of the prompt Gemini got with the prompt we expected. For three days it was one character short. My first fix made it three. The real cause was my use of Xano’s multi-argument concat: I’d assumed the wrong argument order, so the whole gated text landed in the title slot of the prompt and the timeline slot was empty. Nothing leaked, since everything had already been through the gate, but the prompt was wrong, and only the length check caught it.
Before your AI feature reads user data
The client asked for a feature. The careful part was ours, and I think it always is. If you’re about to build something like this, here’s what I’d check first:
- Which sources can you leave out? If the feature works without some data, don’t read it at all.
- Can you find the private data without sending it anywhere? If the plan is “ask an AI to find it”, it’s already been sent.
- Does your test data look like the real thing? Render it with the same code your app uses.
- Does your test check what the model received? A log or a preview can cut off right before the part that matters.
- Are you counting misses on text you haven’t seen? Run a blind set before you fix anything.
- What happens when the check fails? Block the call. Don’t fall back to the raw text.
- Is your staging data really test data? If it’s a copy of production, it isn’t.
If you’re building an app with an AI feature in Draftbit, a Read Only thread is a good way to work through the first few questions. The agent reads your project and answers questions about how it works without changing any files, so you can find out where user text goes before you change anything. You can start building free.