Inspiration
What it does
How we built it
Challenges we ran into
Accomplishments that we're proud of
What we learned
What's next for RedactFirst
Inspiration
Every day support agents, clinicians, HR and finance teams paste customer messages into AI assistants: "summarise this ticket", "draft a reply to this patient". Those messages are full of names, account numbers, card numbers and health details, exactly the data that should not leave the company. The usual answer is "don't use AI" or "trust the vendor". Hybrid inference allows a third answer: let a small model on the device guard the data, and let a large cloud model do the thinking on text that no longer identifies anyone.
What it does
RedactFirst is a web app for Chrome with a three-step pipeline:
- Redact on the device. Gemini Nano (Firebase AI Logic,
ONLY_ON_DEVICE, JSON response schema) finds people, organisations and addresses. A local rule engine with checksums (Luhn, IBAN mod-97) adds emails, phones, cards, IBANs, SSNs, account / patient / invoice IDs, birth dates and API keys. Values get stable placeholders ([PERSON_1]everywhere the same person appears, including first-name-only mentions). Users can un-redact a value with a click or redact anything missed by selecting it. - See exactly what leaves. A side-by-side panel shows your text (never sent) next to the exact payload. A leak guard re-scans the payload and blocks the cloud call if any original value or structured identifier is still in it.
- Reason, then re-hydrate locally. Light tasks (triage, summary) run with
PREFER_ON_DEVICE: on Gemini Nano when present, on cloud Gemini otherwise, always on redacted text. Heavy tasks (reply draft, action items) run withONLY_IN_CLOUD. The answer comes back with placeholders and the browser puts the real names and numbers back, highlighted. A second tab shows what the model saw and returned.
A privacy ledger lists every model call with ON-DEVICE / CLOUD (from the SDK's inferenceSource),
latency and how many characters were sent. History is saved to Firestore, redacted only; the
placeholder map never leaves the tab's memory.
If Gemini Nano is not available, the app says so, explains how to enable it in Chrome, keeps detection on the local rule engine (raw text still never leaves) and lets light tasks fall back to the cloud on redacted text. It works in every browser without weakening the privacy promise.
How we built it
- Firebase AI Logic hybrid inference (Firebase JS SDK 13.4, Gemini Developer API):
- detector:
getGenerativeModel(ai, { mode: InferenceMode.ONLY_ON_DEVICE, onDeviceParams: { createOptions, promptOptions: { responseConstraint: entitySchema } } }) - light tasks:
InferenceMode.PREFER_ON_DEVICEwithinCloudParamsfor the fallback model - heavy tasks:
InferenceMode.ONLY_IN_CLOUDwith a configurable thinking level initializeDeviceModel()is called on the user's click (Chrome needs user activation);response.inferenceSourcedrives the badges and the ledger, and the detector refuses to continue if it ever reports a cloud source.
- detector:
- App Check with the reCAPTCHA / Google Cloud Fraud Defense provider (enforced for AI Logic), debug provider on localhost.
- Anonymous Authentication scopes history per user.
- Cloud Firestore stores redacted inputs and outputs only; security rules restrict each user to
users/{uid}/history, allow-list the fields, cap sizes and require a server timestamp. - Remote Config holds the cloud model, fallback model, thinking level, the on-device detection prompt, task prompts and the task routing table (which task uses which inference mode), so we can re-route without a redeploy.
- A pure-JS redaction engine (detectors, overlap resolution, alias expansion, re-hydration tolerant
to
[ PERSON 1 ]/person-1drift, leak guard) with 30 unit tests (node --test). - Vite build, deployed to GitHub Pages by GitHub Actions (tests run before every deploy).
Challenges we ran into
- Small models return text, not offsets. Gemini Nano reports entity strings; we locate them ourselves with word boundaries and drop anything that is not in the text, so a hallucinated entity can never cause a wrong replacement.
- Keeping the hybrid promise honest.
PREFER_ON_DEVICEsilently falls back to the cloud, which is great for light tasks but wrong for raw text. Detection therefore usesONLY_ON_DEVICEwith a deterministic local fallback instead of a cloud one. - Busy cloud models. During testing
gemini-3.8-flashanswered "high demand" or took 40 s. We added a hard 30 s timeout with a retry on a lighter model and switched the live cloud model togemini-3.5-flash-litethrough Remote Config, without shipping new code. - Placeholders through a model. Models reformat tokens; re-hydration accepts small variations and leaves unknown placeholders untouched.
Accomplishments that we're proud of
- A clear, verifiable privacy story: the "what leaves your device" panel shows the exact bytes, and the leak guard blocks the call if anything identifying slips through.
- All three inference modes of one SDK used for what each is good at, with per-call evidence of where inference ran.
- It degrades gracefully: full experience with Nano, still private and useful without it.
What we learned
On-device and cloud models are not competitors. The small local model is an excellent privacy filter and fast for light tasks; the cloud model is better at long, careful writing. Hybrid inference makes it possible to combine them per step, not per app.
What's next
- Chrome extension mode: redact before pasting into any web chatbot or helpdesk.
- Custom entity dictionaries (product codes, internal project names) synced through Remote Config.
- Image input (scanned invoices) with on-device multimodal Nano.
- Android and iOS clients with the same pipeline through Firebase AI Logic hybrid inference.
What was built during the submission period
Everything: the app, redaction engine, tests, Firebase project (AI Logic, App Check, Auth, Firestore, Remote Config), deployment and video were created on 27-28 November 2026 for #BuildHybridAI. No pre-existing project code was used. Third-party code: Firebase JS SDK and Vite (open source).
AI assistance disclosure
The code and docs were written with the help of an AI coding assistant (Claude Code, Anthropic), directed and reviewed by the team. The demo video voice-over is a synthetic neural TTS voice. The app itself uses only Gemini models through Firebase AI Logic.
Testing instructions
- Open https://quietstack-labs.github.io/redactfirst/ in Chrome desktop 139+. No login needed (anonymous auth happens automatically).
- For on-device inference enable
chrome://flags/#prompt-api-for-gemini-nano-multimodal-input, relaunch, then press Download Gemini Nano (or just run once; first download takes minutes). Without Nano the app still works with the local rule engine and cloud fallback. - Click a sample (e.g. Clinic note) → Redact on this device → check the highlights and the "What leaves your device" panel → click Triage (Nano / hybrid) and Draft reply (cloud). Switch to "What the model saw & returned" to see the placeholders. All sample data is fictional.
- Code:
npm install && npm test(30 tests).
Links
- Live demo: https://quietstack-labs.github.io/redactfirst/
- Code (Apache-2.0): https://github.com/quietstack-labs/redactfirst
- Video: https://youtu.be/DBJ6S_gL8r8
Built With
- chrome-prompt-api
- cloud-firestore
- firebase-ai-logic
- firebase-app-check
- firebase-authentication
- firebase-remote-config
- gemini
- gemini-nano
- github
- javascript
- recaptcha
- vite