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 carry that discipline: “Null for missing fields” and “Do not invent line items”. Without them, a model asked for a complete object tends to fill the gaps in a noisy scan with plausible values.

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.
One insert for the header and one per line item. The schema decides the table layout; the agent decides the values.

Receipts

Receipts are invoices with a thinner header: merchant, purchase date, currency, total. 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