← All work

Tax CPA Parser

Document intelligence for variable tax documents — 10K+ pages/month

Role
Primary Engineer
Timeline
Oct 2025 – Dec 2025
Context
OctonData · San Francisco (remote)

The outcome

  1. 10K+ pages processed per month, end to end.
  2. Onboarded 10+ U.S. CPA firms, cutting manual review time by 40%+.
  3. Long-document RAG accuracy up 20–30% via semantic, recursive and hybrid chunking.
  4. Extended od-parse, the in-house parser, from PDF/image to Excel, DOCX, PPTX and CAD vector formats behind a router with vector-vs-raster PDF triage, shipped as a Dockerized FastAPI service.
  5. Built od-parse's mechanical-drawing pipeline: Roboflow detection, batched Gemini multimodal verification in a single call per drawing, and a full-image rescan recovering annotations the detector missed.
  6. Grounded a CrewAI tax-analysis crew (return analyzer, IRS code researcher, strategy analyst) on the extracted case data.

The challenge

A production document-intelligence service that turns a client's folder of tax paperwork into schema-checked JSON a CPA can review, at 10K+ pages a month. It sits behind a case-management app on GCP: the app takes uploads, the processor parses, classifies and extracts each document, and the results come back by webhook. Tax paperwork is the hard case for parsing, because the same logical form arrives as a clean PDF, a phone photo or a scan, often bundled with other forms in one file.

CPA firms were reviewing every page by hand because no single extraction method survives real tax documents. A text-layer parser is fast but returns garbage on PDFs with broken font encodings. A vision model reads anything but is slow and costly to run on every page. And an LLM that can't see the data will still return a confident, well-formed answer.

The system

Two services, split so a slow parse never holds a web request. The case app (Flask on Cloud Run) writes uploads to Cloud Storage and a row to a processing_jobs table in Cloud SQL; that table is the only source of truth for where a document is. A scheduler worker polls every 30 seconds, posts pending jobs to the processor fire-and-forget with a callback URL, and a timeout sweep every two minutes moves stuck jobs back to retrying, up to three attempts. The processor (FastAPI, also on Cloud Run) routes each file by what it actually is: small PDFs take a local fast path, larger ones go through od-parse in 15-page chunks, and a PDF whose text comes back as CID codes or near-empty is re-read by Gemini vision, fast model first and the premium model only when a quality check fails. The markdown is PII-redacted, split at form boundaries when one file holds several forms, then sent to Gemini with a schema chosen by form type (W-2, 1040, 1040-NR, generic otherwise). Results land as JSON in Cloud Storage and a document row in Cloud SQL, and a webhook marks the job done. Anything that fails a guard is written out as a typed error artifact rather than as data.

processing_jobsPOST + callbackCID / empty textmarkdownpage textone form eachJSONplaceholderswebhookCPA Co-Pilot APIFlask · uploads to GCSJob WorkerAPScheduler · 3 attemptsFormat Routerfast path · od-parseTiered Vision OCR2.0-flash → 2.5-proForm SplitterPII redact · page boundsGemini Extractionschema per form typeCase StoreGCS JSON · Cloud SQLError Artifacttyped, not data
Tax CPA Parser — job lifecycle and per-document extraction path

The hard parts

  1. Choosing the extractor per file, not per pipeline

    Every extractor had a document class it failed on, so the router decides per file and checks the output before trusting it. PDFs under 800 KB and six pages take a local fast path; larger ones go through od-parse, split into 15-page chunks above 50 pages. The output is then scanned for CID codes, the signature of a font the text layer can't decode. Those files are re-read by Gemini vision, which skips IRS instruction pages, tries gemini-2.0-flash first and escalates to gemini-2.5-pro only when word counts, CID ratio and tax patterns say the read was poor.

  2. A model that can't read the page invents a taxpayer

    When text extraction upstream failed, the LLM didn't return an error. It could return a well-formed record filled with John Doe, 123-45-6789 and other template values. The extraction step now checks responses for known placeholder values and raises a typed error instead of saving them. The error is written as its own JSON artifact next to the case's outputs, so a CPA sees a failed document, not a fake one.

  3. One upload, several forms

    Clients scan a W-2, a 1040 and its schedules into one PDF, and a single extraction call returns one muddled record. The processor detects form boundaries from page headers, keeps only boundaries scored at 0.65 confidence or above, and cuts the PDF into page ranges that are each parsed and extracted against their own schema. Instruction pages and segments too thin to be a real form are dropped before any model call.

  4. Rate limits reshaped the chunking strategy

    Gemini started returning 429s, and the cause was upstream of the API layer: chunking produced many small pieces and each piece was a call. The fix was a hard ceiling of three chunks per document, with chunk size doubling until the count fits. Semantic splitting moved to Chonkie on local all-MiniLM-L6-v2 embeddings, so chunking costs no API calls, with a 15-sentence minimum per chunk and a semaphore capping parallel calls. Recombining chunks became a per-type rule: invoice totals take the maximum because the same total repeats across chunks, bank statements concatenate transactions and medical records merge by date.

  5. Domain semantics that no general parser knows

    Documents were being filed under the wrong year, and the extraction was correct every time. A 1040 belongs to the tax year it's filed for. A W-2 for that tax year is issued the following calendar year and is filed under the issuance year. An identity document belongs to the year it was processed. The year became a per-document-type rule, with the original filename as a hint and a guaranteed fallback so a missing year can't block the pipeline.

What I took from it

  • Fix rate limits at the layer that causes them. The 429s looked like an API problem and were a chunking problem; retry logic alone would have made them slower and permanent.
  • The dangerous failure is the plausible one. A placeholder taxpayer and an invoice total summed across chunks both look like real data, and nothing downstream flags either. Guards have to sit where the plausible-but-wrong value is produced.
  • Domain rules don't appear in the data. Nothing in a W-2 says it belongs under its issuance year rather than its tax year; that came from understanding how firms actually work.
  • Keep job state in one table and let everything else be stateless. With the processor fire-and-forget and a timeout sweep doing the retries, a crashed Cloud Run instance costs one retry, not a lost document.

Stack

Document AI
od-parse, PyMuPDF, Tesseract, Gemini 2.0 Flash / 2.5 Flash / 2.5 Pro, Roboflow
Chunking
Chonkie, all-MiniLM-L6-v2, Gemini embeddings
Services
FastAPI, Flask, APScheduler, Prefect, LlamaParse, CrewAI
Cloud
Cloud Run, Cloud SQL (PostgreSQL), Cloud Storage, Cloud Build, Docker

Timeline

  1. Oct 2025

    Joined OctonData as primary engineer on document intelligence.

  2. Oct – Dec 2025

    Hybrid parsing pipeline and chunking strategies.

  3. Dec 2025

    10+ CPA firms onboarded in production.

Download resume