Inspiration

Medical bills are confusing, and errors are common: duplicate line items, balances that don't add up, and out-of-network "surprise" bills. The federal No Surprises Act gives patients real protections:

  • no balance billing for out-of-network emergency care;
  • a federal dispute process when a self-pay bill is $400 or more over the Good Faith Estimate.

Few people know how to use them. The obvious AI fix is "paste your bill into a chatbot", but a medical bill is full of protected health information: your name, birthday, address, insurance member ID and account numbers. We wanted the power of a cloud model without handing over that data. Hybrid inference makes this possible.

What it does

Paste a bill, or try one of three realistic samples, then click Audit my bill. A 5-step scan bar shows each stage live: Parse → PHI firewall → Name sweep → Explain → Letter. BillShield:

  1. Tokenises every identifier on the device, for example [NAME_1] and [MEMBER_ID_1].
  2. Runs a hidden-name sweep over the raw bill with Gemini Nano in ONLY_ON_DEVICE mode, using structured JSON output. This step can never fall back to the cloud.
  3. Audits the bill with a deterministic rule engine. It checks for duplicate charges, totals and balance math errors, repeated ER visit levels, NSA emergency balance billing, and an NSA Good Faith Estimate overrun with a 120-day dispute deadline countdown. Potential savings count up live, and each finding links to the CMS sources.
  4. Explains the bill in plain English with PREFER_ON_DEVICE. Long bills move to the cloud automatically, with the threshold set in Remote Config.
  5. Drafts a dispute letter with live Gemini (PREFER_IN_CLOUD) from redacted text only. Real names and account numbers are restored on the device, and one click copies or downloads the letter.
  6. Shows a Privacy ledger for every AI step: the requested mode, where it actually ran (inferenceSource), latency, and identifiers sent, which is always 0. A pulsing Hybrid routing badge meters on-device vs cloud latency in real time.

With no network and no model, the offline tier still audits, redacts and drafts a template letter.

How we built it

  • Firebase AI Logic:
    • getAI(app, { backend: new GoogleAIBackend() }) + getGenerativeModel(ai, { mode, inCloudParams, onDeviceParams }), with one hybrid model per task and mode.
    • It runs live on the free Spark plan with the Gemini Developer API (gemini-3.5-flash-lite).
    • onDeviceParams.promptOptions.responseConstraint (a JSON schema) drives the on-device name sweep.
    • initializeDeviceModel() runs on the user's click, with download progress shown in the UI.
    • response.inferenceSource powers the ledger and the On-device/Cloud badges.
  • Remote Config retunes routing without a redeploy: on_device_max_chars, cloud_model, letter_mode. App Check support is built in (reCAPTCHA v3 / Enterprise or a debug token).
  • A code-level PHI guard (guardPrompt → PhiLeakError) refuses any cloud-eligible request that still contains a known identifier.
  • The front end is vanilla JS modules bundled with esbuild, with CSS motion (count-ups, staggered reveals, telemetry pulse, completion pop) that respects prefers-reduced-motion.
  • CI: GitHub Actions runs lint, tests and the build, then deploys to GitHub Pages.
  • The demo video is recorded in Chrome against the live app, with real Gemini calls, then narrated with edge-tts and mixed with ffmpeg.

Challenges we ran into

  • Making on-device inference a privacy boundary rather than a cost optimisation, which means deciding per task which modes are allowed.
  • Restoring tokens in free-form model output so letters are ready to send. We also normalise any markdown the cloud model returns into clean plain text.
  • Proving privacy, not just claiming it: the live end-to-end test inspects the actual network request bodies sent to Gemini and asserts that they contain no identifiers.
  • App Check enforcement rollout: we built graceful local fallback so the app never breaks when the cloud rejects a call.

Accomplishments that we're proud of

  • Real live hybrid AI on a $0 Firebase project, with a ledger showing 0 identifiers sent off-device.
  • 24 unit tests and 46 Chrome end-to-end checks, all passing with 0 console errors. ESLint is clean.
  • The Chrome checks cover four setups: live Firebase AI Logic, the offline tier, a Gemini Nano routing harness, and mobile.
  • On the ER sample, BillShield finds a duplicate $2,310 CT scan and a likely surprise balance bill, for $4,640.60 in potential savings.

What we learned

Hybrid inference is most powerful when routing is driven by data sensitivity as well as availability. ONLY_ON_DEVICE is a real privacy guarantee you can build product features on. Showing the routing live, with telemetry and a ledger, makes that guarantee something users can see and trust.

What's next

  • Scanned bills, using on-device image input (JPEG/PNG).
  • An Explanation of Benefits (EOB) cross-check against the bill.
  • Spanish-language letters.
  • A Chrome extension that audits bills inside patient portals.
  • App Check enforcement with reCAPTCHA Enterprise.

Testing instructions for judges

Open https://mogzz2008.github.io/billshield/, click "ER visit, out-of-network doctor", then Audit my bill. The explanation and letter are generated live by Gemini through Firebase AI Logic; check the "Cloud · Firebase AI Logic" badges and the Privacy ledger. Add ?local=1 to the URL to see the offline tier. To see on-device inference, use Chrome desktop 139+ with chrome://flags/#prompt-api-for-gemini-nano-multimodal-input enabled. Local run: npm ci && npm run build && npm run serve.

Built With

  • firebase-ai-logicgemini-developer-apigemini-3.5-flash-litegemini-nanochrome-prompt-apifirebase-app-checkfirebase-remote-configjavascriptesbuildpuppeteergithub-actionsgithub-pages
Share this project:

Updates

Submission history