Inspiration
Recruiters, legal teams, founders and healthcare staff want AI to review contracts, resumes and medical forms. But compliance rules like GDPR and HIPAA often forbid sending raw personal data to an outside server, and people also work offline. Teams end up either skipping AI or pasting sensitive data into tools they shouldn't. We wanted one tool where the sensitive part never leaves the device, and the cloud only sees what's safe.
What it does
CloakDocs splits the job by what each model is allowed to touch:
Local PII Redact & Triage runs on-device (ONLY_ON_DEVICE) with Gemini Nano and works offline. It replaces names, SSNs, emails, phones, addresses, salaries, dates of birth and account IDs with reversible tokens such as [PERSON_1] and [SSN]. The token map lives only in browser memory. Deep Cloud Clause Audit sends only the sanitized text to the cloud (ONLY_IN_CLOUD). It returns the top 3 legal or financial risks with severity, risk and compliance scores, and redline rewrites. Auto Hybrid Route uses PREFER_ON_DEVICE. Gemini Nano answers when it's ready. The cloud takes over when it isn't, or when the text exceeds a limit controlled by Remote Config. A live telemetry pill shows where each run executed (green on-device, blue cloud, amber hybrid fallback), the exact latency in ms, and online/offline status. A side-by-side view shows what the cloud saw next to the locally re-hydrated result, and a network payload inspector shows exactly which characters left the device.
How we built it
Firebase AI Logic is the single SDK for all three modes: getAI, GoogleAIBackend, getGenerativeModel with hybrid params, and InferenceMode. We read inferenceSource on every response so the UI reports what really ran. Defense in depth for privacy. A rules engine (regex plus context) is a deterministic floor that works with no model. Gemini Nano finds what rules miss, and every entity it returns must literally exist in the document, which discards hallucinations. Before any cloud call, a privacy gate re-scans the outbound text and blocks it if any known original value or identifier remains. Raw text is only ever given to an ONLY_ON_DEVICE model. Firebase App Check protects AI Logic, with the debug-token flow for local testing and reCAPTCHA Enterprise in production. Anonymous Auth gives zero-friction sign-in. Firestore stores per-user sanitized telemetry and scores in real time. Security rules reject any field that isn't on an allow-list, so raw text can't be stored even by mistake. Remote Config controls routing (max_local_char_limit, enable_cloud_deep_audit, cloud_model) with local defaults for offline use. React, Vite and Tailwind CSS on Firebase Hosting. An optional MV3 Chrome extension manifest opens the app in the side panel.
Challenges we ran into
Never sending raw text to the cloud. The hybrid SDK can fall back to the cloud, which is the opposite of what a redactor needs. We used ONLY_ON_DEVICE for raw text, a local rules engine as the fallback, and a hard check that aborts if the SDK ever reports cloud inference for raw text. Salary and money detection. A dollar-amount regex also flags contract fees and liability caps, which the cloud audit needs. We tag amounts as salary only near compensation words. Name matching. "Priya Raman", "Priya" and "Raman" must share one token, and a name must never span a line break. A small on-device model. We chunk long documents and validate its output rather than trusting it. App Check on a free project. Getting enforcement, reCAPTCHA Enterprise and the debug-token flow right without billing took some digging.
Accomplishments that we're proud of
The sanitized-only guarantee is enforced in four places: the redactor, the privacy gate, the Firestore rules, and a visible payload inspector. Redaction keeps working fully offline; it still runs when the network is off. The pill makes the hybrid behavior something you can see, not just read about. It's deployed, App Check-enforced, and open source.
What we learned
Hybrid inference is most useful when you choose the mode per task and treat the on-device model as a privacy boundary, not only a cost saver. A small local model works best as one layer next to deterministic rules, with its output validated.
What's next for CloakDocs
PDF and DOCX import, custom entity types per industry, an exportable redaction report for audit trails, stronger name detection, and a packaged Chrome extension.
Built With
- cloud-firestore
- firebase-ai-logic
- firebase-app-check
- firebase-authentication
- firebase-hosting
- firebase-remote-config
- gemini-(cloud)
- gemini-nano-(chrome-prompt-api)
- javascript
- react
- recaptcha-enterprise
- tailwind-css
- vite