Inspiration
In-house legal counsel, startup founders, and procurement teams review confidential NDAs, Master Services Agreements (MSAs), Data Processing Addendums (DPAs), and offer letters across both desktop workstations and mobile devices every single day. Yet enterprise compliance policies strictly block pasting unredacted contracts into cloud-only AI assistants because doing so exposes counterparty identities, deal valuations, bank IBANs, tax IDs, and proprietary project codenames to external servers.
ClauseVault AI Firewall was inspired by a clear thesis: hybrid AI makes confidential legal review safe, verifiable, and continuous across both Web and Android platforms. By keeping sensitive entity detection, reversible tokenization, and first-pass risk triage 100% local on-device via Gemini Nano—and escalating only scrubbed, placeholder-tokenized clauses to Cloud Gemini for deep playbook redlining—teams get frontier-grade legal intelligence on Chrome Web and Android without leaking a single byte of private data.
What it does
ClauseVault AI Firewall is a zero-trust, cross-platform (Chrome Web + Android APK/PWA) contract review and redlining workspace powered by Firebase AI Logic:
- Cross-Platform Web & Android Architecture: Built as a responsive, installable Progressive Web App (PWA) on Firebase Hosting (
https://web.app) and packaged as a native-installable Android APK (ClauseVault.apkvia Trusted Web Activity), allowing legal teams to review contracts on desktop Chrome and sync anonymized audit ledgers and playbooks seamlessly to Android in real time. - Stage 1 — On-Device Privacy Firewall & Instant Triage (
PREFER_ON_DEVICE/ONLY_ON_DEVICE): Paste or upload an NDA, MSA, DPA, or offer letter on Web or Android. Before any network call occurs, a 4-layer local sanitization engine (combining deterministic regex rules, parenthetical defined-party extraction, chunked Gemini Nano NER, and a pre-flight leak verification gate) replaces organizations, people, addresses, IBANs, tax IDs, financial figures, and secret codenames with reversible local tokens ([ORG_1],[PERSON_1],[FEE_1],[ID_1],[SECRET_1]). Even in Air-Gapped Local Mode or completely offline on mobile, ClauseVault delivers immediate local risk triage and offline PDF export. - Interactive Side-by-Side Diff & Firewall Approval Gate: Users inspect an Original Vault vs. Sanitized Cloud Payload diff view, toggle individual entity masks on or off, or add custom terms to a local blocklist before explicitly approving cloud escalation.
- Stage 2 — Playbook-Aligned Cloud Redlining (
ONLY_IN_CLOUD): Once approved online, ClauseVault transmits only the sanitized, placeholder-tokenized contract plus the user's Company Legal Playbook (governing law, liability caps, payment terms, IP stance, and auto-renewal rules) to Cloud Gemini via Firebase AI Logic to generate clause-by-clause severity ratings (Critical,Moderate,Acceptable), deviation rationales, and ready-to-paste redline counter-proposals. - Local Token Re-Hydration & Clean Export: When the user accepts suggested redlines and exports the finalized contract, the client merges cloud counter-proposals with the local-only entity dictionary (
Map<Token, OriginalValue>) in memory—restoring real party names locally without Cloud Gemini or Firestore ever seeing unredacted data. - Cross-Device Synced Audit Ledger & Custom Playbooks: Anonymized audit histories and customizable company playbooks sync across Chrome Web and Android via Cloud Firestore (with IndexedDB
persistentLocalCache), secured by Firebase Authentication and Firebase App Check.
How we built it
We architected ClauseVault AI Firewall as a unified Web + Android Progressive Web App & Trusted Web Activity (TWA) backed by Firebase's hybrid AI and security stack:
- Hybrid AI Orchestration (
firebase/ai): Built a modular TypeScript router (hybridRouter.ts+privacyFirewall.ts) using Firebase AI Logic (GoogleAIBackend). Local entity extraction and offline triage run viaInferenceMode.PREFER_ON_DEVICEandInferenceMode.ONLY_ON_DEVICE(Chrome built-in Gemini Nano + deterministic local rules), while deep legal redlining executes viaInferenceMode.ONLY_IN_CLOUD. - Zero-Leak Client Dictionary: Maintained the reversible
Map<Token, OriginalValue>dictionary strictly in client memory and local IndexedDB—enforcing a pre-flight leak verification gate that blocks cloud transmission if unmasked emails, currency figures, or corporate suffixes remain. - Cross-Platform Web & Android Delivery: Engineered with React 19, TypeScript, Vite, and Tailwind CSS with mobile-first responsive layouts, Web App Manifest (
manifest.json), and Service Worker (sw.js), deployed live on Firebase Hosting (https://web.app) and packaged into an installable Android.apk(https://github.com). - Cross-Platform Cloud Sync & Attestation: Secured user-scoped contract audits (
users/{uid}/audits) and legal playbooks across Web and Android in Cloud Firestore with offline persistence, Firebase Authentication (Google Sign-In), and Firebase App Check (reCAPTCHA Enterprise + debug attestation).
Challenges we faced
- Overcoming Small Local Model Context & Formatting Limits: Running Gemini Nano on multi-page contracts initially missed line-wrapped company names, underscore-padded signature blocks (
_____Name_____), and international addresses. We solved this by building a 4-layer defense-in-depth pipeline pairing deterministic regexes and parenthetical alias extraction with paragraph-chunked Gemini Nano NER and a legal-heading allowlist. - Delivering Seamless Cross-Platform Web + Android Continuity: Ensuring that a single codebase works identically on desktop Chrome (with hardware Gemini Nano) and Android devices (where on-device Nano may not yet be provisioned) required graceful runtime capability detection and automatic fallback to our local deterministic scrubber plus Firestore
persistentLocalCachesync. - Preventing False-Positive Over-Masking: Adding a curated legal-terminology allowlist and interactive click-to-unmask token pills gave users full precision control before cloud escalation.
What we learned
- Hybrid AI delivers its highest real-world ROI at trust boundaries—where local models act as fast, zero-cost privacy firewalls and cloud models act as deep domain reasoners operating exclusively on anonymized tokens.
- Pairing Firebase AI Logic with a PWA + Android APK architecture lets developers ship verifiable, zero-leak privacy workflows across desktop and mobile from a single TypeScript codebase.
- Combining deterministic rules with Gemini Nano keeps on-device execution fast, predictable, and cross-platform compatible even on devices without hardware LLM weights downloaded.
What's next for ClauseVault AI Firewall
- Native
.docxTrack-Changes & Mobile Share-Sheet Integration: Allowing Android users to share PDF/DOCX contracts directly from Gmail or WhatsApp into ClauseVault via Android's native Share Sheet, and exporting accepted redlines as.docxfiles with tracked changes. - Multi-Contract Playbook Presets & Policy Ingestion: Expanding one-click playbooks across NDAs, SaaS MSAs, DPAs, and Employment Agreements, plus local extraction of playbook rules from internal policy PDFs.
- Biometric / WebAuthn Vault Protection: Adding fingerprint/passkey encryption on Android and Chrome for local IndexedDB token dictionaries.