Skip to main content
Two production concerns the labeling docs leave open: routing low-confidence fields to a human, and tracking accuracy as the system runs over time. Both are short patterns on top of the same extraction agent.

Per-field confidence

Wrap each field in a confidence carrier so a downstream check can decide what needs review. The schema is identical to the one in data labeling; the routing logic is the part that lives here.

Route on low confidence

The trigger is plain Python. Walk the fields, find anything below threshold, and decide what to do with it.
The model returns confidence. Your code decides the threshold and the action.

Gate the next action with requires_confirmation

For a tighter loop, wrap the downstream action (the database write, the ERP push) in a tool that requires approval. Every call to the tool pauses the run until a human confirms it, so nothing posts to the ERP without sign-off.
The pause is persisted in db. A different process can reconstruct the same Agent configuration and continue with the stored run_id and session_id. See human approval for async variants and listing pending approvals from the database.

Accuracy against a golden set

Confidence routes individual documents. A representative golden set lets you compare extraction behavior across prompt or model changes.
AccuracyEval.run() executes its configured agent but does not accept document files. Run document extraction first, then pass its serialized output to run_with_output. AccuracyEval uses a model judge to compare that output with expected_output; it is a semantic score, not an exact field-by-field metric.
Passing db=db stores each evaluation result. Compare model-judge scores across repeated runs with a fixed judge configuration, and add deterministic field checks for invoice numbers, dates, totals, and line items. See the evals cookbook for database logging and the team variant.

Three patterns, one job

The first two gate a single document. The third records a model-judge signal for comparing configurations.

Next steps

Developer Resources