From 5cc1fe1ca7a01c1644fa168af171004fb1b0274f Mon Sep 17 00:00:00 2001 From: JasonFraser Date: Mon, 12 Oct 2026 19:54:03 -0400 Subject: [PATCH] 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. --- CLAUDE.md | 51 +++++++++++++++------ README.md | 56 +++++++++++++++++++++++ fixtures/ground_truth_sep_reference.xlsx | Bin 9943 -> 0 bytes 3 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 README.md delete mode 100644 fixtures/ground_truth_sep_reference.xlsx diff --git a/CLAUDE.md b/CLAUDE.md index e7582bb..856f89f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..65e1e71 --- /dev/null +++ b/README.md @@ -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 `_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. diff --git a/fixtures/ground_truth_sep_reference.xlsx b/fixtures/ground_truth_sep_reference.xlsx deleted file mode 100644 index 8f77c2a50f42c1d941b98e0f3b043af3ac79ccd0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9943 zcmeHt1y@|z(stt>++8}sJ-AzNcY@P6G#1b_gixll?M+?p96q}e*eGrU%UckNuA2w?C4=fvMrLyOt#g|V#wu- zrXAQ%IVh;;4oO&)^7u#>7dI@;B|er(?0rxpy?tzNaDQ5DXbxe4pB_uGe;K2Ts4ei} zpv2;6c;_w~L=>vk#fJu5goAuJyRn5V`Eq5E<#V@U;3g#-m z8V%Iy!nBje9yYk~1jl;WKc9E|ft);_nksy-dm2O+D4sHk8C0$_`1(>t0Xs4YTz<2a zNJ)-5q{yLb_lEa%r)QC5^J#r2$5FC8ZcVT~wS+G=hUszE`g_(g(M$uv9ccl2LoFMW zp+O}{eEJC_EL6L|`Ba*6Y1*3mZIO-l!3jkmA$D1xHoB#5>~8^ZD&xc0iHdKi`&wbh zn)c;t#v2J>rVY@!i9_J-rVrQSy9T_JSU8=qm78|%iot}PUIi#mjspUZupO#hRV1+T z!lvTgpWhB96h3~%mGo(+S0!H&TDF>EgR0l#BOE~WFC4AaVy8WWzEOly5Dm&vV;7LU zD;w+2=l{6*Urfk9O}#8pN#$SMybB+=oLP>?l2Gsvmu;rj^beFa9WUlpOW5++0`eQ83~Pp^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