Inspiration

The person in a family most likely to lose money to a scam is usually the least technical one. In India the scripts are well known: a fake CBI officer announcing a "digital arrest", an "SBI KYC will be blocked today, share the OTP" SMS, a stranger who "sent ₹5000 by mistake" and wants it back on UPI, a part-time job that pays to like videos. They work because they arrive as ordinary messages and demand action now.

The obvious fix is "send every message to an AI". But the messages people most need checked are full of exactly what shouldn't leave their phone: phone numbers, account numbers, UPI IDs, Aadhaar and PAN. Hybrid inference let us build the version we actually wanted: the private part stays on the device, and the cloud only ever sees a redacted copy.

What it does

Scam Shield tells you, in plain language, whether a message is safe, suspicious, or a likely scam, which tactics it uses, and why.

  • Chrome extension: shows a warning banner above scam emails in Gmail. You can also select text anywhere (WhatsApp Web, Messages for Web, any page) and right-click Check with Scam Shield, or paste into the side panel.
  • Android app: share any SMS or chat message to Scam Shield from the share sheet, or select text in any app and choose Check with Scam Shield.

Every result shows "How this was decided" (each step of the routing) and "What left your device": either "Nothing", or the exact redacted text that was sent to the cloud.

How we built it

The core is a second-opinion router, the same on both platforms:

  1. Rules score the raw text with deterministic scam signals (OTP requests, remote-access apps, digital arrest, KYC threats, UPI payment requests, refund tricks, short links…). They're instant, run offline, and are unit-tested.
  2. Gemini Nano, on-device, judges the raw text via Firebase AI Logic in ONLY_ON_DEVICE mode and returns structured output (verdict, confidence, tactics, explanation).
  3. If Nano is confident and agrees with the rules, we're done. Nothing left the device.
  4. Otherwise the message is redacted (phones, emails, UPI IDs, Aadhaar, PAN, IFSC, account numbers, link paths; the link's host is kept because it's a scam signal) and sent to Gemini in the cloud with PREFER_IN_CLOUD, which falls back to on-device when offline.
  5. Final verdict = the worse of rules and model. A model can raise an alarm but can never clear a rule hit. This fails closed: if every model is unavailable, you still get the rules' verdict.

Firebase AI Logic hybrid inference on two platforms:

  • Chrome: the firebase/ai web SDK with the Chrome Prompt API. Structured output uses responseConstraint on-device and responseSchema in the cloud; response.inferenceSource drives the UI.
  • Android: firebase-ai + firebase-ai-ondevice (Gemini Nano through AICore / ML Kit Prompt API). The schema is a KSP-generated @Generable data class used with generateObject(), and warmUp() loads Nano before the first check.

The rules, redactor and router are ported 1:1 to Kotlin. The Android unit tests run the same cases as the JavaScript tests, so the two engines can't drift apart.

The rest of Firebase:

  • App Check (debug provider) protects the Gemini API on both platforms. Chrome MV3 forbids remote scripts, so reCAPTCHA can't load in an extension page.
  • Remote Config tunes the score thresholds, the on-device confidence bar and the cloud model without shipping a new build.
  • Anonymous Auth + Firestore keep a community counter ("this tactic mix has been flagged N times"). Only the tactic combination and link hosts are stored, never message text. Security rules allow only +1 increments.

Challenges we ran into

  • Getting Gemini Nano onto a laptop. Chrome only downloads it with ~22 GB free disk; ours sat on "downloading" until we cleared space.
  • First-prompt latency. Nano's first answer can take 15+ seconds while it loads. We added a 20-second on-device deadline (slower answers escalate to the cloud instead of hanging the UI), a timing readout in the trail, and warmUp() on Android.
  • Small-model quirks. Nano sometimes tagged tactics on a message it called safe. The router now only trusts model tactics that back an alarm.
  • Different structured-output APIs per platform. The web SDK takes a Schema; Android hybrid needs a KSP @Generable class. Same JSON shape, two very different routes to it.
  • Gmail integration. An email opened before the side panel was never re-checked, and reloading the extension orphaned the content script. Both now recover on their own.

Accomplishments that we're proud of

  • Hybrid as a privacy boundary, not just a fallback, and visible to the user: every verdict shows exactly what (if anything) left the device.
  • Fail-closed design: a model can never talk the app out of a rule hit.
  • One engine, two platforms, kept honest by shared test cases.
  • Works offline on Chrome: with Wi-Fi off, rules + Nano still catch the scam.

What we learned

  • On-device models are good enough to settle the common cases. That makes the cloud a second opinion rather than the default, which changes both the privacy and the cost picture.
  • A deterministic layer is what makes it safe to trust a small model: the model adds judgment and plain-language explanations, and the rules make sure it can't make things worse.
  • Exposing the routing ("How this was decided") made debugging easier and the product more trustworthy.

What's next

  • On-device testing on more Android phones with AICore. In the demo, Android shows the cloud second opinion because the emulator has no Gemini Nano.
  • Name redaction with an on-device NER pass; names aren't redacted today.
  • Hindi and other Indian languages.
  • Play Integrity / reCAPTCHA Enterprise App Check for production builds, replacing the debug provider.
  • A notification-listener mode on Android, so SMS gets checked without manually sharing it.

Built With

  • android
  • chrome
  • chrome-prompt-api
  • cloud-firestore
  • esbuild
  • firebase-ai-logic
  • firebase-app-check
  • firebase-authentication
  • firebase-remote-config
  • gemini
  • gemini-nano
  • javascript
  • jetpack-compose
  • kotlin
  • ml-kit
Share this project:

Updates

Submission history