#Why evals are the core skill
AddedAn eval is a repeatable measurement of how well an AI feature does its job: a set of inputs, a way to grade each output, and a number you can compare across changes. It plays the role unit tests play for ordinary code, with two differences: the grade is often a score or a judgement rather than pass/fail on equality, and you run each case several times because the output varies.
Evals matter more than any single prompt trick because every other decision depends on them. Which model? Which effort level? Did this prompt change help? Is retrieval the problem or generation? Can we upgrade to the new model version? Without an eval, each of these is an opinion formed by trying a handful of examples, which is how teams ship "improvements" that fix the three cases someone looked at and quietly break five others. With one, they're measurements. Anthropic's own guidance on building evals makes a related point worth remembering: when an eval result is surprising, the eval itself is the first suspect, because broken graders and wrong labels produce confident numbers that point the wrong way.
The mental model is a regression test suite for behaviour: a fixed set of realistic cases with agreed answers, run on every change, whose score you watch the way you watch a test suite go red. It's never finished: every bug a user reports becomes a new case, so the suite slowly becomes a precise description of what "working" means for your product.
The example is a minimal eval harness for the ticket router: two prompt versions, twelve labelled tickets, every case graded, and the changes listed case by case.
import Anthropic from "@anthropic-ai/sdk";
// Scripted replies (see "How these examples run") ---------------------------------------------
// Replies in the documented response shape. The categories the "model" picks were written for the
// example so that prompt v2 fixes some cases and breaks one; with a real key you'd measure the real model.
const scripted = {
v1: { "My invoice shows the wrong company name": "bug", "SSO login loops back to the start page": "bug", "Please add a dark mode": "feature_request",
"I was charged twice this month": "billing", "The two-step code never arrives": "login", "Export button does nothing": "bug",
"Can you add a Linear integration?": "feature_request", "Why did my card get declined?": "billing", "Locked out after too many attempts": "bug",
"Events show at the wrong time after the clock change": "bug", "Refund my annual plan please": "billing", "Booking page is blank on Safari": "bug" },
v2: { "My invoice shows the wrong company name": "billing", "SSO login loops back to the start page": "login", "Please add a dark mode": "feature_request",
"I was charged twice this month": "billing", "The two-step code never arrives": "login", "Export button does nothing": "bug",
"Can you add a Linear integration?": "feature_request", "Why did my card get declined?": "billing", "Locked out after too many attempts": "login",
"Events show at the wrong time after the clock change": "bug", "Refund my annual plan please": "billing", "Booking page is blank on Safari": "feature_request" },
};
const fetch = async (url, init) => {
const body = JSON.parse(init.body);
const version = body.system.includes("v2") ? "v2" : "v1";
const category = scripted[version][body.messages[0].content];
return Response.json({
id: "msg_01Lm8KxQ2pRt6VzN4cWb9Hj3", type: "message", role: "assistant", model: "claude-haiku-5-5",
content: [{ type: "text", text: JSON.stringify({ category }) }],
stop_reason: "end_turn", stop_sequence: null, usage: { input_tokens: 180, output_tokens: 9 },
});
};
const client = new Anthropic({ apiKey: "sk-ant-test", fetch }); // for real: new Anthropic()
// ----------------------------------------------------------------------------------------------
// The feature under test: route a support ticket to a team.
const prompts = {
v1: "Classify the support ticket into one category: billing, login, bug or feature_request.",
v2: "Classify the support ticket into one category (prompt v2).\n" +
"billing: payments, invoices, refunds, plans (even if something on an invoice looks wrong).\n" +
"login: signing in, passwords, two-step codes, SSO, lockouts.\n" +
"bug: something that used to work or should work is broken.\n" +
"feature_request: asking for something the product doesn't do.",
};
async function classify(version, ticket) {
const res = await client.messages.create({
model: "claude-haiku-5-5", max_tokens: 100, output_config: { effort: "low", format: { type: "json_schema", schema: {
type: "object", properties: { category: { type: "string", enum: ["billing", "login", "bug", "feature_request"] } },
required: ["category"], additionalProperties: false } } },
system: prompts[version],
messages: [{ role: "user", content: ticket }],
});
return JSON.parse(res.content.find((b) => b.type === "text").text).category;
}
// The eval set: real-looking tickets with the right answer, agreed by the support team.
const cases = [
["My invoice shows the wrong company name", "billing"], ["SSO login loops back to the start page", "login"],
["Please add a dark mode", "feature_request"], ["I was charged twice this month", "billing"],
["The two-step code never arrives", "login"], ["Export button does nothing", "bug"],
["Can you add a Linear integration?", "feature_request"], ["Why did my card get declined?", "billing"],
["Locked out after too many attempts", "login"], ["Events show at the wrong time after the clock change", "bug"],
["Refund my annual plan please", "billing"], ["Booking page is blank on Safari", "bug"],
];
// The harness: run every case for every version (4 at a time), grade, and compare.
async function run(version) {
const results = [];
for (let i = 0; i < cases.length; i += 4) {
const batch = cases.slice(i, i + 4);
const outputs = await Promise.all(batch.map(([ticket]) => classify(version, ticket)));
batch.forEach(([ticket, expected], j) => results.push({ ticket, expected, got: outputs[j], pass: outputs[j] === expected }));
}
return results;
}
const [a, b] = [await run("v1"), await run("v2")];
const score = (r) => r.filter((x) => x.pass).length;
console.log(`v1: ${score(a)}/${cases.length} passed v2: ${score(b)}/${cases.length} passed`);
a.forEach((x, i) => {
if (x.pass !== b[i].pass) console.log(` ${b[i].pass ? "fixed " : "REGRESSED"} "${x.ticket}" (expected ${x.expected}; v1 ${x.got}, v2 ${b[i].got})`);
});
console.log(`noise floor with ${cases.length} cases: about ±${Math.round(100 / Math.sqrt(cases.length))} percentage points`);v1: 9/12 passed v2: 11/12 passed
fixed "My invoice shows the wrong company name" (expected billing; v1 bug, v2 billing)
fixed "SSO login loops back to the start page" (expected login; v1 bug, v2 login)
fixed "Locked out after too many attempts" (expected login; v1 bug, v2 login)
REGRESSED "Booking page is blank on Safari" (expected bug; v1 bug, v2 feature_request)
noise floor with 12 cases: about ±29 percentage pointsclassifyis the feature: onemessages.createcall with a structured output schema whoseenumlimits the answer to the four teams, so grading is a simple equality and no reply can be malformed. The model is the small, cheapclaude-haiku-5-5at low effort, which is typical for routing.casesis the eval set: twelve tickets with the team the support leads agreed is right. Real sets are larger (see the next topic), but the shape is the same: input plus expected output.runexecutes every case for one prompt version, four requests at a time (a real harness limits concurrency to stay inside rate limits), and records expected, got and pass for each. Then the two runs are compared case by case.- v1 passes 9 of 12, v2 passes 11. The headline improvement hides the useful detail: v2 fixed three tickets (the invoice question, SSO and lockouts, which v1 called bugs) and regressed one ("Booking page is blank on Safari" became a feature request). Someone trying v2 on the three tickets they were worried about would ship it without seeing the regression.
- The last line is the honest caveat: with 12 cases, a pass rate can swing by roughly ±29 percentage points through noise alone (the rule of thumb is 1 / √n). Two cases' difference here is suggestive, not proof; the next topic is about building a set big enough to decide with.
Accuracy is rarely the only thing that matters. Score properties separately rather than blending them into one number, because separate scores tell you what got worse:
| Property | Typical grader | Example check |
|---|---|---|
| Correctness | exact match, reference comparison, judge | routed to the right team; answer matches the policy |
| Groundedness | judge with the sources | every claim is supported by a retrieved passage |
| Format | code | valid JSON, schema passes, length limit respected |
| Safety and policy | code + judge | no personal data echoed; refuses what it should; resists injection |
| Tone and helpfulness | judge or human | polite, direct, answers the actual question |
| Cost and latency | measured | tokens and seconds per case, at the effort you'd ship |
Cost and latency belong in the eval report from day one: a prompt that gains one point of accuracy while doubling tokens might not be an improvement for your product.
Prompt v2 scores 11/12 against v1's 9/12 on the example's set. Your manager asks whether to ship v2. What do you say, and what would you do first?
Show answer
Probably, but not on this evidence alone: look at the regression, and measure on a bigger set before deciding.
- With 12 cases the noise floor is about ±29 points, so a two-case difference could be chance, especially since outputs vary between runs.
- The case-by-case diff matters more than the totals: v2 fixed three real confusions (invoice, SSO, lockout) and broke one (a blank booking page called a feature request). Read the regression: is it a prompt wording problem that can be fixed without losing the gains?
- Then grow the evidence: run both versions on a larger set (100+ cases, several runs each) that includes the categories v2 changed, and compare per category.
- If v2 still wins with the regression fixed, ship it and keep the four changed tickets as permanent cases, so a future prompt can't silently undo either the fixes or the fix for the regression.