Tax Document Extraction Pipeline
Problem
Preparing a Seller's Discretionary Earnings (SDE) workbook from tax returns means manually reading IRS PDFs — across many form types, some of them scanned — and copying line items into a spreadsheet. It's slow, error-prone, and hard to audit, and a single misread digit can throw off the financials.
Approach
An end-to-end pipeline that turns raw tax-return PDFs into a populated, validated workbook:
- Classification — identifies IRS form types per page (1065, 1120-S, 1120, Schedule C, 1125-A, Schedule L, statements).
- Extraction — deterministic regex extractors per form, with an GPT-4o multimodal fallback for ambiguous pages and attached statements; Tesseract/docTR OCR handles scanned pages.
- Mapping — converts canonical data into cell-write instructions for the correct year column.
- Validation — runs arithmetic identity checks (e.g. Sales − COGS = Gross Profit) and assigns per-field confidence scores, flagging low-confidence fields for human review.
- Output — writes to a macro-preserving
.xlsmtemplate, exports JSON for audit, and generates a review report.
It ships as a PySide6 desktop app with Dropbox sync, configurable OCR/LLM/confidence thresholds, background processing, and a one-shot Windows packaging path (PyInstaller + Inno Setup) that bundles a portable Tesseract runtime to run fully offline.
Results
- Hands-off extraction with a confidence-driven review step instead of full manual entry.
- A self-contained Windows installer whose default OCR engine works offline — no first-run downloads or proxy/SSL headaches.
- A JSON audit export and flagged-field report for traceability on every run.
Learnings
- Pair deterministic extractors with an LLM fallback — cheap and reliable on the common case, robust on the messy tail.
- Arithmetic identities are a powerful, almost-free validation signal for financial documents.
- Cross-platform OCR parity (Windows vs Linux digit accuracy) hinges on the
traineddataquality and preprocessing, not the Python code.
Technical Stack
Key Metrics
Performance: Classification → extraction → validation pipeline
Impact: Automated IRS-PDF → SDE workbook with audit trail