Inspiration
Contracts, NDAs, and vendor invoices are packed with sensitive personal and financial details—names, direct emails, phone numbers, tax/EIN/VAT IDs, bank account numbers, routing numbers, IBANs, and SWIFT/BIC codes—right alongside clauses where subtle traps hide, such as aggressive payment windows, compounding late fees, one-sided liability, or lopsided dispute terms.
Manually stripping out sensitive data before asking an AI for help is slow and easy to get wrong, while pasting raw documents directly into a cloud model exposes confidential information unnecessarily. SafeClause was built for #BuildHybridAI 2026 around a straightforward privacy rule: keep raw PII on-device, and send only scrubbed text to the cloud for heavy reasoning.
What it does
SafeClause is a privacy-first contract, NDA, and vendor invoice auditor that splits work across a two-stage hybrid pipeline:
Stage 1 — Local PII Scrubbing & Quick Triage (On-Device): Runs locally in the browser using Chrome's Gemini Nano (ONLY_ON_DEVICE), paired with a deterministic regex safety net, substring hallucination guard, longest-match-first numbered placeholders ([NAME_1], [EMAIL_1], etc.), token count chips, UTF-8 byte telemetry, and a 2-bullet local triage summary—working even offline.
Stage 2 — Deep Risk Audit & Counter-Offers (Cloud): Sends only the anonymized text to Gemini (gemini-2.5-flash via Firebase AI Logic with PREFER_IN_CLOUD, structured JSON schema output, and App Check protection) to compute a risk score, flag high-risk clauses with copyable counter-offers, highlight payment traps, and surface missing protections.
How we built it
Frontend & Styling: Built with React, TypeScript, Vite, and Tailwind CSS v3 (Inter and JetBrains Mono on a dark slate UI) featuring a telemetry bar, interactive scenario strip/presets, and a 3-step workspace (Raw Input, Local Scrubbed Output, Cloud Risk Audit).
Hybrid AI Layer: Integrated Chrome's on-device LanguageModel / Gemini Nano availability and download flow (ONLY_ON_DEVICE) alongside Firebase (firebase/app, firebase/app-check with reCAPTCHA Enterprise, and firebase/ai GoogleAIBackend with PREFER_IN_CLOUD).
Defense-in-Depth Redaction: Combined model-driven entity extraction with a deterministic regex safety net covering emails, phone numbers, IBANs, SWIFT/BIC codes, account/routing/sort codes, and tax/ID patterns.
AI-Assisted Workflow: Developed locally on Windows using Google Antigravity for rapid scaffolding, UI iteration, and documentation.
Challenges we ran into
Strict TypeScript Compiler Rules: Enforcing verbatimModuleSyntax: true, erasableSyntaxOnly: true, noUnusedLocals: true, and noUnusedParameters: true meant catching missing import type statements and disallowed syntax patterns across generated and edited files.
Local Dev Environment & Package Resolution: Navigating Windows dev server process locks (PID 10116), verifying that firebase (firebase/app, firebase/app-check, firebase/ai) was cleanly installed into node_modules before Vite pre-bundled imports, and restarting Vite after installation.
Balancing Visual Polish With Demo Clarity: Designing an attractive, colorful UI and interactive scenario strip without obscuring the live redaction and risk-audit workflow that judges need to see immediately.
Environment & Provisioning Setup: Wiring .env variables, Chrome 139+ prompt API flags/model downloads, and Firebase AI Logic + App Check debug tokens cleanly without blocking offline Stage 1 testing.
Accomplishments that we're proud of
True Zero-PII Cloud Boundary: Building a workflow where raw sensitive text stays in Stage 1 and only tokenized, scrubbed text flows into Stage 2—backed by visible byte counters, inference source indicators, and a live event log.
Resilient Hybrid + Fallback Architecture: Combining Gemini Nano with a regex safety net and clear offline/unconfigured states so local scrubbing still works reliably even before Firebase keys or on-device models are active.
Actionable Risk & Negotiation Output: Going beyond vague summaries to produce structured risk scores, severity badges, payment trap callouts, missing protections, and ready-to-paste counter-offers.
What we learned
Deterministic Guardrails Matter Alongside LLMs: Pairing on-device LLM redaction with deterministic regex rules and strict token replacement makes privacy behavior much more predictable and verifiable.
Strict Compiler Settings Pay Off Early: Catching type-only imports and unused symbols early via tsc -b / npm run build prevents subtle runtime or bundler surprises later.
Clear State Feedback Builds Trust: In a privacy and security tool, showing exact byte counts, ON-DEVICE vs. IN CLOUD execution states, and honest setup/offline banners is essential for user confidence.
What's next for Safeclause
End-to-End Live Cloud & Nano Verification: Complete Firebase AI Logic and App Check debug token setup on a live project, test full Stage 2 audits across contracts, NDAs, and invoices, and benchmark on-device Gemini Nano scrubbing in Chrome 139+.
Expanded Clause & Document Coverage: Add more sample templates, custom redaction rules/allowlists for domain-specific terms, and side-by-side diffing between original clauses and suggested counter-offers.
Exportable Audit Reports: Allow users to export a clean, privacy-safe risk and counter-offer summary (keeping raw PII excluded) for team review or negotiation prep.
Built With
- app-check
- buildhybridai
- chrome-ai
- contract-auditor
- counter-offers
- data-privacy
- firebase
- firebase-ai-logic
- gemini-2-5-flash
- gemini-nano
- hybrid-ai
- invoice-audit
- legal-tech
- nda-review
- on-device-ai
- pii-redaction
- privacy-first
- prompt-api
- react
- risk-analysis
- tailwindcss
- typescript
- vite
- zero-pii