All projects
Project / Case study

Tax Document Extraction Pipeline

Turning raw IRS PDFs into validated earnings workbooks through OCR, deterministic extraction, and an LLM fallback, with confidence-based review and a clear audit trail.

  • OCR
  • LLM
  • Document AI
  • Automation

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:

  1. Classification: identifies IRS form types per page (1065, 1120-S, 1120, Schedule C, 1125-A, Schedule L, statements).
  2. Extraction: deterministic regex extractors per form, with an GPT-4o multimodal fallback for ambiguous pages and attached statements; Tesseract/docTR OCR handles scanned pages.
  3. Mapping: converts canonical data into cell-write instructions for the correct year column.
  4. Validation: runs arithmetic identity checks (e.g. Sales − COGS = Gross Profit) and assigns per-field confidence scores, flagging low-confidence fields for human review.
  5. Output: writes to a macro-preserving .xlsm template, 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 traineddata quality and preprocessing, not the Python code.

Keep exploring