Extract inconsistent PDF invoices into a reviewed CSV
At a glance
A developer combines PDF text extraction, JSON-mode inference, and validation to process invoices with different layouts. This workflow is listed under Document Processing, Invoices.
- Agents / tools
- gpt-4o-mini, Interwest AI, PyMuPDF, Python
SourceBuilding a tool for these workflows? See weekly rates.
What they did
1) Prepare text-readable invoice PDFs, Python with PyMuPDF and requests, and credentials for a JSON-capable inference endpoint. The author's example uses an Interwest AI endpoint with gpt-4o-mini. 2) Open each PDF with fitz and concatenate page.get_text() across its pages. 3) Send that text with instructions to return JSON containing vendor, invoice number, date, total, currency, and line items with description, quantity, unit price, and amount. Require null for missing fields. 4) Parse the response as JSON; retry malformed output with a simpler prompt and route missing totals to manual review. 5) Repeat across the invoices, collect validated records, export CSV, and manually correct problematic documents.
How it went
The author reports complete extraction for 478 of 500 invoices, with 22 requiring review; these are self-reported results.
Worth knowing
The author encountered omitted items and invented dates. The demonstrated text-extraction step does not provide OCR for scanned pages.