-
-
SafeRefer: the cloud writes the letter from labels only.
-
Paste a client note into a chatbot, and the name goes with it.
-
Step 1 Hide: code rules catch numbers, Gemini Nano in Chrome catches names, on the device.
-
Step 2 Write: only the labelled text goes to Gemini via Firebase AI Logic + App Check. The tooth list runs on-device.
-
Step 3 Restore: the browser puts the real names back.
-
The actual request body in DevTools: [PATIENT], [PHONE].
-
Offline: the letter is queued, then sends itself when the connection returns.
-
One engine, three professions: chartered accountant and advocate.
-
Honest results: 2–4% of identifiers left on generated notes, about 3 in 10 on realistic ones.
-
Hybrid design: hide on the device, write in the cloud, restore on the device.
Inspiration
Doctors, accountants and lawyers paste client notes into chatbots to get a letter drafted. The client's name, phone number and family details go with the note. I am a practising dentist in India and I build clinic software, so I wanted the convenience of a cloud model without sending identities along.
What it does
SafeRefer is a web app for Chrome. A dentist, a chartered accountant or an advocate types or pastes a note. The note is cleaned inside the browser first: names, phone numbers, IDs, dates and addresses are replaced with labels. The user sees the cleaned text side by side with the original and approves it. Only then does the hidden text go to the cloud, which writes the letter: a referral letter, a case summary for a specialist CA, or a brief to senior counsel. The browser puts the real names back into the finished letter and checks it against the original note.
One engine, three professions. A profession pack changes only words and rules, never a safety check. Dentist: tooth list and clinical terms stay visible. CA: PAN, GSTIN, bank account and similar IDs are hidden, amounts and sections stay. Advocate: case and FIR numbers and settlement sums are hidden, the other side is hidden as a separate person (never as the client), Acts and court names stay.
How Firebase AI Logic is used
- Every model call goes through the Firebase AI Logic web SDK at runtime.
- On-device only: Gemini Nano in Chrome finds the names in free text, so the raw note stays in the browser. Redaction never falls back to the cloud. We found that
ONLY_ON_DEVICEalone is not a lock (in a browser with no on-device model the SDK sends the call to the cloud), so the app checks that Nano is really available before every call and otherwise switches to manual mode with no network call; a test proves zero requests. - On-device first, cloud fallback: the dentist's tooth list runs on Gemini Nano and falls back to the cloud model when Nano is missing; it receives the hidden text only, and a badge shows which model ran.
- Cloud only: the cloud Gemini model drafts the letter from the hidden text only.
- App Check (reCAPTCHA Enterprise) protects the cloud calls. Remote Config can change the section list of each letter and the cloud model name, nothing else, with every value checked and an allow-list for models.
- Offline: redaction and the tooth list still work on the device. Send queues the already hidden letter request in the browser (IndexedDB, hidden text plus profession, never a name) and sends it when the connection returns, with retries every 10 seconds. A service worker keeps the app shell. There is no Firestore and no cloud copy of anything.
Features
- In-browser redaction with a review-and-approve step before anything is sent
- Split view showing exactly what the cloud will receive, and a send guard that checks it once more
- A receipt under each letter: the exact text that was sent, its size and its SHA-256
- Names restored locally in the final letter, and a fact check against the original note
- Three profession packs on one engine, and "My terms" that remember places, labs and ID formats on the device
- Offline mode with a queued letter
- A leak-test page: the redactor is run on synthetic notes and the score is shown, misses included
Honest results
On 25 fresh synthetic notes written with an AI assistant and checked by Dr. Yatin, after the rules were built, 3 of 171 identifiers were left (1.8%) with the code rules plus Gemini Nano. The three were generic words, not names, numbers or places. Before two rule fixes made after the first fresh-note runs, the same notes scored 12% to 17% left, and the builder's own notes had flattered the code (code-only 3.2% on the builder's notes, 43.5% on fresh ones). The advocate set, tested with fixes that were not written for it, left 0 of 69. Ten notes per profession is a small set; "0 of 69" does not mean "never leaks".
On 300 locked generated notes about 2% to 4% of identifiers were left (advocate set 21 of 558, 3.8%). On 40 realistic-style notes written with an AI assistant and sealed before any run, 38 of 132 (28.8%) were left (dentist 8 of 34 and 9 of 33, CA 7 of 33, advocate 14 of 32). So our 3% target is met on generated notes and not on realistic-style ones. The user checks every note before anything is sent.
Value
The professional gets the convenience of a cloud model for the writing, while the identifiers that the redactor finds and the professional approves as hidden stay on their own machine. The redactor can miss a name, so the professional's check is the real control; this prototype makes no privacy claim for real clients and no compliance claim. The approval step and the published leak-test scores let the user see how well the redaction works instead of trusting a promise.
What's next
SafeRefer's core (redaction, send guard, name restore, fact check, packs) is a separate module so it can be reused. After the hackathon it is planned to go into Enamel, the clinic software I build and use in my own dental practice, as the step before any cloud AI sees a patient note. It is not wired in today.
Data and disclosure
All notes in the app, repo and video are synthetic and labelled as such. SafeRefer is a hackathon prototype and gives no medical, tax or legal advice. The CA and advocate letters were reviewed by the builder only. Nothing in this repo existed before the hackathon; it was built with the help of Claude (Anthropic) through Claude Code. Enamel is a separate, closed product and is not part of this entry.
Built With
- app-check
- firebase
- firebase-ai-logic
- gemini
- gemini-nano
- indexeddb
- react
- remote-config
- typescript
- vite
