# Setup guide — Invoice Data Extraction Agent

## 1. Install and connect intake/output

Install the agent and connect its document source and structured-output destination.

```
pipx install invoice-extract-agent
invoice-extract-agent connect --intake email,upload --out erp
invoice-extract-agent doctor
```

## 2. Configure confidence & review thresholds

Review routing and the no-guess posture are enforced here.

```
cp .env.example .env
ANTHROPIC_API_KEY=sk-ant-...
REVIEW_BELOW_CONFIDENCE=0.8
NEVER_GUESS_MISSING=true
ROUTE_MATH_MISMATCH_TO_REVIEW=true
```

## 3. Define the field schema

Specify the fields and validation rules you need.

```
# schema.yml
header: [vendor, invoice_number, invoice_date, currency]
line_items: [description, qty, unit_price, amount]
totals: [subtotal, tax, total]
validate: [line_items_sum_to_subtotal, subtotal_plus_tax_equals_total]
```

## 4. Backtest on labeled invoices

Replay invoices with known-correct values to measure field accuracy before going live.

```
invoice-extract-agent backtest --set ./labeled --explain
# reports per-field accuracy + fabricated-value count (must be 0)
```

## 5. Wire into AP intake

Route incoming invoices through extraction; low-confidence ones go to a review queue.

```
# invoice intake -> extract -> validated JSON to ERP; needs_review=true -> review queue
```
