Part of the PolicyTrace series
Documents System note
I masked the personal data. Then I found an unmasked copy.
Masking personal data before the model sees it isn't enough if the same container keeps the unmasked text on disk. How I found it, the fix, and what masking still misses.
• PolicyTrace masks names before any text reaches the model. While checking its deployment, I found the same container was writing the unmasked text of every PDF to a debug folder and never deleting it.
• It's fixed: debug output is off by default and, when on, is deleted with the session. A test stops the default being switched back.
• Masking also covers less than I'd said. Postcodes, dates of birth, the car and every premium still reach the model, and that has to be written down before real policies go near it.
PolicyTrace reads car insurance policy PDFs and returns one checked record. It masks personal data, replacing names, phone numbers and most place names with tokens, before any text goes to the model. I'd said that in most of what I've written about it, and it's true. While checking the deployment for this post, I found that the same container was also writing the unmasked text of every uploaded PDF to disk, and never deleting it.
On the public demo the risk was small, because the only documents anyone should upload are the synthetic ones in the repo. But it's a good example of what separates a working demo from something you could point at real policies.
The folder nobody cleaned up
config/settings.yaml has a debug section, and it was switched on. For every run, src/api.py created output/debug/run_<timestamp>/, and src/agents.py wrote four things into it for each PDF: the raw Markdown from the parser, the masked Markdown that went to Groq, the extraction JSON and a line of timing metrics. The raw Markdown is the document before masking, names and all.
Uploads live in a separate folder, output/sessions/, and that one does get tidied: when it starts, the API deletes session folders older than session_ttl_days, which is 30. There's also a DELETE /api/session/{id} endpoint, whose docstring said it removed "all debug artifacts for this session". It didn't. It deleted the session folder, and the debug folder was somewhere else, named by time rather than session.
None of this was hidden. Debug output was the right default while I was building the extraction, because reading the masked Markdown is how you find out what Presidio, the masking library, missed. I just never changed the default when the app went public.
The fix was small. Debug output is now off by default, and when you switch it on, the API writes it to a debug/ folder inside the session, so deleting the session or the 30-day clean-up removes it too. A test in tests/test_settings.py fails if the default is ever switched back on.
What masking actually covers
It's worth being exact. Presidio catches most names and town names, but it has no rule for UK postcodes, and street lines often get through, so the overnight postcode and much of each address reach the model as written. So do dates of birth (dates aren't masked, because the extraction needs them), the policy number, the registration and the car, occupations, licence types, claims and convictions, and every premium and excess. A name Presidio misses goes to the model too; you'd spot it in the record, because it shows up as a real name where the others are MASKED_ tokens.
Unmasked text also stays in the container: the uploaded PDFs, and the source snippets saved with each highlight in result.json. Both sit in the session folder until the session is deleted, or until the API next starts after 30 days.
How it's deployed
The deployment is deliberately small. PolicyTrace is a FastAPI backend and a React frontend, so it runs as a Docker Space on Hugging Face. The Dockerfile has two stages:
node:20-slimrunsnpm ciandnpm run buildto produceui/dist.python:3.11-sliminstalls the Python requirements, downloads the large English spaCy model Presidio uses for names (en_core_web_lg), copies the code and the built UI, and startsuvicorn api:appon port 7860.
FastAPI serves the API under /api/* and the React app for everything else. The Groq key is a Space secret. There's no CI: the repo has no .github/workflows, and the Space rebuilds whenever code is pushed to it. With 32 fast unit tests, that's an easy thing to add.
What I'd change before a real policy went through it
- Sign-in. There's none. A session id is all you need to fetch its PDFs from
/api/pdf/{session_id}/{filename}. The ids are random UUIDs, which is fine for a demo and not an access control. - Named reviewers and a history. Review actions are saved with the reviewer set to "anonymous", and a second action on a field overwrites the first.
- A queue.
POST /api/processdoes all the work inside the request, two to three minutes on Groq's free tier. That should be a background job the screen checks on. - Proper storage. Space storage is temporary, which is right for a demo. Real use needs a database, object storage for PDFs, and a retention period someone has agreed to.
- Run records. Each result should record the prompt version, the model and the merge rules that produced it, so a changed answer can be explained later. The pieces exist in the config, but nothing writes them onto the result yet.
- The privacy basics. A data-processing agreement with the model provider, a UK postcode recogniser, and a measured check of what Presidio misses on real layouts.
Limits
This list comes from reading one codebase that I wrote, against a synthetic pack. A security review by someone else would find things I haven't, and the masking gaps above are from reading the code and one run, not a measured test on real documents.
The decision behind it
- Decision: one Docker image on a free Hugging Face Space, debug output off by default, and only synthetic documents on the public demo.
- Alternative rejected: a full production set-up (sign-in, database, queue) before showing anything. It would have delayed the demo, with nothing real to protect.
- What it cost: the demo can't take real documents, and the gaps above are only safe while that stays true.
- When to revisit: before the first real policy goes in. Every item in the list above comes first.
Code: deployment notes and
src/privacy.py on GitHubDemo: the live demo is the same image. Use the synthetic pack, not your own documents
Related: What happens to a PDF inside PolicyTrace · Try PolicyTrace yourself: a step-by-step guide
What's the folder your privacy story forgot?
First published 17 Oct 2026. Updated 25 Oct 2026: new title; the spaCy model and request time now match the code; new diagram; the privacy gaps moved into their own section.
Get the next note by email
One short email when something ships or breaks. Free.