Inspiration

Freelancers, founders and small landlords sign NDAs, leases and service agreements every week without a lawyer. The obvious fix is to paste the contract into a chatbot, but that sends every name, salary, bank detail and address in it to a server. The contracts people most need checked are the ones they least want to share.

Hybrid inference splits the work. A small model on the device can find what's private, and a large model in the cloud can do the legal reasoning. The cloud model never needs to know who the parties are to tell you an indemnity clause is one-sided.

What it does

  1. Load a contract. Paste it, or import a PDF or Word file. The file is read in the browser and never uploaded.
  2. Mask it on the device. Gemini Nano reads each clause, finds people and companies, and labels the clause type. Pattern rules catch emails, phone numbers, amounts, dates, account numbers, addresses, web addresses and IDs. Each detected value becomes a placeholder such as [PARTY_A] or [AMOUNT_1]. Recognized aliases reuse the same placeholder, including supported short forms like "Northwind" for "Northwind Analytics, Inc.". Masking can miss values; reviewing the preview is essential.
  3. Check before sending. A leak check scans the masked text again and blocks the send if any known value or pattern match is still there. You see the exact text that will leave the device. You can mask anything else by hand, then approve.
  4. Analyze in the cloud. Gemini returns a risk level, a plain-English explanation and questions to ask the other side for each clause, plus a suggested rewrite when one can be grounded in the clause's own text. Every answer has a fixed JSON shape that is checked before it's shown.
  5. Restore on the device. The real names come back from an encrypted local vault, and each clause card shows whether it ran in the cloud or on the device.
  6. Ask questions on the web. Chat about the contract. Each question is masked on the device the same way, shown to you, and sent only after you approve it. The answer comes back with the names restored.
  7. Delete it. One button removes the document and its saved values. Saved vaults become unreadable 24 hours after their last save; expired records are purged when the app next starts, rather than by a background deletion timer.

How we built it

The web AI flow uses Firebase AI Logic. Each job uses the inference mode that fits what it's allowed to see. On iOS, raw-text masking calls Apple Foundation Models directly and stays local; native masked analysis uses Firebase AI Logic. The table describes the web flow:

Job Mode Why
Find names and classify clauses ONLY_ON_DEVICE It sees the raw contract, so it can never fall back to the cloud
Clause analysis PREFER_IN_CLOUD The text is already masked. Online it gets Gemini's reasoning, and offline it falls back to Gemini Nano
Chat answers ONLY_IN_CLOUD Only an approved, masked question is sent
  • Structured output: web on-device reads use a responseConstraint, and web cloud analysis uses a response schema. The iOS masking path uses Apple's generation schema; its Firebase analysis path requests JSON with schema instructions. Shared validators reject responses that fail the expected structure.
  • App Check is enforced for Firebase AI Logic. The hosted web app is registered with reCAPTCHA Enterprise; development builds require registered debug tokens. Native production attestation remains unregistered, so native release/cloud readiness is not claimed.
  • Remote Config supplies validated web analysis prompts and kill switches, with local defaults and caching. The cloud model is restricted to the verified no-billing model; it cannot be freely changed remotely. Native analysis uses shared local defaults.
  • Firebase Hosting serves the web app.
  • Privacy engine (TypeScript, shared by web and mobile): pattern rules plus the model's reading, a leak check that fails closed, and an approval guard that only accepts the untouched, current result of a masking run. A copied, edited or outdated preview can't be sent. Replacement values are AES-GCM encrypted in IndexedDB. The web key is non-extractable; native vault-key material is protected by the Android Keystore or iOS Keychain, rather than storing the replacement values themselves there.
  • Web: React and Vite. PDF import uses pdf.js and Word import uses mammoth, both in the browser.
  • Mobile: Capacitor wraps the same React app. A Kotlin plugin uses Firebase AI Logic with Gemini Nano on Android. The Swift plugin masks raw text locally with Apple Foundation Models directly and uses Firebase AI Logic for masked analysis. Phones can also scan a paper contract with the camera and read it on the device. The mobile apps are development builds, not published in a store; the hosted web app also works in a phone's browser. Physical iPhone evidence covers local masking and scanning, not native cloud/chat release acceptance. Native chat is not enabled in the current app entry point. Camera-image cleanup was implemented, but physical deletion after the fix remains unverified.

Challenges we ran into

  • A small model misses things. Nano misses names, and sometimes reports role words like "the Company" as names. We run the broad pattern pass alongside the model, not only when it's missing. If the model finds a name the rules can't confirm, the user is asked to review.
  • Over-masking breaks the analysis. Masking "Tenant", "Oregon" or a section heading hides exactly what the cloud needs. We built an answer key for six sample contracts, with 70 values that must be hidden and 35 terms that must stay readable, and tuned against both lists.
  • Consistency matters. If "Halcyon" could mean the company or its product, picking one silently would give a wrong answer. Ambiguous short forms are refused and the user is asked for the full name.
  • Phones differ from Chrome. The iOS masking path supports Apple's generation schema, while its Firebase analysis path uses JSON/schema instructions plus shared validation. A model read can hang; failed local reads produce patterns-only masking with a review warning.

Accomplishments that we're proud of

On six sample contracts (an NDA, a freelance agreement, a lease, an offer letter, a SaaS agreement and a promissory note):

  • Gemini Nano in Chrome: 70 of 70 sensitive values masked, 35 of 35 needed terms kept, and 59 of 60 clause types right.
  • Cloud analysis on main: 60 of 60 clauses came back valid, with every name restored.
  • Leak check: each of the 70 real values was planted back into the masked text, and the send was blocked 70 times out of 70.
  • Simulated failure cases on these fixtures: with the model missing, crashing, answering in prose, or finding no names, every required fixture value was still masked. These are bounded tests, not a guarantee for arbitrary contracts.
  • Imports: all 12 PDF and Word versions of the samples split into the same clauses as the pasted text.
  • Tests: 797 automated tests cover the privacy engine, the approval guard, chat, the web app and the native bridges.

What we learned

  • The privacy boundary has to be enforced in code, not left to prompts. An approval object that can't be forged did more for safety than any instruction to a model.
  • Gemini Nano is good at reading and bad at being the only line of defense. Pairing it with deterministic rules gave us both recall and precision.
  • Choosing the inference mode per job, rather than one mode for the whole app, is what makes hybrid inference trustworthy here.

What's next

  • A Chrome extension side panel that reviews a contract on the page you're reading.
  • Completing physical Android Nano testing and native release/cloud/chat acceptance. Reconcile the existing bounded iPhone masking results with future release builds.
  • More contract types, and redlines exported back into the original Word file.

Built With

  • apple-foundation-models
  • capacitor
  • firebase
  • firebase-ai-logic
  • firebase-app-check
  • firebase-hosting
  • firebase-remote-config
  • gemini
  • gemini-nano
  • indexeddb
  • kotlin
  • mammoth
  • pdf.js
  • react
  • swift
  • typescript
  • vite
Share this project:

Updates

Submission history