Skip to main content
Accounts payable systems usually need invoice header fields and a list of line items. Define that contract as a Pydantic schema before writing the result downstream.
Handle missing fields explicitly. The instructions tell the agent to return null for absent values and prohibit invented line items. Check the resulting None values before writing the invoice to the AP ledger.

Persist the row

A validated Invoice is ready for persistence. Pydantic .model_dump() gives you a dictionary you can pass to any database driver.
Insert the header once, then insert each line item with the returned invoice ID. The schema maps cleanly to separate header and line tables.

Receipts

For receipts, use a smaller header with the merchant, purchase date, currency, and total. Keep the same line-item shape and change output_schema to Receipt.
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