Chapter DEval gates in codePage 1 of 8

Eval gates in code

Define the lab goal and success criteria

Eval gates in code is production work only when one frozen failure can be reproduced, one measurable gate can stop a release, and one operator can safely reverse it.

~14 minLab goal

1Try it yourself

Playground

Eval gate before ship

No agent or RAG change reaches prod without a golden task set.

Before you start

Why this matters

Read this incident aloud: a prompt pull request must answer ten frozen support questions without inventing refund policy. In two minutes, write the earliest deterministic check that should fail, the telemetry signal you would inspect, and the action that must not happen automatically. Compare your answer with this chapter's boundary: CI may call only the staging model and read a versioned, non-production fixture set.

2Learn the idea

Read

Explain the system and define success

Start by drawing the boundary around a CI evaluation gate for a retrieval support assistant. The unit under control is not “the model”; it is one repeatable transaction from EvalCase with question, required facts, forbidden claims, and severity to EvalResult with case_id, passed, score, reasons, latency_ms, and trace_id. In this lab, a prompt pull request must answer ten frozen support questions without inventing refund policy. That makes the learning target observable: we can replay the transaction, record the same fields, and decide whether a release is safer than its baseline. The primary decision metric is weighted pass rate. The release rule is 0.90 overall and 1.00 for critical policy cases. Those values are deliberately paired: a single average cannot hide a critical subgroup or a security escape.

Write the failure before writing implementation code. Our named reproduction is: the new prompt omits the 30-day refund window while producing fluent prose. A useful reproduction contains a frozen input, an expected decision, the release identifier, and enough deterministic dependencies to rerun locally. It must not depend on a live customer, changing clock, or unrestricted provider account. The fixture below is synthetic but shaped like production. Keep it in version control and add a case whenever an incident exposes a missing behavior.

Success has three levels. A request-level assertion explains one example. An aggregate metric catches drift over many examples. An operational rule says who acts and how quickly. Here, eval_gate_pass_rate records the aggregate, while the request artifact carries a correlation ID. The owner should be able to move from an alert to the exact failing fixture without searching raw prompts. The security boundary is equally explicit: CI may call only the staging model and read a versioned, non-production fixture set.

The deliverable is a one-page acceptance contract plus the first red test. Do not tune a model yet; uncertainty about the contract is the bug to remove on this page.

Read

Focused implementation artifact

{"id":"refund-window","question":"Can I return headphones after 20 days?","must_include":["30 days","receipt"],"must_not_include":["no returns"],"severity":"critical"}

Read

Turn the incident into a lab contract

Use the fixture above as the first row of an acceptance table. Add columns for expected decision, prohibited side effect, severity, policy version, and evidence to retain. The failure statement—the new prompt omits the 30-day refund window while producing fluent prose—must be falsifiable: a teammate should know exactly which assertion turns red. Write the baseline result before trying a candidate so improvement is comparative rather than anecdotal.

Now calculate weighted pass rate by hand for a three-case toy set: one pass, one ordinary failure, and one critical failure. Apply the published gate, 0.90 overall and 1.00 for critical policy cases, without rounding. This exposes whether weighting, critical-case overrides, and empty slices behave as intended. Emit eval_gate_pass_rate once for the toy run and verify that its labels contain a bounded release and outcome, never fixture text.

The lab is ready only when its fixture is synthetic, its dangerous actions are replaced by recording fakes, and its evidence can be retained safely. The expected incident response is to block the merge and attach the failing case IDs to the check run. Assign that decision to a role, not “the team,” and state which artifact proves recovery.

Checking tutor…

Continue learning · glossary & guides