Demo video (2:55): https://youtu.be/xU4oUomnDtM · Try it: https://clauseguard-hybrid-1c5e2.web.app/#walk

Inspiration

Leases, medical bills and contracts are full of names, IBANs, patient IDs and prices, and the usual advice is to paste them into a cloud chatbot. That leaks the data before anyone has decided it is fine. Hybrid inference looked like the right tool: let the private part run on the device, and let the cloud see only what a human has approved.

What it does

ClauseGuard is a four-step privacy airlock in Chrome. Import a PDF, Word or text file (parsed locally). Review the sensitive items it finds (names, IBANs, emails, IDs, amounts) and accept, reject or add your own. Approve the exact cleaned text that would leave the device; the approval is bound to its SHA-256 and goes stale if anything changes. Results: a cloud Gemini model flags risky clauses (for example an unreasonable deposit rule or hidden fee) using placeholders only, and the real names are put back locally in your browser. If you prefer, Check on this device only keeps everything local, even offline. Two aids make this easy to check. A "Left this device" note in the side panel counts requests to cloud AI from the browser's own Resource Timing record and shows a short fingerprint of the approved text. A "Walk through a sample lease" card on the Start screen gives one hint per step.

How I built it (Firebase AI Logic)

Firebase AI Logic's hybrid inference is the core, not an add-on. The same firebase/ai SDK is used in two explicit modes:

  • InferenceMode.ONLY_ON_DEVICE for anything touching raw text: entity extraction and local clause triage with Chrome's on-device Gemma. I deliberately avoid PREFER_ON_DEVICE, because its silent cloud fallback would break the privacy promise. If the model is missing it fails closed to deterministic local detection, labelled DEGRADED_DETERMINISTIC_SAFE.
  • InferenceMode.ONLY_IN_CLOUD for cross-clause reasoning, only on the human-approved redacted payload, with Firebase App Check (reCAPTCHA Enterprise; debug token on localhost only). initializeAppCheck runs before getAI.
  • After every call the app checks response.inferenceSource (on_device or in_cloud) and rejects a mismatch, and shows the observed source in the UI.
  • Firebase Remote Config tunes the model name, playbook and output-token limit, but the client rejects any remote value that would weaken approval, the leak preflight or App Check.

Around that: TypeScript and Vite, pdf.js and JSZip for local parsing, deterministic detectors plus a document-scoped entity graph, a SHA-256 approval state machine, a ZeroCanaryPreflight leak scan, Vitest for unit tests, and Playwright with the Chrome DevTools Protocol to record every network request in browser-level tests. Code paths are listed in the README.

Challenges I ran into

  • Chrome's on-device model is a moving target: on Chrome 156 the component updater failed on a 32-bit size overflow for the ~2.3 GiB Gemma component, so I wrote a verified fallback installer; on Chrome 158 availability varied with profile state before the live run passed. I report readiness honestly in the UI instead of faking it.
  • Making "nothing leaves" provable, not just stated: I log every request with CDP and plant canary strings to check they never appear in a cloud body, URL or console.
  • Keeping redaction lossless while names overlap (I index longest surface first; 42/42 synthetic documents round-trip exactly).
  • Turning a privacy-engineer's flow into something a tenant or patient can follow in four steps.

Accomplishments that I'm proud of

All from files in evidence/:

  • Browser privacy suite: 11 scenarios pass, 0 unexpected external requests, 0 raw canary strings in cloud request bodies. (Cloud endpoint was a local mock in that run.)
  • Live on-device run on Chrome 158: Gemma available, two samples processed, 0 external requests in all phases, and an offline run (navigator.onLine=false) completed using the on-device model.
  • One real cloud Gemini call is recorded (2026-11-27): gemini-3.5-flash-lite, HTTP 200, App Check ATTESTATION_VERIFIED, no raw hidden values in the request body. It ran on localhost with an App Check debug token, on one sample.
  • Approval is byte-exact: sent SHA-256 equals approved SHA-256, and a post-approval edit blocks the cloud call.
  • Detector benchmark on my own 42-document synthetic corpus: precision 0.991, recall 0.872 (be aware: synthetic, self-made data; recall is not perfect, which is why a human reviews).

What I learned

  • ONLY_ON_DEVICE plus ONLY_IN_CLOUD with a human gate gives a stronger privacy story than PREFER_ON_DEVICE, because the user can see the line between the two.
  • Checking inferenceSource on every response turns "I think it ran locally" into something testable.
  • On-device models add value on top of deterministic rules, but in my live run they added one entity on one of two samples. I would rather say so than oversell it.
  • Hosting and browser-flag realities (HTTPS contexts, App Check domains, model download time) shape the demo as much as the code.

What's next

  • Run and record a live end-to-end cloud call against the production Firebase project and publish that evidence.
  • Benchmark Gemma's own extraction quality (the current benchmark measures only the deterministic detector).
  • OCR for scanned documents, more document types, and a Chrome-extension version for use inside web mail and DMS tools.
  • User testing with real tenants, patients and small legal teams. None has happened yet.
  • External security review of the browser vault.

For judges: how ClauseGuard meets each criterion

Technological Implementation

The same firebase/ai SDK runs both modes. ONLY_ON_DEVICE handles raw text. ONLY_IN_CLOUD handles only the approved, redacted text, after App Check is initialised. Every response is checked for inferenceSource, and a mismatch is rejected. The side panel also shows a "Left this device" note. It counts cloud requests from the browser's own Resource Timing record, not from app bookkeeping. One real cloud Gemini call is recorded (HTTP 200, App Check ATTESTATION_VERIFIED, no raw hidden values in the request body).

Check it: firebaseClient.ts, nanoAdapter.ts, approvalMachine.ts, live run JSON, egress.ts.

Design

The product is a calm four-step flow: Import, Review, Approve, Results. A "Walk through a sample lease" card gives one short hint per step. A plain-language guide explains each step, and a privacy report can be saved as a PDF. If the on-device model is missing, the app says so and uses built-in rules.

Check it: start the walk, guide.html, reportPdf.ts.

Potential Impact

People are told to paste leases, medical bills and contracts into chatbots. Tenants, patients and small businesses are the audience. The tool lets them get a first-pass risk check without sending names, IBANs or IDs. Five made-up samples cover these cases. No real users have tried it yet, and I make no usage claim.

Check it: samples.ts, README section 9 (limitations).

Quality of the Idea

Hybrid inference is used as a privacy boundary. The person approves the exact bytes that leave the device, bound to a SHA-256 that goes stale if anything changes. The cloud sees placeholders only, and the real names are put back locally in the browser. The "Left this device" note lets anyone see the line between the two modes.

Check it: approvalMachine.ts, egress test.

Built With

  • chrome-prompt-api
  • firebase
  • firebase-ai-logic
  • firebase-app-check
  • firebase-hosting
  • firebase-remote-config
  • gemini
  • gemini-nano
  • jszip
  • pdf.js
  • playwright
  • typescript
  • vite
  • vitest
Share this project:

Updates

Submission history