Invoice & Contract Intelligence
A backend-first AI system that turns messy invoices and contracts into reliable structured data: parsing, OCR fallback, document classification, multimodal LLM extraction, validation, confidence scoring, human review, and JSON/CSV export. Currently in the foundation phase, built in reviewable increments.
- ROLE
- Backend / AI Engineer
- CONTEXT
- Independent
- DURATION
- Ongoing
- YEAR
- 2026
Build status
- FoundationDone
Repo, environment, dependencies, FastAPI entrypoint, health endpoint, Pydantic settings
- Persistence baselineDone
PostgreSQL connection layer and initial migration structure
- Storage layoutDone
Local document storage outside source folders, normalized filenames, configurable location
- Upload & jobsIn progress
Upload endpoint, document metadata model, Redis worker baseline, job status lifecycle
- Parse & OCRQueued
PDF text and layout extraction (pdfplumber / PyMuPDF), OCR fallback for scanned documents
- Classify & extractQueued
Invoice / contract / unknown classification, multimodal LLM extraction to structured JSON
- Validate & scoreQueued
Schema validation, normalization, business rules, and field-level confidence scoring
- Review & exportQueued
Human review of flagged fields, approved-result persistence, JSON and CSV export
A live readout of the real build. Three foundation phases have shipped; the document-processing pipeline is queued. Orange marks the one phase under construction now.
Problem
Companies receive invoices and contracts as PDFs, scans, and email attachments. The values that accounting and contract systems need (invoice number, VAT, totals, parties, dates, clauses) are trapped inside documents that are not directly usable, so someone opens each file and copies fields by hand. The documents are not just digital, they are poorly structured from a backend's point of view.
Solution
A FastAPI service that treats extraction as a governed, reviewable workflow rather than one opaque AI call. Uploads are stored and registered, a background worker parses text and layout (with OCR fallback for scans), classifies the document, and runs a multimodal LLM against typed invoice and contract schemas. Every field carries a confidence score; uncertain or invalid fields route to human review before results are approved, persisted, and exported.
Highlights
- Typed extraction, not loose text: invoice and contract Pydantic schemas turn model output into validated, field-level backend data with explicit required and optional fields
- Confidence-scored, human-in-the-loop review: each field combines model confidence, validation outcome, and extraction quality; anything uncertain is flagged and gated behind explicit approval
- Auditable by design: raw model responses, validation errors, job failures, and review decisions are all stored, so an approved record can be traced back to how it was produced
- Backend-first and incremental: async processing on Redis workers, configurable storage outside the source tree, and a lightweight review UI added after the core pipeline is proven
- BUILD PHASES
- 8
- COMPLETE
- 3 / 8
- DATA MODALITIES
- 2