S-02 · CASE STUDY
Document extraction pipeline
Extracts structured data from long documents through an auditable, repeatable multi-stage pipeline.
Bull AI · Sep 2025 to now / Software Engineer, AI & Data Platforms
Python, LangGraph, Pydantic, PostgreSQL
TL;DR
A six-stage pipeline that extracts quarterly segment revenue from filings for about 3,000 listed companies, at 95 to 98% accuracy on a hand-checked sample.
The problem
Segment-level revenue for listed Indian companies sits inside PDFs such as annual reports, results filings and presentations, often as scanned tables and charts. It has to be extracted for about 3,000 companies every quarter, and it has to be right.
What I built
- 01A six-stage pipeline (retrieve, OCR, parse, discover, extract, validate) that works through about 3,000 listed companies across 18 to 19 sectors, one company at a time.
- 02It maintains roughly 5 to 7 years of quarterly segment-level revenue and related decision metrics for each company, fusing several data sources.
- 03The OCR backend underneath: self-hosted layout analysis turns each page into a semantic block graph, and only tables and charts go to a lightweight vision model.
- 04Extraction runs as an HTTP service with an engine pool, an admission queue, deadlines and graceful drain.
How it works
Architecture
- retrieve · 01
- parse · 02
- discover · 03
- extract · 04
- validate · 05
with: Step cache · Relational DB
Decisions that mattered
Send only what needs vision
Layout analysis decides which regions are tables or charts. Prose never reaches the vision model, which keeps cost and latency down.
Cache by content
OCR, vision and extraction results are content-addressed, so a rerun only redoes the steps whose inputs changed, and a run can be replayed from its stored artifacts.
Prompt changes are tested
Prompt and schema changes are checked by contract tests, and evaluation harnesses with tracing compare every change against a hand-checked sample.
Repair numbers, then validate
Strict output validation plus repair passes for periods, currency units and table totals. Cost and latency are recorded for every page.
Proprietary work. The approach and architecture are described; client data and code are not shown.