Generative AI · Planned
Document AI for structured data extraction
A pipeline that turns invoices and forms into validated structured data using OCR and an LLM with typed schemas, measured field by field.
Planned project. This page describes the goal, the approach, and how the system will be evaluated. Code, a live demo, and results will be published here once it is built.
At a glance
Solo project: OCR pipeline, LLM extraction, validation, and API
- Problem
- Turn scanned invoices and forms into structured records a downstream system can trust.
- Planned approach
- OCR with layout preserved, LLM output constrained to a Pydantic schema, and arithmetic and format checks on every record.
- Design decisions
- Schema-validated output, so malformed responses are caught instead of stored.
- Fields that fail validation go to a review queue rather than being guessed.
- Evaluation plan
- Field-level precision and recall on a labelled document set, the straight-through rate, and cost per document.
Goal
Extract fields such as vendor, dates, totals, and line items from scanned invoices and forms, and return data a downstream system can trust. The output has to be valid against a schema, and every field the model is unsure about has to be marked for human review rather than guessed.
Planned approach
- Ingestion. Accept PDFs and images, run OCR where there is no text layer, and keep the page layout so tables stay readable.
- Extraction. Ask an LLM for output that matches a Pydantic schema, so every response is validated and typed.
- Validation rules. Check the arithmetic, such as line items summing to the total, and date formats. Records that fail go to a review queue.
- Serving. A FastAPI endpoint that accepts a document and returns the extracted record with a status for each field, stored in PostgreSQL.
Evaluation plan
- A labelled document set with the correct value for every field.
- Field-level precision and recall, reported per field, because a pipeline can be excellent on dates and poor on line items.
- Straight-through rate: the share of documents that pass every validation check without human review.
- Cost and latency per document.
Definition of done
A public repository, a demo, a per-field results table, and a write-up of the document types that still need review.