Inspiration
Every day, people paste resumes, employment contracts, medical notes, and financial agreements into cloud AI tools—exposing raw Personally Identifiable Information (PII) like names, phone numbers, emails, addresses, and government IDs to external servers. With frameworks like India's Digital Personal Data Protection (DPDP) Act and stricter enterprise privacy policies, users should not have to choose between protecting personal data and getting cloud-grade AI analysis. We built Zero-Leak Document & Form Guard so raw PII stays strictly inside browser RAM while cloud AI only ever sees anonymized tokens.
What it does
Zero-Leak Document & Form Guard (Live Demo) is a privacy-first Hybrid AI web application that detects and vaults PII locally on the user's device before any text is sent to the cloud.
[PDF / TXT in Browser RAM]
│
▼
Stage 1: Regex Shield (Structured PII → Local Vault)
│
▼
Stage 2: On-Device AI (ONLY_ON_DEVICE → Contextual PII → Local Vault)
│
▼ (Sanitized Tokens Only: [PERSON_1], [ADDRESS_1], [EMAIL_1])
Stage 3: Cloud Gemini (gemini-3-flash-preview → Audit / Analysis)
│
▼
Stage 4: Local Re-hydration (Maps Tokens Back + Live Payload Inspector)
- 100% Client-Side PDF/TXT Parsing: Uploaded documents are parsed directly in browser memory using a bundled
pdfjs-distworker—files are never uploaded to a backend server. - Stage 1 — Regex Shield: Deterministically catches and vaults structured PII (emails, phone numbers, and Strict India PII / DPDP patterns).
- Stage 2 — On-Device Contextual Scanner (
ONLY_ON_DEVICE): Runs built-in browser AI (Gemini Nano) strictly on-device with zero silent cloud fallback to redact contextual entities like ALL-CAPS names, cities, and addresses, backed by a Strict Fail-Closed toggle that blocks cloud calls if local AI is offline. - Stage 3 — Cloud Reasoning & Hybrid Quick Verdict: Routes only the sanitized, tokenized payload through a leak gate to
gemini-3-flash-previewfor deep Risk & Compliance Audits, Summaries, or Action Items, paired with aPREFER_ON_DEVICEquick verdict. - Stage 4 — Local Re-hydration & Live Payload Inspector: Re-maps tokens locally from browser memory and exposes three verifiable tabs: Final Re-hydrated Answer, Exact Payload Sent to Cloud, and Raw Tokenized Cloud Reply.
How we built it
- Frontend & Local Ingestion: React, TypeScript, Vite, and Tailwind CSS, paired with
pdfjs-distusing an in-memory local worker (pdf.worker.min). - Hybrid AI Pipeline: Built on the Firebase AI Logic SDK, separating
InferenceMode.ONLY_ON_DEVICEfor contextual PII redaction,InferenceMode.PREFER_ON_DEVICEfor hybrid quick verdicts, andgemini-3-flash-previewfor cloud reasoning on anonymized text. - Security & Deployment: Hosted on Firebase Hosting and secured with Firebase App Check using Google Cloud Fraud Defense (reCAPTCHA Enterprise), with
import.meta.env.DEVgating so debug tokens are strictly stripped from production builds.
Challenges we ran into
- Preventing silent cloud leaks in Stage 2: Default hybrid inference modes can silently fall back to cloud endpoints when on-device AI is unavailable. Locking Stage 2 to
InferenceMode.ONLY_ON_DEVICEand adding a leak gate plus a Strict Fail-Closed option eliminated that risk. - Handling unstructured PDFs with small on-device models: Multi-page resumes with ALL-CAPS headers caused inconsistent entity labels and high latency across chunked passes. We fixed this with category normalization (
CATEGORY_ALIASES) and a single-pass2500-character scan cap. - Production App Check & Worker Bundling: Aligning Vite's production worker bundling for
pdfjs-distand migrating from dev debug tokens to live Google Cloud Fraud Defense (reCAPTCHA Enterprise) attestation on.web.apprequired strict key and environment verification.
Accomplishments that we're proud of
- Built a verifiable zero-leak workflow—judges and users can inspect the Exact Payload Sent to Cloud tab after every run instead of taking our privacy claim on trust.
- Achieved fast on-device Stage 2 redaction across both Chrome and Microsoft Edge (completing locally in under 3 seconds on Edge with zero cloud fallback).
- Shipped a live, production-hardened web app backed by Firebase App Check and Google Cloud Fraud Defense.
What we learned
- Hybrid AI works best with strict boundary separation: on-device models enforce privacy boundaries, while cloud models handle deep reasoning over tokenized structure.
- On-device models require defensive output parsing, label normalization, and tight input budgets compared to cloud LLMs.
- Separating development debug tokens from production App Check attestation is critical before deploying client-side AI apps.
What's next for Zero-Leak Document & Form Guard
- Expanding redaction presets for healthcare records, financial statements, and legal NDAs alongside Strict India PII (DPDP).
- Adding client-side WebAssembly OCR for scanned, image-only PDFs with zero server uploads.
- Supporting one-click local export of both redacted documents and re-hydrated audit reports.
Built With
- firebase
- firebase-app-check
- firebase-hosting
- gemini
- gemini-nano
- google-cloud
- pdf.js
- react
- tailwindcss
- typescript
- vite
- vs