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
Share this project:

Updates

posted an update —

SafeClause Build Log — From Scaffold to Zero-PII Hybrid AuditorSafeClause has come a long way from an empty Vite starter screen to a working hybrid AI contract, NDA, and vendor invoice auditor built for #BuildHybridAI 2026.What's New & How It Has EvolvedHybrid Two-Stage AI Pipeline: Stage 1 runs on-device in Chrome with Gemini Nano (ONLY_ON_DEVICE) to scrub sensitive personal and financial details locally and generate a fast 2-bullet triage summary; Stage 2 sends only the anonymized text to cloud Gemini (gemini-2.5-flash via Firebase AI Logic with PREFER_IN_CLOUD and structured JSON schema output) to score risk, flag traps, and draft counter-offers.Defense-in-Depth Redaction Engine: Combines entity extraction with a substring hallucination guard, longest-match-first numbered placeholders ([NAME_1], [EMAIL_1], etc.), and a deterministic regex safety net covering emails, phone numbers, IBANs, SWIFT/BIC codes, account/routing/sort codes, and tax/EIN/VAT IDs.3-Step Workspace + Live Telemetry: Built a React, TypeScript, and Tailwind CSS v3 dark-slate UI featuring a top telemetry bar (Online/Offline, Gemini Nano status/download, active execution state, UTF-8 byte counters, and an event log) alongside raw input presets, redacted output/triage, and cloud risk audit cards. Visual & Demo Polish: Upgraded the UI with a vibrant gradient hero/scenario strip and clearer stage badges so judges can test fictional freelance contracts and vendor invoices right away.Build & Git Hardening: Resolved early Windows Vite lock conflicts, installed firebase (app, app-check, ai), and verified strict TypeScript settings (verbatimModuleSyntax: true, erasableSyntaxOnly: true, noUnusedLocals: true, noUnusedParameters: true) while packaging clean source uploads for GitHub.Snippet: Longest-Match-First Redaction & Safety NetTypeScriptexport function scrubDocumentLocally(rawText: string, nanoEntities: string[]) { const uniqueEntities = [...new Set(nanoEntities.filter(Boolean))].sort( (a, b) => b.length - a.length ); const redactionMap = new Map(); let workingText = applyModelRedactions(rawText, uniqueEntities, redactionMap); workingText = runRegexSafetyNet(workingText, redactionMap); return { scrubbedText: workingText, redactionMap }; } Next UpComplete live Firebase AI Logic + App Check debug token verification and benchmark on-device Gemini Nano in Chrome 139+.Add side-by-side clause vs. counter-offer diffing and privacy-safe audit report exports.Drop a comment if you're testing SafeClause or have ideas for the next iteration!

Submission history