-
-
Airlock: Gemini Nano seals identities on device; Gemini in the cloud works on placeholders
-
Review: every identifier found on device, and the exact sealed payload that will leave
-
Unsealed answer (left) vs what the cloud wrote on placeholders (right): in_cloud
-
Simulated outage: Firebase AI Logic falls back to Gemini Nano on the same sealed payload
-
Privacy receipts in Firestore: sealed payload, SHA-256, and which model answered
Inspiration
Clinics, support desks, HR teams and ordinary people with a landlord problem all paste messages full of names, phone numbers, addresses and ID numbers into cloud AI, because that is where the good models are. The usual answer is "don't", or a policy promise. We wanted privacy enforced by where the code runs.
What it does
Airlock splits every request across a device boundary:
- Seal (on device). Deterministic rules catch structured identifiers (emails, phones, Luhn-checked cards, IBANs, SSNs, IDs, dates, street addresses). Then Gemini Nano via Firebase AI Logic in
ONLY_ON_DEVICEmode reads the rule-masked text and returns people, organizations and places as compact structured JSON. Name parts are linked ("Maria" gets the same placeholder as "Maria Delgado"), and Nano takes a second look at the redacted text. - Review (on device). You see the exact bytes that will leave, with a byte count, a SHA-256 hash and a local pre-flight scan. Click any highlight to let it through, or add your own.
- Think (cloud). The sealed payload goes to Gemini in the cloud via Firebase AI Logic in
PREFER_IN_CLOUDmode, behind App Check. The cloud drafts the reply, summary or action items on placeholders. - Unseal (on device). Placeholders are swapped back for real values from a vault that only ever exists in the tab's memory.
If the cloud is unreachable, Firebase AI Logic falls back to Gemini Nano automatically. Because the payload is already sealed, the fallback is equally private; the UI shows inferenceSource and has a Simulate cloud outage switch to prove it. A Keep it all on device button answers entirely with Nano and sends zero bytes.
Every cloud request leaves a privacy receipt in Firestore: the sealed payload, its hash and which model answered.
How we built it
- Firebase AI Logic (Gemini Developer API): three models from one SDK.
- An
ONLY_ON_DEVICEextractor with an on-deviceresponseConstraintJSON schema. - An
ONLY_ON_DEVICEwriter for local-only answers. - A
PREFER_IN_CLOUDwriter with a system instruction that preserves placeholders. - Also uses
initializeDeviceModel(behind a user gesture), streaming andinferenceSource.
- An
- App Check with reCAPTCHA Enterprise, enforced for AI Logic.
- Anonymous Auth, so every browser gets a private identity without a sign-up.
- Firestore for receipts. Security rules restrict reads and deletes to the owner and validate the schema, so even a modified client cannot store original text or the vault.
- Remote Config for the cloud model, the second-look pass and default entity types.
- Hosting with strict headers. No third-party fonts or scripts.
- React + TypeScript + Vite, with unit tests for detectors, span resolution, name linking and re-identification.
Challenges we ran into
- Speed of on-device structured output. Our first schema (an array of
{text, type}objects over the raw text) took 35–50 s on Nano, because output tokens dominate. Two changes cut the scan to about 5 s and made the whole seal take about 9 s:- masking rule-detected identifiers before Nano sees the text;
- asking for three flat string lists.
- Hallucinated or mis-typed spans. Every model string must occur verbatim in the text or it is dropped. A name the model files under "places" is re-typed as a person when it matches a known name.
- Placeholder mangling. Re-identification tolerates
[Person 1]/[ PERSON_1 ]and flags placeholders the model invented. - Cloud capacity. A larger cloud model returned "high demand" errors during testing. Remote Config lets us switch models without a redeploy, and the hybrid fallback keeps the app working meanwhile.
Accomplishments we're proud of
- One SDK, both execution modes, one coherent privacy story. The small model is trusted with raw data but does one narrow job. The large model does the hard reasoning but never sees identities.
- Every step is visible and verifiable: the outgoing bytes, the hash, the receipts, and which model answered.
What we learned
Hybrid inference is most useful when each model is given the job that matches its trust level, not just its size or speed.
What's next
- An Android build with Gemini Nano via Firebase AI Logic, sharing the same redaction core.
- Attachments: images of letters or forms, with redaction applied on device.
- Org policies through Remote Config (for example, always hide medication names).
- A Chrome extension that seals text in any web form before it is sent.
Built With
- chrome-prompt-api
- cloud-firestore
- firebase-ai-logic
- firebase-app-check
- firebase-authentication
- firebase-hosting
- firebase-remote-config
- gemini
- gemini-nano
- react
- typescript
- vite