-
-
Route by sensitivity: Gemini Nano reads on the device, the cloud Gemini model writes on placeholders.
-
Written in the cloud on placeholders; the real names put back on the device, with a receipt.
-
The leak check: 8 values stay on the device, 415 bytes would leave, no hidden value in the outgoing text.
-
"Keep everything on this device": the same call written by Gemini Nano, no call to the cloud model.
-
Live run: 7 values hidden by the rules, 1 found by Gemini Nano on the device ("Grace").
Inspiration
People paste HR complaints, patient referrals and contracts into AI chat every day. That text carries names, phone numbers, national IDs, IBANs and file references. Companies either ban AI and lose the time it saves, or allow it and leak personal data. Rules-only redaction is not enough either: it misses what does not look like a pattern, such as "Grace from HR" or "Lina from payroll".
We wanted the cloud model's writing quality without handing it the private text. Firebase AI Logic hybrid inference made the split possible in one SDK: the small model on the device reads, the big model in the cloud writes.
What it does
NOAI Hybrid routes AI work by sensitivity, not by capability. Paste a message, a medical note or a contract clause, and pick a task: draft a reply, summarise, or list obligations and deadlines.
- Rules on the device hide structured identifiers and known names: emails, phones, IBANs, cards, Saudi ID and Iqama numbers, dates of birth, companies with a legal suffix, file references, names in English and Arabic.
- Gemini Nano on the device reads what is left and finds the names and organisations the rules missed. Every item it returns must be quoted from the text, or it is ignored.
- A leak gate checks the outgoing text for every hidden value. One hit blocks the send.
- The cloud Gemini model writes the answer on placeholders only, such as
[PERSON_5]and[REF_1]. With "Keep everything on this device" switched on, the same call runs on Gemini Nano. - The real values are put back on the device when the answer arrives.
The owner sees every hidden value as a chip and can click one to send it as is. The screen shows how many values stay on the device, how many bytes leave, the SHA-256 of exactly what was sent, and whether the answer was written in the cloud or on the device.
From the live run on the hosted demo in Chrome (25 Nov 2026), HR complaint sample: 8 private values hidden, 7 by the rules and 1 by Gemini Nano ("Grace", a first name on its own). 784 bytes sent, 0 of the 8 values in them. The reply was written in the cloud by gemini-flash-lite-latest in 1851 ms, and 4 placeholders were put back on the device. With "Keep everything on this device" on, Gemini Nano wrote the reply on the device in 8718 ms.
All names, numbers and companies in the three built-in samples are invented.
How we built it
A static web app (HTML, CSS, JavaScript modules), no backend. The Firebase JS SDK 13.4.0 is loaded from the gstatic CDN with the Gemini Developer API backend (GoogleAIBackend).
- The finder never leaves the device:
getGenerativeModel(ai, { mode: InferenceMode.ONLY_ON_DEVICE, onDeviceParams: { createOptions, promptOptions: { responseConstraint } } }). The response constraint is a JSON schema (items: [{ text, kind }], kind one of PERSON, COMPANY, ADDRESS, REFERENCE), so Gemini Nano returns structured data. Each item is accepted only if it is found word for word in the text. - The writer prefers the cloud:
mode: InferenceMode.PREFER_IN_CLOUD,inCloudParams: { model: 'gemini-flash-lite-latest' }, with on-device params for the fallback. The "Keep everything on this device" switch runs the same writer withONLY_ON_DEVICE.response.inferenceSourceis shown on screen, so the user always knows where the answer was written. - Device status and download:
LanguageModel.availability()drives the status pill, andinitializeDeviceModel()shows download progress the first time Gemini Nano is needed. - App Check is enforced on Firebase AI Logic: reCAPTCHA Enterprise on the hosted demo, a registered debug token on localhost (kept out of the repo).
- Rules: the NOAI redactor (TypeScript, see below), turned into browser JavaScript by a small build step, plus new rules for reference numbers and titles.
- Hosting: GitHub Pages, deployed by a GitHub Actions workflow on every push.
Challenges we ran into
- Streaming against the cloud endpoint failed mid-answer in testing (
AI/parse-failed). Since the whole answer is restored at once anyway, we switched to onegenerateContentcall. - A small model can invent. The quote check means Gemini Nano can only hide text that is really there, never add or change any.
- Over-hiding and under-hiding. A title on its own ("Dr") came out as a person, and file references like HR-2291-K needed a rule of their own; both are handled now. A one-word "address" is a city or a country, which the answer needs, so it is not hidden.
- App Check on a static site: reCAPTCHA Enterprise for the hosted domains, a debug token only on localhost, and the token file kept out of the public repo.
Accomplishments that we're proud of
- The cloud model writes a useful reply to an HR complaint while every name, phone, email, ID and reference in it stays on the device.
- Gemini Nano catches what rules cannot, and cannot invent what is not there.
- A receipt on every answer: bytes sent, SHA-256 of exactly what left, how many hidden values were in it (0), and where the answer was written.
- One switch moves the whole job onto the device.
What we learned
Hybrid is not only about falling back when the network is gone. Routing by what the data is, rather than by how hard the task is, gives privacy and quality at the same time: the small model does the job only it can be trusted with, and the big model does the job it is best at.
What's next for NOAI Hybrid
- Bring the same flow to the places people already paste text, starting with the NOAI browser extension.
- More placeholder-safe tasks (translation, tone rewrite) and more document types.
- Let teams set which kinds of values may be sent as they are.
Pre-existing code and what was built during the contest
Built during the contest period (11 to 30 Nov 2026): the whole web app (public/app.js, index.html, style.css, samples.js), the Gemini Nano finder with a JSON response constraint and quote check, the leak gate, the hybrid writer with the on-device switch and the on-screen inference source, the reference-number and title rules, the build that strips TypeScript types for the browser, App Check, and the hosted deploy.
Pre-existing (disclosed): vendor-src/redact.ts and vendor-src/names.ts are the on-device redactor from NOAI by Silent Key Technologies (first published in SilentKeyTech/noai), written before the contest. One change was made during the contest: words such as "between" and "with" are no longer read as the start of a company name.
Licence: AGPL-3.0.
Built With
- chrome
- firebase
- firebase-ai-logic
- firebase-app-check
- gemini
- gemini-nano
- github
- github-actions
- javascript
- recaptcha-enterprise
- typescript
