Inspiration
Scam messages work because they are private and urgent: a parcel that cannot be delivered, a bank account that is "locked", a wedding invitation that is really an .apk file. In Indonesia, where I live, these arrive on chat apps every week, and the people most at risk are the ones least likely to ask anyone.
The moment someone wonders "is this real?" is the moment a second opinion helps most. But the message is personal. It can contain a name, a phone number, an account number or a one-time code. Asking people to paste that into a cloud service means taking a second risk in order to check the first. An on-device model removes that trade-off, and that is the case hybrid inference was made for.
What it does
Cek Dulu means "check first". You paste a message, in any language, and get:
- a verdict: Scam, Suspicious or No warning signs, with the kind of scam named;
- the evidence: the warning signs are underlined and numbered in the message itself, each with a one-line reason;
- what to do next, and a reply that gives nothing away when replying makes sense;
- a label that says where the check ran: "ON DEVICE · nothing left this browser" or "CLOUD · cleaned copy sent".
With the on-device model present, the message never leaves the browser, and the check still runs with Wi-Fi switched off (shown in the video).
How I used Firebase AI Logic hybrid inference
The app uses three inference modes, each for a reason.
ONLY_ON_DEVICEfor checking a message. A private message must not leave the device because of a silent fallback, so the main check does not usePREFER_ON_DEVICE. Gemini Nano returns structured JSON throughresponseConstraint.ONLY_IN_CLOUDonly after consent. When there is no on-device model, when the message is too long for it, or when the person asks for the larger model, the app shows a consent screen with the exact text that would be sent. Before that preview is built, phone numbers, email addresses, long numbers (accounts, IDs, one-time codes) and link query strings are removed on the device. The person chooses "Send this and check" or "Cancel, send nothing". The cloud model returns the same structure throughresponseSchema, and one parser validates both.PREFER_ON_DEVICEfor "How does this kind of scam work?" A general explainer contains nothing from the message, so automatic fallback is the right behaviour there.
The label on every result comes from response.inferenceSource, which the SDK reports, not from what the app intended.
Other Firebase products: App Check (reCAPTCHA Enterprise) so only this app can call the cloud model; Remote Config to add newly reported scam patterns to the model's instructions and to tune routing without a release, with built-in defaults so the on-device path works when it cannot be reached; Hosting for the app.
How I built it
TypeScript and Vite with the Firebase JS SDK, and no other runtime dependency. The rules that matter for trust are small pure modules with unit tests: redaction, the routing decision, and strict parsing of the model's answer. Quotes from the model are matched against the real message, and a quote that does not occur in it is not shown as a quote. I built it with Claude Code as the coding agent and tested the on-device path by hand in Chrome on a MacBook.
Challenges
- Resisting the one-line solution.
PREFER_ON_DEVICEwould have made the main check trivial, and wrong for this problem. Turning "fallback" into "ask" took a routing module and a consent screen. - Two models, one contract. The on-device and cloud models take schemas in different forms. Keeping one result shape and one validator stops the two paths from drifting apart.
- Knowing what the device can do before asking it. The app asks Chrome about availability first, so it can offer the one-time model download from a click instead of failing.
- App Check on a new project. For the first minute after registering the provider, token requests were rejected; the app reports that state in plain words instead of a raw error.
What I learned
Hybrid inference is a product decision as much as a technical one. Which mode to use depends on what the data is, and the same app can need three different answers.
What is next
- Reading screenshots on the device (the code path exists; it needs more testing before I claim it).
- Indonesian and other interface languages.
- A share target on Android, so a message can be sent to Cek Dulu straight from a chat app, using the same Firebase AI Logic code on Gemini Nano.
Built With
- chrome
- firebase
- firebase-ai-logic
- firebase-app-check
- firebase-hosting
- firebase-remote-config
- gemini
- gemini-nano
- typescript
- vite