Inspiration
Every tax season, freelancers sort hundreds of bank transactions into business and personal, by hand. The tools that could do it for them want a bank login or an uploaded statement, and a statement reveals who your clients are, what they pay you, and what you buy. So a lot of freelancers export a CSV and do it in a spreadsheet.
On-device models change that trade-off. If the model that reads the statement runs inside the browser, the statement never has to leave the laptop. We wanted to see how far that idea goes when you also need a cloud model for the things a small on-device model can't do well: writing, multi-turn chat, and reasoning across months.
What it does
Private Ledger does one job: turn a bank CSV into a clean list of business expenses for your accountant.
- Import a CSV in your currency. The importer reads the currency and the number format from the file itself (
Rp 85.000,1.234,56 €,DR/CRmarkers, Indonesian or German column names) and shows what it found before anything is saved. - Sort on the laptop. Saved rules handle transfers, payroll, and fees. Gemini Nano, through Firebase AI Logic in
ONLY_ON_DEVICEmode, sorts every other merchant into business or personal with a category. Results stream in one by one, and sorting works with Wi-Fi off. - Review the unclear ones. Coffee shops, marketplaces, airlines, food delivery, and cash withdrawals can be either, so they always come to you, including Indonesian and German merchants such as Tokopedia, Grab Food, and MediaMarkt. One key per decision, Z to undo, and the merchant is remembered next time. Remembered merchants can be inspected and forgotten without losing your transactions.
- Monthly summary from totals only. Cloud AI writes a plain-language summary from category totals and a currency code. You can open exactly what was sent.
- Ask the Advisor. A cloud chat model answers questions like "What is my biggest business cost?" It can't read your data: it asks your laptop through function calling, six functions run locally against IndexedDB, and only totals go back.
- Privacy check before anything is sent. A pasted statement line, a question that names a merchant from your data, or an amount next to a date ("on Oct 3 for 350") is stopped on the laptop and never sent. Rules run first, then Gemini Nano.
- Export for your accountant. A CSV of business transactions, created on the laptop.
A Privacy panel sits next to the work on every screen: transactions kept on the laptop on one side, and on the other the exact text of the last request that went to the cloud and a counter of transactions sent. Every number is computed from the Privacy Ledger, which records every AI task with its inference mode, model, size, duration, and the text that left. It can be exported as JSON.
How we built it
Every AI call goes through the Firebase AI Logic Web SDK. There are six model instances, one per inference configuration, and the inference mode of each follows the sensitivity of the data it handles:
| Feature | Inference mode | What it is given |
|---|---|---|
| Sort business or personal | ONLY_ON_DEVICE |
Bank transactions and the business profile |
| Privacy check on outgoing messages | ONLY_ON_DEVICE |
The chat message, before it is sent |
| What is this merchant? | PREFER_ON_DEVICE |
One cleaned merchant name; the cloud only with your OK |
| Monthly summary | PREFER_IN_CLOUD |
Category totals for one month and the currency code |
| Advisor chat with function calling | ONLY_IN_CLOUD |
Your question, and totals from local functions |
| Cloud sorting fallback | ONLY_IN_CLOUD |
One bank description per merchant, only after you agree |
SDK features in use: all four hybrid inference modes, with inferenceSource read from every response and written to the ledger (the label on each result comes from what the SDK reports, not from what the app expected); initializeDeviceModel() from a click, with download progress; structured output on both sides (responseConstraint for Gemini Nano, responseSchema for the cloud); on-device streaming; multi-turn chat with function calling where the functions execute in the browser; and App Check with reCAPTCHA Enterprise in production.
The cloud model is gemini-3.5-flash-lite on the free tier. Every cloud request has a 20-second timeout and retries with exponential backoff on 429, 500, and 503.
The rest of the stack: React 19, TypeScript, Vite, Tailwind CSS, Dexie on IndexedDB, and Firebase Hosting. There is no backend. A Content-Security-Policy limits connect-src to Firebase AI Logic, App Check, and reCAPTCHA, so the browser itself enforces the privacy line. A service worker generated at build time lets the installed app start offline. ESLint enforces the layering of src/lib (core logic, data, AI, state), and CI fails if an App Check debug token ever reaches a production bundle.
Challenges we ran into
- The model never says "unsure". Before writing the app we tested Gemini Nano on 40 synthetic rows. Clear rows were good (30 of 33), but 0 of 7 ambiguous rows were flagged, and a savings transfer and a warehouse club were sorted as business with high confidence. So the review queue is decided by rules and a mixed-use merchant list, not by model confidence.
- Latency. A non-streaming batch of 20 showed nothing for 27 to 36 seconds. Normalizing merchants, sorting each unique merchant once, batches of 10, and streaming brought the first result down to about 2 seconds.
ONLY_ON_DEVICEcan reach the cloud. In Firebase JS SDK 13.2.0, when the browser has noLanguageModelAPI, a model created withONLY_ON_DEVICEsends the request to the default cloud model. Every on-device call first passes our ownassertOnDeviceReady(), which refuses instead, and the ledger records it as "Not sent".PREFER_IN_CLOUDalso falls back on 429 and 503, not only offline. The totals were still sent in that case, so the ledger records both the cloud attempt and the on-device call.- A failed
sendMessagebreaks aChatSessionfor good. The advisor keeps its own history and builds a fresh session per request, so a timeout never corrupts the conversation. - Currencies. Amounts in two currencies can't be added without an exchange rate, and fetching rates would mean a network call. One ledger holds one currency, the decimal mark is decided from the whole column, and the cloud prompts tell the model never to convert.
Accomplishments that we're proud of
- A privacy line you can inspect, not a promise: zero transactions sent, counted from a ledger anyone can export.
- A cloud model that can answer questions about your money without ever seeing a transaction, through function calling that runs on the laptop.
- A full product flow (import, sort, review, summary, export) in plain language for freelancers, in light and dark, installable and usable offline.
- Statements in Indonesian and German bank formats import correctly, with the local number format and currency.
What we learned
Hybrid inference works best when the mode follows the data, not the feature list. The useful question for each feature was "what is this model allowed to see?", and the answer picked the mode. We also learned to trust what the SDK reports (inferenceSource) over what the code intended, and to put deterministic rules in front of a small model wherever a wrong answer would cost the user.
What's next for Private Ledger
- Android, with Gemini Nano through the same Firebase AI Logic hybrid API.
- Tax categories per country, starting with Indonesia and the EU.
- Multi-currency ledgers with exchange rates the user enters.
- A larger evaluation set for the privacy check, written independently of the rules.
Built With
- chrome-built-in-ai
- dexie
- eslint
- firebase
- firebase-ai-logic
- firebase-app-check
- firebase-hosting
- gemini
- gemini-3.5-flash-lite
- gemini-nano
- github-action
- indexddb
- node.js
- papaparse
- prompt-api
- pwa
- react
- recaptcha-enterprise
- service-worker
- tailwindcss
- typescript
- vite
