Skip to main content
Document processing pipelines need a review path for low-confidence fields and a way to measure extraction quality over time. Add both to 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

Walk the extracted fields, find values below the confidence threshold, and route the document in application code.
Treat confidence as an agent-provided routing signal. Application code sets the threshold and chooses the action.

Gate the next action with requires_confirmation

Wrap a downstream action, such as a database write or ERP push, in a tool that requires approval. Every call pauses the run until a human confirms it. This places approval at the system boundary.
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

A representative golden set compares 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.

Review controls

Confidence routing and approval-gated tools act on one document. AccuracyEval records a model-judge signal for comparing configurations.

Next steps

Developer Resources