Inspiration
People paste letters from their doctor, bank or landlord into ChatGPT, Gemini or Claude every day to understand them. Those letters carry a full name, date of birth, Social Security number, card number, address and a diagnosis. Once pasted, that text can be stored and read by people at the AI company: Google's own Gemini API terms ask developers not to send personal information to the free tier. We wanted the explanation without the exposure.
What it does
- You drop a PDF, a photo of the letter, or paste the text. PDFs are read in the browser; photos are read by Gemini Nano on your computer. Nothing is uploaded.
- Masker finds names, organizations, addresses, birth dates, SSNs, card, account, policy and record numbers, and replaces them with labels like [PERSON_1] on your own computer. You see your letter and "What AI will see" side by side, and can show or hide any detail with a click.
- You ask a question. Gemini answers using only the masked letter, and Masker puts your real details back into the answer locally.
- Use any chatbot: "Copy for ChatGPT / Claude" copies the masked letter with a note to keep the labels; paste the answer back and your details return.
- Optional: a cloud check reads the masked letter and points at indirect clues that could still identify you ("the only licensed falconry instructor in Millbrook", "your husband Tomas"). One click hides them.
- A "What left this computer" log lists every request. A leak guard checks every outgoing request body and stops it if a hidden detail is still inside.
How we built it: what runs where, and why
All AI runs through Firebase AI Logic, with three inference modes chosen on purpose:
| Step | Mode | Why |
|---|---|---|
| Reading the raw letter, finding names, organizations, places, IDs | ONLY_ON_DEVICE (Gemini Nano in Chrome, JSON schema output) |
The raw letter must never leave the computer. PREFER_ON_DEVICE would silently fall back to the cloud when the model is missing, so it is never used for raw text. In the SDK, ONLY_ON_DEVICE throws instead of falling back. |
| Reading a photo of a letter | ONLY_ON_DEVICE (Gemini Nano, image input, streamed) |
A photo of a medical or tax document is as private as its text, so it never goes to the cloud. Without Gemini Nano the page asks for the text instead. |
| "Could anything else identify me?" | ONLY_IN_CLOUD (gemini-3.5-flash-lite, JSON schema output) |
Needs world knowledge a small local model lacks: how rare a job is, how small a town is. It sees masked text only. |
| Questions about the letter | PREFER_IN_CLOUD |
Better answers from the cloud model; still works offline with Gemini Nano. Either way it sees masked text only. |
Every answer shows where it was computed (inferenceSource).
Around the models:
- A pattern layer with no AI: SSN, cards with a Luhn check, IBAN, phones, emails, US addresses, labeled IDs (MRN, member, policy, account), dates, names after titles and in form fields ("First name / Last name" on a 1040). It runs instantly in every browser and is the safety net under the model. Patterns for Russian documents (names with a patronymic, tax and insurance numbers) are in too.
- On-device findings are accepted only if they appear verbatim in the letter, so the model cannot invent or rewrite data. The letter is passed as data, and the prompt tells the model to ignore instructions inside it.
- The label table lives only in the tab's memory: never sent, never stored.
- Birth dates become an age (90+ grouped, as in the US HIPAA Safe Harbor rule), so the answer can still say "at 41".
- Firebase App Check with reCAPTCHA (Fraud Defense), Firebase AI Logic's per-user limit plus a client limit, a strict Content Security Policy, no analytics, no accounts.
- 35 unit tests for patterns, labeling, restoring, the leak guard and parsing.
Challenges we ran into
- Gemini Nano is not on most visitors' machines (it needs desktop Chrome, 22 GB of free disk, 16 GB of RAM or a GPU). Masker works without it: patterns plus your own selection, and the cloud stays locked until you confirm the masked text.
- On a laptop with little free memory the first on-device run is slow while the model loads, so the page shows progress and the pattern results right away.
- Names appear in many spellings ("Dana R. Whitfield", "Ms. Whitfield", "Dana") and, on forms, split across "First name" and "Last name" fields. All of them share one label, including in the question you type.
Accomplishments that we're proud of
The privacy split is not a checkbox: the raw letter physically never reaches the cloud, and a guard in the page enforces it on every request.
What we learned
Hybrid is most useful when each mode is picked for a reason: on-device for what must stay private, cloud for what needs world knowledge, and "prefer cloud" for what can degrade gracefully offline.
What's next
A Chrome extension that masks text right inside ChatGPT, Gemini and Claude; more languages for the on-device model; a faster first run when Chrome keeps Gemini Nano warm.
Built during the submission period
Everything in the repository was written during the #BuildHybridAI 2026 submission period: pattern layer, on-device detection, on-device photo reading, labeling and restore, leak guard and network log, cloud clue check, questions, PDF import and the web app. No pre-existing code.
Try it
- Live app: https://masker-d7943.web.app
- Code: https://github.com/Sofiia7/masker
Built With
- chrome-prompt-api
- firebase-ai-logic
- firebase-app-check
- firebase-hosting
- gemini
- gemini-nano
- pdf.js
- recaptcha
- typescript
- vite
- vitest