Skip to main content

The problem

Your invoice extraction prompt returns this:
The JSON is valid. The arithmetic is not: 100 + 10 = 110, not 105. A schema can enforce numbers, but it cannot tell you that invoice totals agree.

The contract

Run the model

The repair loop is useful for extraction because the model often has enough source context to fix arithmetic or missing fields once the violation is explicit.

Accept or reject

Only accepted invoices should reach accounting. Rejected invoices still give you the attempt history, including which arithmetic rule failed and the values that caused it.

When to use this pattern

  • Invoice and receipt extraction
  • Quote-to-order workflows
  • Expense report validation
  • Any AI-extracted financial record with totals, rates, or line items