Go to file
JasonFraser e4e43618b7 Route scanned/photographed statements through Docling OCR
The pipeline previously had no OCR path at all - pdfplumber has zero OCR
capability (confirmed by building an image-only PDF from a real statement
page and watching extract_text() return nothing), and the only guard
against that case raised a misleading error ("could not recognize this
statement's column layout") written for a different problem entirely.

reconcile._needs_ocr() now distinguishes "no text layer at all" (a scan
or phone photo - routes to _run_ocr_only(), Docling's OCR as the sole
canonical source) from "has text, but this extractor doesn't recognize
the bank's layout" (unchanged, same error as before). docling_client's
new ocr_table_to_rows()/ocr_extract_pdf() reshape Docling's OCR'd table
into the identical row format table_extract.extract_page() produces, so
rows_to_transactions/extract_statement_facts run completely unchanged on
OCR'd data rather than duplicating that logic for a second engine.

Column-role resolution (_resolve_columns, shared with the existing
cross-check path) is now collision-aware instead of first-match-wins:
excludes a field when a header cell's text genuinely contains vocabulary
from two different fields at once (caught a real Docling mis-segmentation
bug this way, on an RBC page), while still correctly resolving two
separately-clean columns that both legitimately match the same field
(HSBC has two real date columns) and not confusing "amount" nested inside
"credit amount" for contamination. Took two iterations against the real
fixture corpus to get both cases right at once.

An OCR-sourced extraction can never reach "Verified" (checks.py's new
check_ocr_source, always needs_review) - there's no second engine to
cross-check Docling's OCR against, so the safety property every other
check rests on doesn't hold here.

The upload UI now accepts .jpg/.png in addition to .pdf.

Real-world reliability is honestly unresolved, not assumed solved - see
CLAUDE.md's new "OCR / scanned statements" section for four real test
renders this session and exactly what did and didn't work. The routing
and reshaping logic itself is verified correct (confirmed through the
real running app, both a text-PDF upload and a raw-image upload); whether
a given scan or photo actually extracts anything depends on Docling's
own, inconsistent table-structure recognition on that specific image.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 09:04:24 -04:00
app Route scanned/photographed statements through Docling OCR 2026-10-11 09:04:24 -04:00
docs Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
fixtures Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
outputs Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
templates Route scanned/photographed statements through Docling OCR 2026-10-11 09:04:24 -04:00
uploads Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
zexample Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
.gitignore Route scanned/photographed statements through Docling OCR 2026-10-11 09:04:24 -04:00
CLAUDE.md Route scanned/photographed statements through Docling OCR 2026-10-11 09:04:24 -04:00
Dockerfile Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
UI_DESIGN_THEME.md Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
UI_DESIGN_THEME_ENTERPRISE.md Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
docker-compose.yml Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
requirements.txt Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00