Inspiration
International students in Germany get official letters in German: the broadcast fee office, the Ausländerbehörde, the health insurance, the landlord. Ayesha, our illustrative persona, moved from Lahore to Munich to study. One letter looked like advertising, so she ignored it, and later paid a late fee. Translating it wasn't the problem. Knowing what it wanted from her, and by when, was. And she didn't want to paste her name, address, date of birth and bank details into a chatbot to find out.
That's a perfect fit for hybrid inference: the letter is personal, so it should be read on the device; but explaining it in Urdu or Arabic needs a bigger model in the cloud. LetterLens uses both, and makes the boundary visible.
Who it's for
International students and newcomers in Germany who receive official letters they can't fully understand. LetterLens turns a letter into one clear next step: the deadline, the amount and what to do, each linked to the sentence in the letter, private by default.
What it does
- Reads the letter on your device. Take a photo, paste the text or try a fictional sample. OCR runs in the browser, and Gemini Nano in Chrome extracts the letter type, sender, deadlines, amounts and next steps.
- Shows where each answer comes from. Click a deadline or amount and the exact sentence lights up in the letter. Every field is checked against the letter text: Found in letter, or Please verify with the reason (for example, a date calculated from "within 14 days" rather than printed).
- Your letter never leaves your device without your approval. Without a local model, LetterLens asks first, removes personal details, and shows exactly what would be sent.
- Explain more: a plain explanation in Urdu, Arabic, Turkish or English (right-to-left where needed) plus a polite German reply draft. It runs in the cloud, so it shows the redacted text side by side with your letter and asks every time. Your details are put back into the answer on your device.
- Checklist of next steps, made on the device when possible.
- Deadlines: add to your calendar (.ics or Google Calendar) and save to a private list. Only the date, title, sender, amount and letter type are stored, never the letter.
- Works offline after the first visit: the letter is still read with OCR and Gemini Nano with Wi-Fi off.
- Honest about where things ran: an On-device / Cloud · details removed badge comes from the SDK's
inferenceSource.
How we built it
A React + TypeScript web app for Chrome on desktop. Everything runs client-side through Firebase: no backend server, no Cloud Functions.
Firebase AI Logic hybrid inference, with an explicit mode per task:
- Understanding the letter, on device:
InferenceMode.ONLY_ON_DEVICE(Gemini Nano). The OCR text never leaves the device. - Understanding the letter, no Nano:
ONLY_IN_CLOUD(gemini-3.5-flash-lite), only with the redacted letter and only after the user approves. - Explain more + German reply:
ONLY_IN_CLOUD(gemini-3.7-flash), with the redacted letter, after the user sees it and approves, every time. - Checklist:
PREFER_ON_DEVICE, the automatic hybrid mode. Its input is only the letter type, dates, amounts and actions (redacted), never letter text.
We deliberately don't use PREFER_ON_DEVICE for reading the letter: on a device without the model it would silently send the unredacted letter to the cloud. We also found that ONLY_ON_DEVICE alone doesn't stop a cloud call when Chrome's Prompt API is missing, so the app checks that Nano is ready before every on-device call and treats any on-device error as "ask the user", never as an automatic fallback.
Validation layer. Every model output is checked before display: the date must be real and in a sensible range, the quoted sentence must be found in the OCR text (exact or within 10 % edit distance, mapped back to the original for highlighting), the date must appear inside its quote, and the amount must appear inside its quote in German or English notation. Failed fields are never hidden; they're marked Please verify.
Two-layer redaction, on the device. Layer 1 is deterministic: the user's own name and address from Settings (stored only in this browser), names after Frau/Herr/Herrn, IBANs (also with OCR errors), emails, phone numbers, reference numbers, and dates of birth after "geb." / "geboren am" / "Geburtsdatum". No other date is removed, so deadlines survive. Layer 2 adds the personal details Gemini Nano found, each checked against the OCR text first. Placeholders like [NAME_1] are filled back in locally; the redaction map lives only in memory for one request.
Firebase products: App Check (reCAPTCHA Enterprise) for every AI call; anonymous Authentication; Firestore with security rules that accept only the metadata fields of a deadline (keys().hasOnly([...])), so letter text can't be stored even by a bug; Remote Config for model names and prompt text (validated, never able to change where data goes); Firebase Hosting with a service worker that caches only the app's own files and a self-hosted Tesseract, never AI answers or database data.
Privacy rules as tests. The privacy audit runs as automated tests that scan the source: PREFER_* only in the checklist model, no runtime caching, an allow-list of storage keys, Firestore writes only in one module, no console.log of letter content, no raw HTML, cloud calls only from the hooks that hold consent, and redaction maps never passed to state, storage or logs. 217 unit tests in total.
Challenges we ran into
- Small models get dates wrong in plausible ways: a real sentence paired with the letter date instead of the deadline, or "within 14 days" miscounted. Checking that the date is written inside its quote catches most of it, and calculated dates are always flagged.
- Privacy vs. fallback. The convenient hybrid mode would have sent unredacted letters to the cloud on devices without Nano. Explicit routing plus a readiness check fixed it.
- Cloud answers quote the redacted text ("Beitragsnummer [ID_1]"), so they never matched the original letter until we restored placeholders before validating.
- Offline and App Check: if the page is opened offline, App Check's token requests hang for the whole page load, so cloud features ask for a reload instead of hanging.
- Right-to-left text reverses spaced numbers. In Urdu and Arabic, "512 345 678" was displayed as "678 345 512", a wrong payment reference. We isolate those numbers left to right.
- OCR breaks patterns. Our own sample's IBAN was read as "DEOO …" and slipped past the IBAN rule, so the rule now accepts the characters OCR confuses.
Accomplishments that we're proud of
- The letter is read with Wi-Fi off, privately, with every field linked to its source sentence.
- Your letter never leaves your device without your approval, and you see exactly what would be sent first.
- The privacy rules aren't just documented: Firestore security rules and automated tests enforce them.
- One click from the first screen to a real result.
What we learned
- Hybrid inference is most useful when you choose the mode per task and per data sensitivity, not per app.
- A small on-device model is good at structure, but it needs a deterministic validation layer to be trustworthy.
- We believe showing people exactly what is sent is what makes AI acceptable for personal documents, so we made that preview the centre of the cloud path.
What's next
- More letter types and more explanation languages.
- Android with Gemini Nano and iOS with Apple Foundation Models, using the same routing and redaction through Firebase AI Logic.
- Reminders before deadlines, and sharing a deadline with a friend or advisor without the letter.
Try it
Open the hosted app in Chrome on desktop and click Try a sample letter (all samples are fictional). With Gemini Nano enabled (Chrome 149+, chrome://flags/#prompt-api-for-gemini-nano-multimodal-input), the letter is read on-device. Without it, LetterLens asks for approval and uses the cloud with personal details removed. On a phone, the cloud path runs.
Known limitations: a page opened offline needs a reload before cloud features work; heavy OCR damage can stop a quote from matching (the field shows Please verify); Explain more always needs the cloud.
Built With
- chrome-built-in-ai
- cloud-firestore
- date-fns
- firebase
- firebase-ai-logic
- firebase-app-check
- firebase-authentication
- firebase-hosting
- firebase-remote-config
- gemini
- gemini-nano
- javascript
- pwa
- react
- recaptcha-enterprise
- shadcn-ui
- tailwindcss
- tesseract.js
- typescript
- vite
- workbox