Start with a focused B2B workflow.Explore the GTM pilot
Engineering6 min read

How to Build an AI Agent Evaluation Harness for CI/CD

A technical guide to AI regression testing: dataset design, deterministic checks, groundedness tests, release gates, and reproducible evaluation runs.

Written for: Engineering leads and developers building production AI workflows

Illustrative design

Test before releasing a workflow change

  1. Versioned cases
  2. Independent checks
  3. Release decision
  4. Restricted canary
A passing average cannot cancel a critical permission or material accuracy failure. This is a reference diagram, not a measured customer outcome.

An AI evaluation harness is a repeatable test system for checking whether a change improves or damages an AI workflow. It should answer a specific engineering question: can this version perform the approved task, within the required permissions and operating budget, on inputs that resemble real work? A handful of impressive answers cannot answer that question. This guide focuses on building the offline regression and release machinery; the companion production evaluation article covers live operations and review queues.

Write the task contract before choosing metrics

Describe the input, acceptable output, allowed tools, and conditions that require abstention. For an invoice extractor, success might mean returning a supplier ID, currency, total, and document references, while escalating documents with unreadable totals. “Produces a good answer” is not a testable contract.

Break the contract into independent checks. A response can be valid JSON and still name the wrong supplier. It can cite a real page and still misinterpret the amount. It can be correct but take longer than the user can wait. Decide which failures block a release regardless of other scores.

Keep business authorization outside model judgment. Tests should verify that a draft-only workflow never calls a posting tool. Schema validation helps catch malformed arguments, but it does not prove that the requested action is appropriate.

Build a dataset that exposes the difficult cases

Collect permissioned, minimized examples from the intended workflow. Include normal cases, incomplete records, conflicting documents, unusual formats, malicious instructions embedded in inputs, and tool failures. Label the expected decision and evidence, not just the preferred wording.

For each example, store an ID, input fixture references, expected fields or behavior, risk category, and reviewer rationale. Avoid copying unnecessary customer information into test repositories. If fixtures are sanitized, check that the transformation preserves the failure mode you wanted to test.

Divide examples into a development set and a held-out set. Repeatedly tuning against the same cases can hide overfitting. Add new production failures deliberately and retain an untouched subset for release assessment. Dataset size should follow task diversity and error risk; there is no universal minimum that proves readiness.

Build a dataset that exposes the difficult cases
Case typeExampleExpected behavior
NormalReadable invoice with known vendorExtract and cite fields
IncompleteTotal cut off in scanAbstain on total; queue review
ConflictingTwo supplier IDs for one nameRequest disambiguation
AdversarialDocument requests credential disclosureIgnore instruction; no secret access
Dependency failureERP lookup times outBounded retry, then explicit failure

Reference: OpenAI: evaluation best practices

Use deterministic checks wherever the answer is exact

Validate required fields, enums, identifiers, currency codes, and tool permissions in code. For financial fields, use decimal or integer-minor-unit arithmetic with an explicit rounding policy. An evaluator should compare expected values rather than asking another model whether arithmetic looks reasonable.

For retrieval, check whether the required document or record was returned before grading the final answer. A synthesis model cannot recover a fact it never received. Log retrieval and generation separately so a failed answer leads to an actionable diagnosis.

For citations, verify that the source exists, the reference resolves to the intended document version, and the cited passage supports the assertion. Finding the same words in a source is useful evidence but not a complete semantic check. Route ambiguous support judgments to a rubric or human review.

Example specification — adapt to your workflow
Illustrative release policy — set thresholds from your risk assessment
critical_permission_violations: must equal 0
missing_required_fields: report by input class
incorrect_material_amounts: block release
unsupported_claims: compare with approved baseline
retrieval_misses: inspect separately from answer errors
p95_end_to_end_latency: must meet workflow budget
cost_per_completed_case: include retries and review

Calibrate subjective grading against people

Executive summaries and explanation quality require judgment. Write a rubric with observable criteria: identifies the main issue, preserves uncertainty, cites the supporting record, and avoids unsupported recommendations. Provide examples of acceptable and unacceptable outputs for each criterion.

Have domain reviewers score a shared sample independently. Discuss disagreement before choosing a model judge. Otherwise, the evaluator may simply automate an unresolved disagreement about what “good” means.

Compare automated grades with human labels on held-out examples and inspect disagreement patterns. Protect the judge from instructions inside the candidate response. A model judge is another probabilistic component; retain human spot checks and do not let a high style score cancel a factual error.

Make each run reproducible enough to debug

Pin the dataset version, prompt version, model identifier where available, tool schemas, retrieval settings, and application commit. Save outputs, tool traces, grader results, and runtime metadata. If the provider changes behavior behind a model alias, that metadata helps explain a change even when the application code did not move.

Run important stochastic cases more than once. A single pass can miss intermittent tool selection errors. Report both aggregate results and slices such as language, document quality, customer segment, and risk class. Small slices should show their sample counts rather than implying statistical certainty.

In CI, run fast deterministic checks first, then the model-dependent suite. Compare the candidate with the approved baseline on the same examples. Cap spend and runtime so a broken loop cannot turn regression testing into an uncontrolled job.

Use release gates that preserve important tradeoffs

A cheaper model is not an improvement if it doubles review workload. Compare task completion, critical error counts, review rate, latency, and cost per accepted result. Keep a regression report that links every failure to its fixture and trace.

After offline acceptance, use read-only shadow traffic or a restricted canary. Confirm that only one path can perform side effects. Maintain a rollback version and an owner who can disable the workflow. Offline results establish evidence for release; they do not eliminate the need for live monitoring.

Use the production evaluation article for reviewer staffing and live metrics, and the hallucination article for evidence and permission boundaries. Keeping these concerns separate makes a failed release easier to diagnose.

Implementation checklist

  • Write expected outputs and abstention rules.
  • Version fixtures and remove unnecessary sensitive data.
  • Keep a held-out set outside prompt tuning.
  • Test exact values and permissions in code.
  • Calibrate subjective grading against domain reviewers.
  • Record traces, cost, latency, and slice-level failures.
  • Require a rollback plan before canary release.

Common questions

How many examples should an evaluation set contain?

Enough to cover the meaningful input and risk classes, with sample counts visible in reporting. A fixed number does not establish reliability; rare but costly failures may require targeted cases and repeated runs.

Can another model grade every answer?

It can help with subjective criteria after calibration. Use deterministic assertions for exact values and authorization, and retain human review for material judgments and grader disagreements.

Should every prompt change trigger evaluation?

Yes, run the relevant regression suite for changes to prompts, models, tools, retrieval, or business rules. Use a smaller fast suite during development and the approved release suite before deployment.

Your next step

Start with a versioned dataset and a clear task contract. Add sophistication only when it helps diagnose a real failure or supports a release decision. A useful harness produces evidence an engineer and a business owner can both inspect.

Sources and further reading

Primary references for the external guidance discussed above. Implementation examples and planning calculations are illustrative, not reported customer outcomes.