What it does
A registry abstractor reads kidney-clinic notes and copies stage, eGFR and albuminuria into a registry. Many clinics do not allow raw notes in a cloud model. This app puts a gate in front of the cloud call:
- Local guard. Rules mask MRNs, dates, phone numbers, emails and names after a title or label. Firebase AI Logic
ONLY_ON_DEVICE(Gemini Nano) finds names that appear only in prose. If Nano is not available the app says so on screen, runs rules-only, and never falls back to the cloud with raw text. - Preview. You see the original with what was found, and the masked text, which is the only thing that can leave.
- Leak guard. The exact outgoing request is scanned. For the seeded demo notes the call is aborted if any seeded identifier remains; for any note it is aborted if an identifier pattern remains.
- Cloud call. Firebase AI Logic
PREFER_IN_CLOUDongemini-3.5-flash-lite(free tier) gets only the masked text and returns JSON. The stage shown is derived by code from the extracted eGFR with the KDIGO cut-points; the model's own stage is shown beside it. - Local rehydration and export. Tokens are restored from an in-memory vault; JSON and CSV download.
Testing instructions
Open the test URL in desktop Chrome. No login, no keys; all notes are synthetic.
- The first demo note is loaded. Press Run local guard, then Send masked text to the cloud model. You get eGFR, albuminuria category, the CKD stage (derived by code from the eGFR) and the KDIGO risk matrix, with JSON, CSV and FHIR R4 downloads.
- Pick another demo note. Without Gemini Nano in your Chrome, rules miss names inside sentences, so the guard blocks the cloud call and outlines the leftover words in red. That block is the safety check working. Press Mask these and re-check, then Send.
- To see the no-Nano path on a machine that has Nano, open https://registry-gate-hybrid26.web.app/?rules-only
- Open Hybrid Egress Payload Inspector to see the exact bytes sent and the SDK's own
inferenceSourcefor each step (on_device/in_cloud).
How we built it
Vite and plain JavaScript. One getAI, two getGenerativeModel calls (on-device and cloud). Firebase App Check with reCAPTCHA Enterprise, Firebase Hosting on the Spark plan, no billing account. 40 tests and CI run on every push; the leak test checks that the cloud call is never reached when the guard fires.
The Egress Inspector shows the Firebase AI Logic SDK's own inferenceSource for each step, so the hybrid routing is reported by Firebase, not by us: in a live request, name detection reported on_device (Gemini Nano in Chrome) and extraction reported in_cloud. Firebase AI monitoring is switched on, and we read Google's own request logs to check what actually arrived.
Numbers we measured (all on synthetic notes)
- Video clarification: at 1:16-1:27 the video's 100-note run used a mock cloud. Rules alone masked 683 of 772 seeded identifiers; 71 notes were blocked and 29 were sent to the mock; none of the 29 payloads held a seeded identifier. That zero is a property of the guard (it checks the same seeded list), not an independent result. At 0:36 and 1:03, "blanks" and "only placeholders" mean masked note text with the clinical content kept, not a guarantee that every personal detail is gone. At 1:07, the stage shown is derived by code from the eGFR the cloud model extracted. The "154 of 154" with Nano is the 20-note set.
- With Gemini Nano plus rules: 154 of 154 seeded identifiers on the 20-note set, in one in-app run on 19 Nov 2026. One run; model output varies; Nano also masked ordinary words such as "Family".
- Real cloud model, 100 seeded notes, three runs (names masked by the seeded-name oracle, so these runs test extraction, not masking): eGFR and albuminuria category 100/100 in every run; the model's own CKD stage 86, 85 and 83 of 100 (the same 14 notes missed each time, all one stage off); stage derived by code from eGFR 100/100.
- What Google's own logs saw: for one live request from the deployed app, the request logged by Firebase AI Logic (Cloud Logging) held only placeholders such as [NAME_1] and [MRN_1]; none of the 143 seeded identifiers of the 20 synthetic cases appeared. One request; this reads Google's side, independent of our guard.
- Real published prose (50 open-access PubMed Central nephrology texts with synthetic identifiers; oracle masking, so extraction only): when the schema forced a number, the model returned 10 eGFR values that appear nowhere in the text. After allowing "not documented", numbers absent from the text fell to 0 and 16 of 18 study abstracts that give only ranges were answered "not documented"; the synthetic results stayed at 100/100. The cost: 3 case reports with a stated value (2 written as approximate) were also answered "not documented". The automatic answer key still needs a manual audit, so we do not report a match rate.
Limits (we state them)
- Templated synthetic notes plus one run on 50 published abstracts. Nothing here says how it behaves on real charts.
- For a note you paste yourself there is no seeded list, so only patterns are checked and names in prose are not; the app asks you to read the masked text first.
- Not a de-identification tool. No compliance or clinical-performance claim. No time saving has been measured.
- App Check tokens are sent but enforcement is not switched on in the console.
What we learned
Rules miss names inside sentences; in one run, Gemini Nano plus rules masked all 154 seeded identifiers on the 20-note set, including those names, though it also masked some ordinary words. A deterministic gate in front of the one cloud call makes a miss visible instead of silent. The independent number is how many identifiers the masker hides; the "0 leaked" count is a property of the guard, not a result.
What's next
Held-out hand-written notes to measure the masker without the seeded answer key, a saved and repeated Nano benchmark, and a Content-Security-Policy that limits where the page can connect.
Built With
- firebase-ai-logic
- firebase-app-check
- firebase-hosting
- gemini
- github-actions
- javascript
- vite
- vitest