# Examples — Invoice Data Extraction Agent

## Clean digital invoice → full validated JSON

A crisp PDF invoice. The agent extracts all fields at high confidence and the math reconciles.

**Input**

```
Digital PDF: Vendor 'Acme Supply', Invoice INV-204, 2026-05-10, 2 lines: 10 @ $40 = $400, 5 @ $20 = $100; subtotal $500, tax $40, total $540.
```

**Output**

```
{
  "vendor": { "value": "Acme Supply", "confidence": 0.99 },
  "invoice_number": { "value": "INV-204", "confidence": 0.99 },
  "invoice_date": { "value": "2026-05-10", "confidence": 0.98 },
  "currency": "USD",
  "line_items": [
    { "description": "Widget A", "qty": 10, "unit_price": 40, "amount": 400, "confidence": 0.97 },
    { "description": "Widget B", "qty": 5, "unit_price": 20, "amount": 100, "confidence": 0.97 }
  ],
  "subtotal": { "value": 500, "confidence": 0.98 },
  "tax": { "value": 40, "confidence": 0.97 },
  "total": { "value": 540, "confidence": 0.99 },
  "validation": { "math_ok": true, "issues": [] },
  "overall_confidence": 0.98,
  "needs_review": false,
  "review_reasons": []
}
```

**Note:** The clean case: a digital invoice yields high per-field confidence and the validation confirms line items sum to subtotal and subtotal + tax = total. It passes through without review — the volume that should be automatic.

## Low-quality scan, illegible field → null + flag, don't guess

A faxed scan where the invoice number is unreadable. The agent extracts what it can and refuses to guess the rest.

**Input**

```
Scanned/faxed invoice: vendor readable, line items and totals readable, but the invoice number is smudged/illegible.
```

**Output**

```
{
  "vendor": { "value": "Globex Industrial", "confidence": 0.9 },
  "invoice_number": { "value": null, "confidence": 0.2 },
  "invoice_date": { "value": "2026-04-22", "confidence": 0.85 },
  "currency": "USD",
  "line_items": [
    { "description": "Maintenance service", "qty": 1, "unit_price": 1200, "amount": 1200, "confidence": 0.88 }
  ],
  "subtotal": { "value": 1200, "confidence": 0.9 },
  "tax": { "value": 96, "confidence": 0.85 },
  "total": { "value": 1296, "confidence": 0.9 },
  "validation": { "math_ok": true, "issues": [] },
  "overall_confidence": 0.78,
  "needs_review": true,
  "review_reasons": ["Invoice number illegible (confidence 0.2) — left null rather than guessed"]
}
```

**Note:** The math is fine, but the invoice number is unreadable. Critically, the agent returns null with low confidence for that field and flags it for review — it does NOT invent a plausible-looking invoice number. A guessed identifier would corrupt downstream matching and payment.

## Totals don't reconcile → flag the discrepancy, never silently fix

The line items don't sum to the printed total. The agent reports both and routes to review instead of 'correcting' the numbers.

**Input**

```
Invoice: line items sum to $980, but the printed total is $1,080 (subtotal $1,000, tax $80). The $20 line-item gap doesn't reconcile.
```

**Output**

```
{
  "vendor": { "value": "Northstar Parts", "confidence": 0.95 },
  "invoice_number": { "value": "NS-7741", "confidence": 0.96 },
  "invoice_date": { "value": "2026-05-02", "confidence": 0.95 },
  "currency": "USD",
  "line_items": [
    { "description": "Part X", "qty": 20, "unit_price": 24, "amount": 480, "confidence": 0.94 },
    { "description": "Part Y", "qty": 10, "unit_price": 50, "amount": 500, "confidence": 0.94 }
  ],
  "subtotal": { "value": 1000, "confidence": 0.9 },
  "tax": { "value": 80, "confidence": 0.92 },
  "total": { "value": 1080, "confidence": 0.95 },
  "validation": { "math_ok": false, "issues": ["Line items sum to 980 but subtotal is printed as 1000 (gap 20)", "subtotal 1000 + tax 80 = 1080 matches printed total, but line-item sum is inconsistent"] },
  "overall_confidence": 0.9,
  "needs_review": true,
  "review_reasons": ["Line items (980) do not reconcile to subtotal (1000) — discrepancy of 20; not auto-adjusted"]
}
```

**Note:** The defining defensive case: the line items don't sum to the subtotal. A naive extractor might quietly change a number to make it balance. This agent reports the printed values exactly, records the specific discrepancy, and routes to review — surfacing a real data problem (a missing line, an OCR error, or a vendor mistake) instead of masking it.
