Case study

Know Your Letter: official letters, explained in plain Sinhala, Tamil or English

Photograph a letter from a bank, a government office or a lawyer and get what it says, what to do and by when, in your own language. Free, and nothing from the letter is kept.

  • Oct 2026
  • Personal project · Applied AI
Screenshot of Know Your Letter
languages, switchable without re-reading the photo
3languages, switchable without re-reading the photo
pages per letter, in one model call
4pages per letter, in one model call
unit tests, no network needed
88unit tests, no network needed
letters stored or logged
0letters stored or logged
01

The problem

Many people in Sri Lanka receive letters they cannot fully read: a bank notice in English, a government letter in formal Sinhala, a lawyer’s demand, or a letter from an employer abroad. Missing what a letter asks for, or by when, can cost money. Asking someone else to read it means showing them private details.

The goal was one screen on a phone: take a photo, and get what the letter is, what it says, what to do and the deadline, in the reader’s own language. Three things made this harder than calling a model. A wrong amount or date is worse than no answer. A scam letter must never be called genuine. And a letter holds identity and account numbers, so the app has to be trustworthy with them.

02

Architecture

A Next.js app on Vercel. Everything that can run on the phone does, the server makes one call to a vision model, and a small Redis store holds only counters.

On the phone

  • Photos

    Shrunk in the browser to 2000 px JPEG

  • PDFs

    Turned into page images with pdf.js; the file and its password stay on the device

  • Read aloud, share, calendar

    Device voices, share sheet and .ics file, no server call

Next.js API on Vercel

  • /api/explain

    Checks pages, applies the hourly limit, one model call

  • /api/translate

    Translates the text, then checks every number

  • /api/ask

    Answers from the letter itself

  • Clean-up

    Validates the JSON, masks NIC, card and IBAN numbers

Services

  • Ollama Cloud

    Gemma vision model, constrained to a fixed JSON schema

  • Upstash Redis

    Hourly counts under a hashed visitor key, and yes/no votes by letter type

The server logs only the type of an error and how long the request took. A helpful vote stores the kind of sender (bank, utility and so on) and yes or no, nothing else.

03

What happens to a letter

From the photo to the explanation, with a check at each step.

  1. 1

    Prepare on the phone

    Up to four pages are shrunk until they fit together under 3.8 MB, safely inside Vercel’s 4.5 MB request limit, so uploads stay quick on mobile data.

  2. 2

    Check and limit

    The server validates the images and takes one of three letters an hour for that visitor. The visitor’s address is HMAC-hashed before it is stored, and the store forgets it once the hour has passed.

  3. 3

    One model call

    All pages go to Gemma with the prompt in a single call, and the model must fill a fixed JSON schema: what the letter is, what it says, steps, deadline, scam signs, difficult words. The server stops waiting after 55 seconds.

  4. 4

    Clean and protect

    The reply is checked field by field. Country and language must be real codes from fixed lists, and identity, card and bank numbers the model repeated are masked to their last four characters.

  5. 5

    Switch language safely

    Changing language sends the explanation’s text, not the photo, to be translated. Dates never go to the model, and if any number in the translation differs from the original, it is thrown away and the photo is read again in the new language.

04

Decisions and trade-offs

01

A fixed JSON schema instead of free text

The page shows the same sections in the same order every time, and the server can check each field: dates, codes, lists of words. Free text could not be checked or translated safely.

Trade-offThe model does not always keep to the format. Once it sent a single word as an object instead of a list, so the parser accepts several shapes.

02

Translate the explanation, not the photo

Translating text takes about 5 seconds and costs far less than reading the photo again, which takes about 20.

Trade-offA translation can change a number, so every one is checked and some are rejected, which falls back to the slower path.

03

The app never says a letter is genuine

The model lists only the signs of a fake it can actually see. When there are any, the page shows advice written by the app (don’t pay, don’t share a PIN or OTP, call the official number), not by the model.

Trade-offA worried reader of a real letter gets no reassurance from the app, only the advice to check with the sender.

04

Keep nothing from the letter

People photograph letters full of personal details. The privacy promise has to be true by design, not by policy.

Trade-offReal failures cannot be reviewed afterwards, so accuracy is checked on a separate set of test letters run through the model.

05

Serverless and free tier

The app is free to use, so it runs on Vercel’s Hobby plan and Upstash’s free Redis, with no server to maintain.

Trade-offRequests are size and time limited, which is why photos are shrunk on the phone and the model gets 55 seconds.

05

Results

  • Version 2 is live: one to four photos or a PDF in, an explanation out, switchable between Sinhala, Tamil and English.

  • Checked against the real model with a sample English bank letter in all three languages. Two lessons from that run are built in: the prompt asks for the letter’s official wording explicitly, and the parser accepts the looser shapes the model sometimes sends.

  • Difficult official words are listed with plain meanings in the reader’s language and underlined where they appear, allowing for how Sinhala and Tamil words change their endings.

  • 88 unit tests cover the clean-up, masking, translation checks, rate limiting, calendar files and word matching, and run without a network.

06

What I'd do next

Some of version 2 has only been tested with a stand-in for the model. Before saying it works, I want to:

  1. 01

    Run real letters from abroad, in Arabic, Korean and other scripts, through the model. Support for them is built and unit-tested, but not yet proven on real letters, or within 55 seconds for four pages.

  2. 02

    Have fluent speakers check the Sinhala and Tamil country names and word meanings.

  3. 03

    Find which check rejects English-to-Sinhala translations of the sample letter, which forces the 20-second fallback.

  4. 04

    Count "days left" in the reader’s own time zone, not Sri Lanka’s, so readers abroad are never a day out.

Built with

  • Next.js
  • React
  • Gemma (vision LLM)
  • Ollama Cloud
  • JSON Schema
  • pdf.js
  • Upstash Redis
  • Vercel
  • Web Speech API
  • Node test runner

© 2026 Kalhara Tennakoon. All Rights Reserved.