# Case Study: Lekhavo's Bank Statement Parser | Tembrant

> How Tembrant built the statement parser behind Lekhavo: per-layout parsers, balance checks against printed figures, and held imports when a statement won't tie.

Source: https://tembrant.com/case-studies/bank-statement-parser
Last updated: 2026-11-21

[Finance](https://tembrant.com/finance) / [Case studies](https://tembrant.com/finance#case-studies) / How we built Lekhavo's bank statement parser

# How we built Lekhavo's bank statement parser

A parser for 16 Indian banks that proves each statement against its own printed balances before a single row reaches the books.

Published November 21, 2026 · Updated November 21, 2026

On this page

* [The problem](#the-problem)
* [The approach](#the-approach)
* [How failures surface](#how-failures-surface)
* [Architecture at a high level](#architecture-at-a-high-level)
* [What it supports today](#what-it-supports-today)

## The problem

[Lekhavo](https://tembrant.com/products/lekhavo) is our bookkeeping and practice software for Indian chartered-accountant (CA) practices. Everything it does, from double-entry ledgers to reconciliation, depends on the first step: reading the bank statement. If a statement is read wrong, the ledger is wrong, and nobody notices until the books refuse to close.

Indian bank statements make that first step hard:

* A practice receives statements from large private and public-sector banks and from small co-operative banks, as PDF, CSV and Excel exports.
* One bank can have several PDF layouts in circulation at once.
* Some layouts glue text so tightly that a naive extractor merges amounts into the narration.
* Many PDFs are password-protected.

Nobody can check thousands of rows by eye, so the parser had to check itself.

## The approach

### A parser per layout

Each layout has its own parser class, registered with the bank names it handles. When a file arrives, every parser that can read its file type scores it, and the highest score wins. Ties break by a fixed order, so the same file always goes to the same parser. A file nothing recognizes is rejected as an unsupported statement rather than guessed at.

### Reading position, not just text

For PDFs, words are extracted with their coordinates. A production adapter combines three PDF libraries: one for glyph positions and font metrics, one for vector paths and rotated text, and one for rebuilding words and tables. Columns are found by clustering the right edges of right-aligned numbers, and a token only becomes an amount if it snaps to an amount column. That rule keeps fragments of payment reference numbers, which often sit near the amount columns, out of the figures.

### The statement’s own figures as the check

A correctly parsed statement balances. Each running balance equals the previous one plus the row’s signed amount, and the opening balance plus every amount equals the closing balance. These two rules catch a deposit read as zero, a withdrawal with the wrong sign or a shifted column, without anyone reading the numbers.

The parsers go further where the bank prints more:

* **Printed summaries.** One bank’s layout prints opening and closing balances, debit and credit totals, and transaction counts. Its withdrawal or deposit column can be so sparse that the direction of some amounts is lost. The parser proposes directions from the running-balance deltas, but applies them only if the result reproduces every printed figure exactly. If it doesn’t, the statement is left unbalanced for the checks to catch.
* **Page carry-forwards.** Another layout prints brought-forward and carried-forward balances on each page. The parser takes the statement’s opening from the first page and its closing from the last, so a page’s own carry-forward is never mistaken for the statement’s figure, and it logs a warning when rows don’t match the printed debit or credit totals.
* **Failed transactions.** Rows the bank marks as failed are kept, flagged, with a zero signed amount, so they stay visible without breaking the balance.

### Tests that re-parse real statements

The regression suite re-parses every real statement fixture through the live parser on each run, not a saved snapshot. For every statement it checks per-row continuity in whichever direction the bank sorts, oldest-first or newest-first, and then opening plus amounts against closing. The test allows one rupee of slack for rounding in the source documents.

Some statements don’t reconcile because the bank’s own PDF is inconsistent. One compact layout prints a lagging running balance for clusters of same-day credits. Those fixtures are marked as not reconciling, with the reason written next to them, so the exception is documented instead of hidden.

## How failures surface

The parser runs as its own service, and Lekhavo does not take its word for quality. On import it recomputes the gap: opening balance plus every transaction minus closing balance, in exact paise. The rule for writing to the books is an exact zero, not the one-rupee tolerance used for display.

If the gap isn’t zero, or the statement has no transactions, the import is held. A held import keeps the gap, the parser name and version, and the reasons. Its transactions are not committed. A reviewer can accept it, reject it, or request a reparse once the parser is fixed, and each decision goes into the audit trail.

Two more checks follow:

* **Duplicates.** Each transaction is fingerprinted by account, date, amount and normalized description, plus its position among identical rows. Re-uploading a statement, or uploading two that overlap, adds nothing, while two genuine identical payments on one day are both kept.
* **Boundaries between statements.** For each account, Lekhavo compares each statement’s printed opening and closing with the balance it derives from the books. An account is marked verified, mismatch or assumed. An opening and closing of 0.00 with transactions in between is treated as a parsing placeholder and marked assumed, not trusted.

## Architecture at a high level

* **Parsing library.** Python, typed models with decimal amounts, and a registry of per-layout parsers.
* **Parser service.** An HTTP API for document jobs. Files upload through presigned object-storage URLs, job creation takes an idempotency key, results are fetched or delivered by signed webhook, and statement passwords are encrypted when stored. Each parse runs in its own child process under a hard time limit, and library error messages are never passed back, since they can contain document content.
* **Queues and hosting.** Jobs live in PostgreSQL queues with leases and retries. In production the API and the queue workers run as two services built from one image, so a long parse never takes API capacity.
* **Lekhavo.** Recomputes quality, holds imports, deduplicates and posts to the ledger.

The service also reads Form 26AS and NCD schedules. The NCD workflow is covered in the [NCD interest and TDS case study](https://tembrant.com/case-studies/ncd-interest-tds-reconciliation).

## What it supports today

* **16 Indian banks**, including three co-operative banks, across PDF, CSV and Excel exports. Coverage per format varies by bank: some are PDF-only, one is Excel-only.
* Several PDF layouts for some banks, and password-protected files.
* File types .pdf, .csv, .xls and .xlsx.

The supported banks are Indian. The approach (a parser per layout, positional extraction, balance and summary checks, held imports) carries over to other countries’ statements, but each new bank and layout needs its own parser and real samples to test against. Our [bank statement parser development](https://tembrant.com/bank-statement-parser-development) page covers how we do that for clients, and the [extraction accuracy guide](https://tembrant.com/guides/bank-statement-extraction-accuracy) sets out the checks on their own.

To discuss a parser for your banks, [get in touch](https://tembrant.com/contact).

## Related

* [Custom bank statement parser development](https://tembrant.com/bank-statement-parser-development)
* [How to validate bank statement extraction](https://tembrant.com/guides/bank-statement-extraction-accuracy)
* [Lekhavo](https://tembrant.com/products/lekhavo)
* [How we built Lekhavo NCD: issuer interest workbooks to one checked file per client](https://tembrant.com/case-studies/ncd-interest-tds-reconciliation)

## Have financial data that has to tie out?

Tell us what you want to build. We reply with questions, a plan and an estimate.

[Start a project](https://tembrant.com/contact)

![](https://tembrant.com/emblem.webp)
