Inspiration

Small leaks add up: a meal charged twice, a $1 trial that quietly became $22.99 a month, a streaming price that crept up, a wire fee nobody noticed. Most people know they should ask for the money back, and few do, because finding the leaks takes an evening with a spreadsheet and writing the emails takes another.

AI could do both, but there is a catch. A bank statement is one of the most private documents a person has. Pasting it into a chatbot sends where you eat, who you pay and how much you earn to someone else's server. We wanted an AI money tool that does not ask for that trust.

What it does

Drop in a bank statement (a CSV from any bank) or try the built-in sample of 400 lines.

  1. It finds the leaks. Double charges, trials that became paid plans, price rises, overlapping subscriptions and bank fees, each with the statement lines behind it and what it costs per year. This part is ordinary, tested code, not AI.
  2. It writes the message. For each leak, Gemini drafts the refund, cancellation or fee-waiver message, polite or firm, to the merchant or to your bank, using only facts from the statement.
  3. It explains the rest. It sorts merchants no rule could place, answers questions in your own words ("what did I blow on takeout?"), explains unfamiliar charges, and puts the statement in plain words.

The idea: the inference mode is the privacy switch

Hybrid inference is usually treated as a performance trick: run on the device when you can, fall back to the cloud when you cannot. For financial data, a silent fallback is exactly the problem. Clawback turns the inference mode into a switch the user holds:

  • On this device first. When Gemini Nano is available in Chrome, every request runs with InferenceMode.ONLY_ON_DEVICE. Nothing leaves the browser, and the app says so under every answer.
  • The cloud only by consent. Without an on-device model, a request can go to Gemini with InferenceMode.ONLY_IN_CLOUD, but first the app shows the complete text that would be sent, character for character, and waits for "Send it". You can also choose "stay on this device" (never send) or "use the cloud without asking".
  • A ledger of everything. Every request is listed with where it ran (response.inferenceSource), how long it took and, for the cloud, the exact text that left.
  • No PREFER_* modes for statement text, because a fallback the user did not see is what this app exists to prevent.

How we built it

  • Firebase AI Logic (firebase/ai, Gemini Developer API backend): getGenerativeModel with mode, inCloudParams (model, system instruction, responseMimeType and responseSchema for JSON tasks) and onDeviceParams (createOptions with expected inputs and outputs, responseConstraint for JSON). initializeDeviceModel() is called from a button so the person chooses to download Gemini Nano. Replies stream with generateContentStream.
  • Firebase App Check protects the cloud path.
  • The model never does arithmetic. Totals, dates, regular charges and alerts come from tested TypeScript. The model drafts, sorts and translates questions into a query the app computes itself.
  • Every prompt is plain data (src/ai/tasks.ts), so the consent dialog shows the very text the model receives.
  • Strict readers for every structured reply. An unknown category, or a merchant that is not in the statement, is dropped rather than trusted.
  • A strict Content Security Policy: the page may only talk to itself and to Firebase.
  • Plain TypeScript and esbuild, no framework. 33 unit tests and 8 end-to-end browser scenarios.

Challenges we ran into

Every automated check passed and the app still failed on the real models. Running Gemini Nano and cloud Gemini side by side changed three designs:

  • Sorting. Asked for a list of twelve answers, Nano often returned eleven or thirteen, and with numbered slots it pinned categories on the wrong merchants. Now each answer must start with the merchant's name, chosen from an enum of the names asked, and answers are matched by name. Missing answers are asked again; nothing is guessed.
  • The summary. Nano sometimes merged two figures into a new one. The app now checks every dollar amount in the reply against the facts it supplied, asks once more if one is new, and otherwise shows the computed facts.
  • Explaining a charge. Nano confidently invented a meaning for "SQ". Payment prefixes (Square, Toast, PayPal and others) are now looked up in code, and the model is only asked what kind of business the name suggests.

Accomplishments that we're proud of

  • The privacy promise is checkable: the ledger shows what left the device, and the consent dialog shows it before it leaves.
  • The same features work in both modes. On a MacBook Air with Chrome's built-in model: a refund message in about 5 s, twenty unfamiliar merchants sorted in about 25 s, a question understood in 3 to 5 s, all with nothing sent.
  • The numbers are always right, because the model never produces them.

What we learned

Small on-device models are good at language and unreliable at bookkeeping. Constrained output (a JSON schema with enums), matching answers by name rather than position, and refusing any figure the app did not supply make the difference between a demo and something you would trust with your money.

What's next for Clawback

PDF statements, more banks' CSV layouts, sending messages straight from the app with one click, and an Android version with Gemini Nano through the same Firebase AI Logic code.

How it was made (disclosure)

Built during the submission period, in November 2026, with help from Claude Code, an AI coding assistant. The statement reader, leak detection and page layout come from my earlier project Loose Change (open source, Apache-2.0, built on 16 Nov 2026, also during this submission period), which had no generative AI. Everything about Firebase AI Logic is new in Clawback: the on-device and cloud engine, consent and ledger, message drafting, model-based sorting, question reading, summaries and charge explanations. The sample statement is invented.

Built With

Share this project:

Updates

Submission history