Inspiration
People paste letters, contracts and patient notes into AI tools every day. The useful part of the task (summarise, reply, translate) rarely needs the names, addresses or bank details, yet those are exactly what gets uploaded. Hybrid inference makes a clean split possible: the private part of the work stays on the device, the heavy part goes to the cloud.
What it does
- You paste a document. A privacy scan runs on your device: deterministic rules find e-mails, IBANs, card numbers, national IDs, phones and postcodes, and Gemini Nano finds names, addresses, organisations and dates of birth.
- You see exactly what will leave the device: the masked text with placeholders such as
[PERSON_1], next to the table of original values. If something was missed, you type it and it is masked too. - You pick a task. Only the masked text is sent. Long or reasoning tasks (draft a reply, translate) run in the cloud; short ones (summary, action items) prefer the on-device model.
- The answer comes back with placeholders. The real values are filled back in locally. The app also flags any placeholder in the answer that is not in your map.
How we built it
- Firebase AI Logic Web SDK with three model handles:
ONLY_ON_DEVICEfor detection,PREFER_ON_DEVICEfor short tasks,ONLY_IN_CLOUDfor heavy tasks. - Detection prompt returns one
TYPE|exact textline per finding. A value is kept only if it really occurs in the document, so invented findings are dropped. - Rules validate before they flag: IBAN mod 97, Luhn for cards, check digits for Turkish national IDs. Overlaps resolve to the longest span.
- App Check with reCAPTCHA Enterprise; Firebase Hosting; no build step, plain ES modules.
- Unit tests for the validators, masking, re-identification and the model-output parser (no model, no network).
Challenges
- Asking the on-device model for JSON with a schema took about 17 seconds on the sample letter. Switching to a line format brought it to about 2 seconds.
- The model over-masked at first (job titles, currencies). A tighter type list and the "must occur in the text" filter fixed it.
- Initialising the device model could hang; the app now races it against a short timeout and falls back to rules.
- The biggest one: in a browser without the
LanguageModelAPI, Firebase AI Logic creates no on-device adapter, and a model set toONLY_ON_DEVICEquietly called the cloud instead. Our own test with the API hidden caught the raw sample letter in agenerateContentrequest. The app now checks for the API itself before the scan and, when it is missing, runs the rules only and says so. Retested on the live site: no request during the scan.
What we measured
- One machine, Chrome 155 on macOS: sample letter scanned in about 2 seconds on-device once the model is loaded. After Chrome unloads an idle model, a scan took 15 to 28 seconds; the app now warms the model on the first click.
- A short task (Summarise) in PREFER_ON_DEVICE mode answered in about 2 seconds with no network request. With fetch blocked, the privacy scan still completed.
- 5 fictional documents: all 24 expected personal values masked; the document with no personal data left untouched. This is a small set, not a benchmark.
Limits
- The on-device model can miss personal data; the review step is there for that. This is a helper, not a compliance guarantee.
- Needs desktop Chrome with the built-in model. Without it, rules still run and names need a manual check.
- App Check returns a verified token on the hosted demo; enforcement is not switched on yet.
What's next
Document upload (PDF), more national ID formats, a saved history that stores masked text only, and enforcement of App Check.
Links
- Live demo: https://redact-and-ask.web.app (desktop Chrome with the built-in model)
- Code (Apache-2.0): https://github.com/ahmetilhanli/redact-and-ask
This project was built with AI coding assistance (Claude Code). All sample documents are fictional.
Built With
- chrome
- firebase
- firebase-ai-logic
- gemini
- gemini-nano
- javascript