How can I improve Gemini API accuracy for extracting line items from variable invoices and quotations?
I’m building a Django-based price-intelligence system that uses the Gemini API to extract structured commercial data from PDFs, scanned quotations, invoices, purchase orders, price lists, and email documents.
I need to extract fields such as supplier, document date, currency, product/service name, item code, part number, quantity, UOM, unit price, line total, and line-level specifications.
The main issue is extraction accuracy across different document layouts.
Examples of failures:
some priced line items are missed
a description is sometimes attached to the wrong price row
supplier or document date is incorrect
decimal values are sometimes read incorrectly
a prompt change that fixes one document format can reduce accuracy for another format
My current approach is:
Gemini multimodal document extraction
structured JSON response schema
page-by-page PDF extraction
previous/next page as context for continuation rows
Python validation and normalization after extraction
For each page I currently ask Gemini to return structured data similar to:
{
"supplier_name": "ABC Trading LLC",
"document_date": "2026-08-15",
"currency": "USD",
"items": [
{
"product_name": "Pump Model X20 230V",
"quantity": "2",
"uom": "PCS",
"unit_price": "450.00",
"line_total": "900.00"
}
]
}
I want the extraction to remain source-faithful and work with previously unseen supplier layouts without continuously adding supplier-specific prompt rules.
What is the recommended architecture for this?
In particular:
Should Gemini extract directly into the final business schema, or should I first extract source-faithful rows/cells and map them to my schema afterward?
Is it better to combine OCR/document-layout extraction with Gemini instead of relying only on Gemini vision?
What is the best way to prevent wrong row-to-price binding and missed line items across unknown document layouts?
How should I validate Gemini output without post-processing accidentally changing correct source values?
I’m looking for a production-oriented approach rather than a fixed-template invoice parser.