Operations and security 3 min read Updated
AI extraction for invoices and PDFs: accuracy and cost
In short
Structured Outputs guarantee JSON field types, not arithmetic truth; reliable invoice and order extraction pairs schema-constrained models with deterministic line-sum checks, supplier lookups and human sign-off on exceptions.
Extracting line items from supplier PDFs, purchase orders and shipping notes replaces hours of manual back-office typing, yet raw language model prompts fail silently on multi-page tables, decimal commas and blurry scans. Production extraction pipelines keep error rates low and unit costs predictable by pairing schema-constrained extraction with deterministic validation and targeted human review.
Comparing document ingestion paths
Every incoming PDF or email attachment should take the cheapest reliable path rather than sending every document through the heaviest multimodal prompt.
| Ingestion method | Best document type | Main trade-off |
|---|---|---|
| Structured e-invoice (XML / ISDOC) | Electronic invoices from modern ERPs | Zero AI token cost and exact fields, requires partner adoption |
| PDF text layer plus schema extraction | Clean digital PDFs with single-column tables | Low token cost, breaks if text extraction scrambles columns |
| Page-image vision plus Structured Outputs | Scanned invoices, stamps and dense multi-column grids | Preserves visual alignment, higher cost per page |
Why schema validation needs deterministic math checks
Using Structured Outputs enforces strict JSON keys, enums and nullable optional fields so downstream code never crashes on malformed syntax. However, syntactic compliance never proves financial accuracy. A model can still misread a seven as a one on a low-DPI scan or omit a freight line.
Run deterministic checks in application code on every extracted payload before it touches accounting (AI features in production):
- Arithmetic reconciliation: verify that quantity multiplied by unit price matches each line total within rounding tolerance, and that line totals plus VAT equal the invoice total.
- Entity and master-data matching: resolve the supplier registration number, VAT ID and bank IBAN against your approved vendor table in the ERP (ERP API integration).
- Duplicate detection: reject or flag any combination of supplier ID and invoice number already recorded in the ledger.
Working on something similar in your own product? A few honest sentences are enough – we read every enquiry and reply by email. Apply with your idea
Controlling unit cost per processed document
Extracting a two-page invoice should cost fractions of a cent to a few cents, provided you route documents intentionally. Parse structured XML formats such as ISDOC directly without calling a language model at all. For PDFs, inspect whether a clean embedded text layer exists first, strip repetitive legal footers or marketing banners, and pass only relevant pages into extraction.
Reserve higher-cost reasoning or high-resolution image passes for documents that fail initial arithmetic checks, and cap maximum pages per attachment so an accidental 80-page catalogue PDF cannot exhaust daily token budgets.
Prompt injection risks and human approval queues
Supplier PDFs and inbound email attachments are untrusted external inputs. Following the OWASP Top 10 for LLM Applications and the NIST AI Risk Management Framework, isolate extracted text from system instructions, never let an extracted field trigger automatic bank transfers, and display flagged fields beside the rendered PDF page so a clerk confirms exceptions in seconds (AI automation ROI).
Rollout checklist before going live
- Build a benchmark set of 30 to 50 real supplier invoices and purchase orders covering clean PDFs, scans and multi-page tables.
- Define strict nullable JSON schemas so missing fields return null rather than guessed values.
- Implement deterministic line-sum, VAT-rate, currency and duplicate-number assertions on every output.
- Route any failed check to a side-by-side human review queue and track exception rates weekly by supplier template.
Model pricing, PDF tokenisation rules and national e-invoicing mandates evolve over time. Test extraction accuracy against your own supplier documents and keep human sign-off before posting payments or tax records.
Common questions
- Does JSON schema enforcement eliminate wrong numbers on extracted invoices?
- No. Strict JSON schema constraints guarantee valid keys and types, but a model can still misread a digit on a blurry scan or swap net and gross totals. Deterministic code must verify line-item sums, VAT rates and supplier IDs afterwards.
- When should you extract embedded PDF text instead of sending page images to a vision model?
- Use deterministic text extraction first on native digital PDFs with simple single-column layouts to keep token cost low, and reserve vision or rendered page images for scanned documents, skewed receipts or complex multi-column tables.
- How should an automated invoice pipeline handle low-confidence or mismatched documents?
- Never post unverified invoices straight into accounting or payment batches. Route any document whose arithmetic checks, currency or supplier registration fail validation into a side-by-side human review queue.
Sources
- Structured Outputs, OpenAI Platform Docs. Accessed 24 November 2026
- OWASP Top 10 for Large Language Model Applications, OWASP Foundation. Accessed 23 November 2026
- AI Risk Management Framework, NIST. Accessed 24 November 2026
Further reading
-
AI features in production: reliability and safety
A convincing prompt in a demo is easy; running an LLM feature in production means treating model outputs as untrusted data, scoping inputs strictly and capping cost and agency.
-
AI agents in SME automation: where ROI works
Start AI automation with narrow, verifiable back-office workflows that keep a human approval step; avoid autonomous agents on high-risk legal, financial, or customer-facing actions.
-
Integrating Pohoda, ABRA Flexi and ERP via API
Connecting an online shop or marketplace to Pohoda or ABRA Flexi reliably depends on queue isolation, idempotent order keys and explicit stock reservation rules rather than live checkout calls.
Have an idea that should exist? Or a working product that needs more customers, a new website or a complete rework? Bring us anything. Apply with your idea