Inspiration

People paste leases, medical bills and contracts into chatbots because they need a real answer. The question is usually general: "Can my landlord keep the deposit for normal wear?" The document is not. It holds a name, an address, an account number and a signature. Today you either send all of it to the cloud, or black it out by hand and hope you caught everything.

Hybrid inference makes a third option possible. A small model on the device can read the private document. A large model in the cloud can answer the general question. Halfveil puts a gate between the two.

What it does

  1. You paste a document and ask a question about it. On the web you can also open a file: PDF, Word (DOCX), a spreadsheet, text or a photo of a page.
  2. The device model finds your personal details and veils them in place: names, addresses, phone numbers, account numbers, dates of birth. You can lift a veil or veil more words.
  3. The device model writes one or two general questions that hold none of those details. You see the exact text before it leaves. A leak check in code blocks the send if a veiled value is still in it.
  4. Only the checked questions go to Gemini in the cloud.
  5. The device model connects the cloud answer to the lines of your document, and code puts your real details back in, on your device.

The page reads top to bottom in one column. A rail marks each step green on the device and blue in the cloud, so you always see where your text is.

In the default mode, the document never leaves the device. On the web, a second mode sends the document with made-up values (or a placeholder) in place of each veiled detail, for questions that need the whole text. You see all of it before the send, and the device swaps the real values back in by exact match. A reload removes the document and the answers.

How we built it

  • Firebase AI Logic hybrid inference on the web: every step that reads the original runs with InferenceMode.ONLY_ON_DEVICE on Gemini Nano in Chrome. The cloud step runs with InferenceMode.ONLY_IN_CLOUD. We never use a "prefer" mode for the private steps, because a prefer mode falls back to the cloud when the device model is missing.
  • One gate core in TypeScript (pure functions, JSON in and out) runs in the browser and in JavaScriptCore on iOS and macOS. The Android build loads it in the Jetpack JavaScript sandbox.
  • A Flutter app for iOS, macOS and Android. Platform channels reach the device models through Firebase AI Logic: Apple Foundation Models on iOS and macOS (a session on the system model only, so it never falls back to the cloud), and Gemini Nano with ONLY_ON_DEVICE on Android. The cloud step uses the firebase_ai Dart package.
  • Firebase App Check: reCAPTCHA Enterprise on the web; App Attest (iOS) and Play Integrity (Android) in release builds.
  • Safety nets in code, not only in prompts: pattern detectors, typed placeholders that code restores, a leak check before every send, and a line check so the model cannot put words in your document.
  • Files are read and written in the browser (pdf.js, Tesseract.js for scans and photos, mammoth, SheetJS, docx, pdf-lib).

Challenges we ran into

  • The Apple model refuses personal text. Its structured answer step still refuses 9 of 10 test documents. New prompt wording did not stop this, so a plain-text fallback answers the 9 refused documents, and all 10 get an answer.
  • Context limits. One span request on a 331-character lease filled the Apple model's 4,096-token context, because the model repeated its output. The core now sets a token budget and an output cap for each step, and sizes the chunks to fit.
  • Hybrid has no Dart API. The Dart package of Firebase AI Logic calls only the cloud, so the app reaches each device model through native platform channels.
  • A model veils too much. The Apple model veiled roles and legal terms, so the leak check blocked a correct question. We added checks on which values may count as private.

Accomplishments that we're proud of

  • On our test set of 10 fictional documents with 50 private details, the full gate veiled 50 of 50 with Apple Foundation Models (also through Firebase AI Logic in the iOS app) and 49 of 50 with Gemini Nano in Chrome. No outgoing question held a private detail in either run.
  • Without any device model, the pattern rules alone still veil 48 of 50, and the app asks the user to check each name.
  • The same core runs in Chrome, in the iOS Simulator and on macOS, and on each one the original stays on the device. The Android build uses it too, but it has not run on a phone yet.

What we learned

  • The split between device and cloud is the product, not a fallback. The device model is good at finding and placing; the cloud model is good at knowing.
  • A prompt is not a guarantee. Every promise that matters (no leak, real values back, no invented lines) is checked in code.

What's next

  • Checks on a real iPhone and an Android phone with their device models.
  • More languages: the device model of each platform sets the languages, so each one needs its own checks.
  • Photos: find location clues (a street sign, a parcel label) before a photo is shared.

Built With

  • apple-foundation-models
  • bun
  • dart
  • docker
  • firebase-ai-logic
  • firebase-app-check
  • flutter
  • gemini-api
  • gemini-nano
  • javascriptcore
  • jetpack-javascriptengine
  • kotlin
  • nginx
  • react
  • recaptcha-enterprise
  • swift
  • typescript
  • vite
Share this project:

Updates

Submission history