Inspiration

Clinicians, therapists and social workers spend hours turning session notes into referral letters. A cloud model writes those letters well. But pasting a client's note into one sends their name, birth date, address and diagnosis to a server the clinic doesn't control. A small on-device model keeps the note private, but it can't write the letter as well.

The usual hybrid pattern is "on-device when you can, cloud when you must". For this job that is exactly backwards: the raw note must never go to the cloud, and the letter should come from the cloud. So Airlock splits the work by what each model is allowed to see.

What it does

  1. The on-device model finds every identifier. It reads the raw note and lists every person, relative, clinician, facility and place. Pattern detectors catch phones, emails, record numbers and dates. Nothing in this step can reach the cloud.
  2. The clinician reviews. Held identifiers are highlighted. Tap one to release it, or select text to hold something the scan missed.
  3. Only tokens leave. Each identifier becomes a typed token ([PATIENT_1], [CLINICIAN_1], [DOB_1] (age 54)), and cloud Gemini drafts the letter from the redacted note.
  4. Airlock proves it. Before sending, the full prompt (including anything typed into the task line) is checked for every held value. Send stays locked until the count is zero. On the web, the app also captures the literal request body where the Firebase SDK calls fetch and checks it again: 0 of 17 held.
  5. Names come back on the device. Tokens are swapped back for the real values locally, by plain string substitution, not by a model.

It runs on web (Chrome desktop with Gemini Nano) and natively on iPhone (Apple Intelligence). Both share the same token format, leak checks and Firestore history.

How we built it

Each inference mode in Airlock is a privacy decision, not a fallback setting:

Job Web (Firebase AI Logic) iOS Why
Find identifiers in the raw note ONLY_ON_DEVICE, JSON-schema-constrained output Apple Foundation Models, guided generation The raw note must never be a cloud request. With no on-device model, Airlock stays sealed: patterns plus a mandatory manual review stand in, and the raw note is never sent instead. On the web, any response whose inferenceSource isn't on-device is rejected.
Draft the letter PREFER_IN_CLOUD Firebase AI Logic's GeminiLanguageModel, falling back to the on-device model The input holds only tokens, so the better model can write it. If the cloud is down or overloaded, the letter is drafted on-device, and the UI says which one wrote it.
Audit detection on labeled notes ONLY_ON_DEVICE Apple Foundation Models Measures, on the user's own machine, how many labeled identifiers would still reach the cloud.

Around the models:

  • App Check is enforced for AI Logic. The hosted app uses reCAPTCHA Enterprise; local development and iOS debug builds use debug tokens.
  • Anonymous Auth scopes each user's history.
  • Firestore stores only the redacted note and the letter as the cloud wrote it, tokens and all. The client refuses to save a record that contains a held value. Security rules enforce ownership, the schema and field sizes, and reject any record that reports a leak.
  • Remote Config holds the policy name, the cloud model and the drafting instructions. When gemini-3.8-flash started returning 503 "high demand" during development, we switched the drafting model without a release.
  • Hosting serves the web app.

Detection is a pipeline:

  • Regex patterns.
  • An on-device pass for everything named.
  • A second on-device pass for places and organizations alone.
  • Then every held value is propagated to each of its occurrences, overlapping spans are merged, and name parts are aliased ("Maria" shares the token of "Maria Delgado").

The Swift app is a line-for-line port of the TypeScript patterns, vault and leak scan, so both platforms behave the same.

Measured

The Audit tab runs 15 synthetic notes with 193 labeled identifiers (10 tuning notes and 5 written afterwards as a holdout) and counts how many identifiers would reach the cloud:

Leaked with Airlock Leaked with patterns alone Mean scan
Web, Chrome 158 + Gemini Nano (3 runs) 0 of 193, each run 77 of 193 7.9–8.4 s per note
iOS 27.2, Apple Foundation Models (in-app) 0 of 193 77 of 193 4.2 s per note

All runs were on an M3 Pro MacBook Pro on Nov 26, 2026. Every note is synthetic.

Challenges we ran into

  • Small models vary. Early versions missed 1 to 3 identifiers on some runs, such as a city on its own or a name in a signature line. A second on-device pass for places, relation-word and signature backstops, and propagating each held value to every occurrence got this to 0 across repeated runs.
  • Apple's guardrails. Foundation Models refused some clinical notes as sensitive in guided generation. Airlock uses the permissive content-transformation guardrails, which cover plain-text output, so when guided output is refused it retries as simple kind|text lines.
  • The task line is a side door. A clinician can type "letter for Maria to Dr. Whitcomb" into the instructions. Held values in the task are sealed to their tokens. A name the scan never saw is caught by another on-device pass over the task, and sending is refused until the clinician takes it out or moves it into the note and scans again.
  • Proving a negative. Counting tokens doesn't prove nothing leaked. The web app scans the literal request body that leaves the browser.
  • Three adversarial review rounds caught case variants, line-wrapped names, underscores as word boundaries, and the over-redaction of words like "don't".

Accomplishments that we're proud of

  • 0 of 193 labeled identifiers leaked on both platforms, with the proof visible in the UI for every letter.
  • It fails closed: no on-device model means no raw note in the cloud, ever.
  • One design, two platforms, two different on-device models, and the same guarantees.

What we learned

Hybrid inference is most useful when the split follows what each model may see, not only what each model can do. The on-device model doesn't need to write well, just to read carefully. The cloud model doesn't need to know who the patient is to write a good letter.

What's next

  • Android once Gemini Nano is available on a test device.
  • App Attest for iOS release builds.
  • Organization policies in Remote Config: which identifier kinds to hold, and allowed cloud models.
  • Quasi-identifier warnings: a rare diagnosis or a distinctive story can still identify someone, so the clinician stays responsible for what they send.

Built during the submission period

Airlock is a new project. The repository, the web app, the iOS app and the labeled audit notes were all created during the submission period; the first commit is from Nov 26, 2026. It uses no pre-existing code other than open-source libraries (the Firebase SDKs, React, Vite). It was built with AI coding agents.

Testing instructions

Web

  1. Open https://airlock-hybrid-2026.web.app in Chrome on a desktop (Windows, macOS, Linux or ChromeOS) that meets Chrome's on-device model requirements, including about 22 GB of free disk space. If the status pill says the model isn't downloaded, click Download and wait.
  2. On Draft, pick a sample note, click Scan on this device, review the highlights, then click Send through the airlock. The middle column shows the captured request and how many held values it contains.
  3. Audit runs the 15 labeled notes on your machine. History shows what Firestore stored.
  4. In a browser with no on-device model, the scan stays sealed: patterns hold what they can, and sending requires a manual review.

iOS (Xcode 27, iOS 27 simulator on an Apple silicon Mac with Apple Intelligence enabled): see "On iPhone" in the README. It covers creating an App Check debug token, xcodegen generate, and running the Airlock scheme.

Built With

  • apple-foundation-models
  • bun
  • cloud-firestore
  • firebase-ai-logic
  • firebase-app-check
  • firebase-authentication
  • firebase-hosting
  • firebase-remote-config
  • gemini
  • gemini-nano
  • react
  • recaptcha-enterprise
  • swift
  • swiftui
  • typescript
  • vite
Share this project:

Updates

Submission history