Skip to main content
The shape AP teams need: a header (vendor, totals, dates) and a list of line items. The schema is the contract with downstream systems.
The hard part is the missing-field discipline. A hallucinated total corrupts the AP ledger. Two lines in the instructions (“use exactly what the document shows”, “null if missing”) cut the hallucination rate substantially on noisy scans.

Persist the row

The agent’s job ends at a validated Invoice. The next step is a normal INSERT. Pydantic .model_dump() gives you a dict you can hand to any driver.
Two writes per invoice. The schema decides the table layout; the agent decides the values.

Receipts

Receipts are invoices with a thinner header. Drop due_date, vendor_tax_id, and bill_to. Keep the same line-item shape. The same agent and the same instructions work; only output_schema changes.
For phone-camera receipts (skewed, low light), the input becomes an image rather than a PDF. See multimodal inputs for the input argument.

Confidence on noisy scans

Production AP sees faxed copies, partial scans, and mixed-language invoices. When you need a flag for “send this to a human”, wrap each value in a confidence carrier. The pattern is identical to the data labeling pattern and feeds the routing logic in human routing and eval.

Next steps

Developer Resources