Salar Saeedi

Applied AI · Analysis

Valid JSON can still contain the wrong invoice total

Pair schema-constrained AI output with financial invariants, source locations and an explicit path for exceptions.

Salar Saeedi2 min read
Three-stage illustration — Valid JSON can still contain the wrong invoice total

Say a scanned invoice lists a €100 subtotal, €20 VAT and €120 payable. The model returns an integer field called total with the value 100. The response can validate syntactically while sending the wrong amount downstream.

What a schema can enforce

Structured Outputs constrain successful model output to the applicable schema. Required keys, value types and allowed categories are useful at the boundary. An application still needs to handle refusals and incomplete responses and decide whether the value matches the invoice.

Source · OpenAI API — Structured model outputs

Validate the relationship between fields

Extract subtotal, tax and payable as separate fields, with currency and page location. Use integer minor units or a decimal type. Reconcile the arithmetic against explicit discounts or rounding lines, and route ambiguous or contradictory invoices to review. A tax field may be missing, zero, or included in the displayed price, and those cases need different handling.

Source · OpenAI API — Evaluation best practices

Place the acceptance test after extraction

Create fixtures for credit notes, repeated subtotals, a carried-forward balance and a second currency shown for reference. Track exact-match accuracy for the payable field, human review rate and wrong auto-accepts. Store the extracted source span so someone can repair a mistake without opening the whole batch.

Source · OpenAI API — Evaluation best practices

What to take away

Count a result as automatic acceptance only after both the response format and the financial checks pass.

References

Related work in the portfolio