Close the three Phase-1 loose ends: README, stray fixture, check findings

Add README.md - what the product is, docker compose up, project
layout, measure.py usage, pointer to CLAUDE.md for the deeper record.

Delete fixtures/ground_truth_sep_reference.xlsx - a bank-description
to accounting-category mapping from the separate bank_statement_
categorizer tool, not this product's own extraction ground truth, and
referenced nowhere in this repo. Nothing to repurpose it into, since
this product deliberately doesn't categorize transactions at all.

Investigate HSBC-Aug's running_balance failure and both fixtures'
engine_agreement findings - confirmed not extraction bugs. Built and
hand-verified fixtures/HSBC-USD-August2026_ground_truth.xlsx (all 31
transactions checked against the rendered PDF, including the Cancelled
wire and its two blank-balance rows) to prove it: 1.0 field accuracy.
The running_balance break is the Cancelled wire's -22,386.00 genuinely
not applying to the real balance chain - the check correctly flagging
that, not smoothing it over. engine_agreement on both fixtures is
Docling missing a table and pdfplumber's result being used instead,
exactly as designed, correctly flagged for lower confidence rather
than silently trusted.
This commit is contained in:
JasonFraser 2026-10-12 19:54:03 -04:00
parent da1b8b325e
commit 5cc1fe1ca7
3 changed files with 92 additions and 15 deletions

View File

@ -756,22 +756,43 @@ restructure; the behavior itself predates it and is unchanged:
(confirmed visually: the only balance figures on the statement are a
"Closing ledger balance brought forward" and "Current ledger balance" dated 01–02
Oct, outside the Sep 1–30 statement period, not this statement's own opening/
closing). `fixtures/HSBC-USD-August2026.pdf` still has no ground truth (only
Sep was built) — `measure.py` reports it (untouched pass only), which surfaced a
pre-existing, real problem: it currently fails `running_balance` (1 broken row)
and `engine_agreement` (Docling found no table on 3 of 4 pages) — not caused by
this work, but now visible and tracked instead of silent.
closing). `fixtures/HSBC-USD-August2026_ground_truth.xlsx` was built 2026-10-12
(see below) the same way — all 31 transactions visually confirmed page-by-page,
including the two blank-balance rows and the Cancelled wire around the
`running_balance` flag (also `None`/`None` opening/closing, same reason as Sep).
- [x] `git init` this repo — done 2026-10-11, initial commit `16f74f7`.
- [ ] Decide whether a `README.md` is wanted.
- [ ] `fixtures/ground_truth_sep_reference.xlsx` was discovered to be mismatched: it's a
bank-description→accounting-category mapping (Bank Description / Accounting
Description / Amount columns, 8 rows, no date or balance) — categorization data
from the separate `bank_statement_categorizer` tool, not this product's own
per-transaction extraction ground truth. It was left in place rather than deleted
unilaterally; decide whether to remove it or repurpose it.
- [ ] The HSBC-Aug and RBC `engine_agreement`/`running_balance` issues `measure.py` now
surfaces (above) aren't fixed — this harness's job was to make them visible and
regression-tracked, not to resolve them.
- [x] Decide whether a `README.md` is wanted — yes; added 2026-10-12. Short: what the
product is, `docker compose up`, project layout, `measure.py` usage, and a pointer
to this file for the deeper architecture/decision record. Doesn't duplicate
anything CLAUDE.md already covers in depth.
- [x] `fixtures/ground_truth_sep_reference.xlsx` was discovered to be mismatched (a
bank-description→accounting-category mapping from the separate
`bank_statement_categorizer` tool, not this product's own extraction ground truth)
and had nothing in this repo referencing it — deleted 2026-10-12 rather than
repurposed, since this product deliberately doesn't categorize transactions at all
(see "What this is" at the top of this file), so there was no use it could be put
to here.
- [x] The HSBC-Aug `running_balance`/`engine_agreement` and RBC `engine_agreement`
issues `measure.py` surfaces — investigated 2026-10-12, not extraction bugs.
HSBC-Aug's single `running_balance` mismatch is the Cancelled wire on page 3
(`-22,386.00`, no printed balance) doing exactly what "never silently correct or
exclude data" requires: its amount genuinely doesn't apply to the real balance
chain (it was cancelled), so the chain breaks by exactly that amount and the check
correctly flags it rather than smoothing it over - confirmed by rendering all 4
pages and reading every row against the extracted output (see the new ground truth
entry above), not just by eyeballing the mismatch in isolation; one other row on
page 4 that looked like a second anomaly at a glance (a balance that drops by
exactly the prior row's own $150,000 credit) turned out to be ordinary
newest-first chain math checked out correctly by the automated check, not a second
break. `engine_agreement` on both HSBC-Aug (Docling found no table on pages
[1, 2, 4]) and RBC (page 4, the same column-mis-segmentation bug documented under
"Docling spike finding"/the Architecture section's `docling_parser.py` note) is the
architecture working as designed - Docling missed a table, pdfplumber's own result
was used instead, correctly flagged `needs_review`/`fail` for lower cross-engine
confidence rather than silently trusted. Nothing to fix in either case - these are
real, correctly-surfaced statement/engine conditions, confirmed by building the
missing ground truth (HSBC-Aug) and getting 1.0 field accuracy on it, same as the
other two fixtures now that the RBC footer bug above is also fixed.
Nothing else from the original Phase 1 step list (scaffold, Docling spike, extractor,
reconciler, pipeline, checks, UI, Excel export) is outstanding — those are built. Phases

56
README.md Normal file
View File

@ -0,0 +1,56 @@
# Bettersight Statement Extractor
Turns a bank statement PDF (or a scanned/photographed one) into clean, structured
transaction rows, proves the arithmetic against seven automated checks, and exports to
Excel. Supports HSBC and RBC statement layouts today, auto-detected rather than
hardcoded per bank.
This is Phase 1 of the planned Bettersight product line - extraction + checks + export
only. It deliberately does **not** categorize transactions (bank description →
accounting description). See `CLAUDE.md` for the full architecture, the phase roadmap,
and the reasoning behind most of the non-obvious decisions in this codebase.
## Running it
```bash
docker compose up --build # start everything (app + Docling), foreground
docker compose up --build -d app # rebuild + restart just the app after a code change
docker compose down # stop and remove both containers
```
Then open http://localhost:8091.
For frontend development with hot reload: `cd frontend && npm run dev` (Vite, proxies
`/api` to the backend container) alongside `docker compose up` for the backend/Docling
containers.
## Project layout
```
backend/ Flask API - routes -> services -> repositories -> schemas
frontend/ Vue 3 + Vite SPA - views -> components -> composables -> services
fixtures/ Real statement PDFs + hand-verified ground truth, for measure.py
docs/ Reference material and test files not part of the measured corpus
results/ measure.py's own dated JSON reports (gitignored)
```
## Measuring accuracy
```bash
python3 backend/measure.py
```
Runs every `fixtures/*.pdf` with a matching `<name>_ground_truth.xlsx` through the real
extraction pipeline and reports two numbers: the untouched pass rate (statements that
reach "Verified" with zero edits) and field accuracy (date/description/amount/balance,
compared row-by-row against hand-verified ground truth). A fixture without ground truth
is still run and reported, just without a field-accuracy score. Works with or without
the Docling container up - degrades to pdfplumber-only per page if Docling is
unreachable, the same fallback behavior the live app has.
A fixture's statement can legitimately land on "Failed" or "Needs review" even with
100% field accuracy - that's a check correctly flagging something real about the
statement itself (a cancelled transaction, disagreement between the two extraction
engines on a given page), not an extraction error. `measure.py`'s field accuracy is
what tells you whether the data is actually right; the pipeline status is a separate
signal about how much automated confidence that statement earned.