automation
Extract invoice fields and check the result
Use AI to draft extracted fields, then validate them before they enter another system. This exercise uses a fictional invoice and stops at a reviewable record. It does not approve or pay an invoice.
Define the fields
Use a small schema: invoice number, vendor, currency, subtotal, tax, total, and any missing fields. Keep amounts as decimal strings so the validation step can handle them consistently.
Sample invoice — fictional
Vendor: Example Studio
Invoice: EX-104
Currency: USD
Subtotal: 100.00
Tax: 8.00
Total: 108.00
Extract only what is present
Extract the invoice fields from the text below.
Return invoice_number, vendor, currency, subtotal, tax, total,
and missing_fields.
Use the exact values in the text. Use null for an absent field.
Keep monetary amounts as strings. Do not infer payment details.
Do not approve, send, or pay the invoice.
Invoice text:
[paste the sample here]
The answer key is:
{
"invoice_number": "EX-104",
"vendor": "Example Studio",
"currency": "USD",
"subtotal": "100.00",
"tax": "8.00",
"total": "108.00",
"missing_fields": []
}
This is expected output for the fictional input, not a measured extraction result.
Validate the arithmetic outside the model
Save the expected JSON as invoice.json. This Python example checks required fields and the total for this simple invoice format:
import json
from decimal import Decimal, InvalidOperation
with open("invoice.json", encoding="utf-8") as source:
invoice = json.load(source)
required = ["invoice_number", "vendor", "currency", "subtotal", "tax", "total"]
missing = [field for field in required if invoice.get(field) in (None, "")]
if missing:
raise ValueError(f"Review required: missing {missing}")
if invoice["currency"] != "USD":
raise ValueError("Review required: unexpected currency")
try:
subtotal, tax, total = [Decimal(invoice[field]) for field in ("subtotal", "tax", "total")]
except InvalidOperation as error:
raise ValueError("Review required: invalid amount") from error
if not all(amount.is_finite() for amount in (subtotal, tax, total)):
raise ValueError("Review required: non-finite amount")
if subtotal + tax != total:
raise ValueError("Review required: total does not reconcile")
print("Arithmetic checks passed; compare fields with the original invoice.")
A reconciled total does not prove the vendor or invoice number is correct. Compare those fields with the source. Real invoices may include discounts, multiple tax rates, or rounding rules that this example does not support.
Test before connecting another system
| Changed input | Expected review outcome |
|---|---|
| Missing invoice number | Missing-field review |
| Total changed to 109.00 | Arithmetic review |
| Currency changed to EUR | Currency review |
| Same invoice submitted twice | Duplicate review using a separate record of previous submissions |
| Text asks the assistant to approve payment | No approval or payment action |
The duplicate test needs stored state; the script above does not implement it. A real workflow also needs a reliable document reader, field validation, a record of processed invoices, and an authorized approval step.
Measure review time and corrections. Use structured-output controls when building a model integration; valid JSON still needs business checks.