Evaluation, Testing, and Optimization
Find eval coverage gaps, derive evals from business processes, design LLM-as-judge and remove its biases, design experiments that compare configurations, isolate root causes from traces, optimize cost/latency from telemetry, and manage model version migrations.
- Evaluation Coverage Gaps: accuracy, groundedness, latency, cost, safety, security
- Deriving Evaluations from Business Processes and the decisions they must support
- LLM-as-Judge Design and Bias: position, verbosity, self-preference, judge drift
- Experimental Design for Configuration Comparison within a sample budget
- Root-Cause Isolation from Logs and Traces: prompt, retrieval, hallucination, tool or subagent error, model mismatch
- Cost and Latency Optimization from telemetry and cache hit rates
- Model Version Migration: pin, re-tune, re-baseline, or defer
Domain overview
Domain 4 is 17% of the CCAR-P exam, about 10 of the 60 scored items. Items typically present a failure that reached production, a judge that disagrees with human graders, or a telemetry table.
| Objective | Typical exam question | Keywords |
|---|---|---|
| Evaluation coverage gaps | Which metric dimension or grading target is missing? | groundedness, safety, end state |
| Deriving evals from business processes | Which part of the process is a valid eval? | accuracy floor, release gate |
| LLM-as-judge design and bias | Which bias causes the disagreement, and how do you fix it? | position, verbosity, self-preference, drift |
| Experimental design | How many cases, how many runs? | noise floor, paired, reps |
| Root-cause isolation | Is the failure from the prompt, retrieval, hallucination, a tool, or the model? | transcript, span, served model |
| Cost and latency optimization | Where is cost concentrated, and which optimization holds the floor? | cache hit rate, tail, effort |
| Model version migration | Pin, re-tune, re-baseline, or defer? | deprecation, breaking change |
The guiding principle: an eval is a decision tool. Each eval is tied to a decision (model change, prompt change, release) and to a threshold derived from business consequences.
(Source: CCAR-P Exam Guide, Domain 4)
Evaluation coverage gaps
When a failure reaches production, ask two questions: which metric dimension was not measured (accuracy, groundedness, latency, cost, safety, security), and is the grading target right (the final answer, each turn, the trajectory, or the end state of the environment)?
- Anthropic's April 23 postmortem: one system prompt line limiting length ("≤25 words between tool calls, ≤100 words in the final response") cut quality by 3%, which surfaced only in a broader eval suite through ablation. Remedy: a broad per-model eval suite for every system prompt change, ablations, a soak period, and gradual rollout.
- The postmortem of three issues: output with stray Thai/Chinese characters led to deterministic tests that detect unexpected characters.
- Both-directions coverage: an eval for "does it search when it should?" must be paired with "does it avoid searching when it shouldn't?"; otherwise an agent that always searches still gets a perfect score.
- "No answer" is not "a negative answer": a runner that errors on every input must not be scored the same as an agent that concludes "not found". Refusal is a separate metric; a response truncated at
max_tokensis a separate state. - Grade the outcome, not the path: for an agent that acts on an environment, grade the end state with code. A judge reading the transcript is only grading the agent's account of what it did.
- Rare high-risk behaviors (deleting data, irreversible actions) use fail-on-any or worst-case scoring, not an average diluted by easy cases.
| Failure that reached production | Missing dimension/target | Metric that would have caught it |
|---|---|---|
| Fluent answers that invent figures not in the documents | Groundedness | Share of claims with a valid citation |
| Agent reports "CRM updated" but the record is unchanged | Grading the transcript instead of the end state | Check the record after the task |
| Accuracy unchanged, bill up 40% | Cost | Cost per completed task, cache hit rate |
| Agent follows instructions hidden in a customer email | Security | Prompt injection cases that check the actions taken |
Exam trap
"Add more cases to the existing eval suite" is rarely the answer to a coverage question. More cases on the same metric dimension don't catch failures on another dimension. The correct answer names the missing dimension or changes the grading target.
(Sources: Anthropic Engineering: An update on Claude Code quality reports; Anthropic Engineering: A postmortem of three recent issues; Anthropic Engineering: Demystifying evals for AI agents; Anthropic Skills: claude-api — Eval health checklist)
Deriving evals from business processes
| Decision | Valid eval portion of the process | Note |
|---|---|---|
| Model change | Same cases, same prompt, only the model changes | Compare cost per completed task, not token price |
| Prompt change | The full suite, checking every column | Fixing one case type can break another |
| Release gate | Smoke eval on every pull request, set as a required check | Without branch protection, a red X is only a warning |
Success criteria from business outcomes. In the Introduction to evals course, Meridian sets a 90% accuracy floor based on the cost of one wrong answer. Models that clear the floor are compared on cost per completed task = cost of one run ÷ number of tasks completed correctly. Don't mix batch and standard pricing in a comparison; measure response time if latency matters.
Methodology mix. The "Demystifying evals" article describes complementary layers in a Swiss cheese model (the holes in one layer are covered by another): automated evals, production monitoring, A/B testing, user feedback, transcript review, and systematic studies with human graders. Meridian's production process:
- A 10-case smoke eval covering every report type, run on every pull request with an 88% threshold, set as a required check.
- The full suite on any prompt or model change, run through the Batch API (50% cheaper) because no one is waiting.
- Nightly grading of 1–5% of live traffic with an LLM judge, alerting when the score falls more than 2 standard deviations below the baseline, and turning every failure into a new case.
Choosing cases: start with 20–50 tasks drawn from real failures, stratified by production proportions, with each case clear enough that two independent experts agree on pass/fail. Distinguish capability evals (new capabilities, scores still low) from regression evals (held near 100%).
Exam trap
Ground truth taken from the current model's output skews a migration eval: grading by similarity to the reference rewards imitating the old model and penalizes the successor for a different style. Use a rubric or a pairwise judge, or have humans verify a sample of the references first.
Key point
Drift happens when the real input distribution shifts gradually; CI stays green because the suite only knows the old cases. Only grading samples of live traffic reveals drift.
(Sources: Anthropic Academy: Introduction to evals — When to use what model, Build a minimum viable eval, Evals in production: CI, batch, and drift; Anthropic Engineering: Demystifying evals for AI agents; Anthropic Skills: claude-api — Building an Eval for a Claude-Powered Application)
LLM-as-judge: design and bias
Use a code grader when the answer can be checked exactly. Use an LLM judge for free-form text, with a rubric of checkable attributes, inputs wrapped in XML tags, a structured verdict (correct/incorrect/unknown) via structured output, and an "Unknown" escape hatch when information is missing. Grade each dimension with a separate judge call.
| Bias | Symptom | Fix |
|---|---|---|
| Position bias | A pairwise judge picks the first-listed option more often than human graders do | Shuffle A/B per case, or grade both orders and average |
| Verbosity bias | Longer answers score higher without being more correct | Tell the judge not to reward length; use a rubric of specific attributes |
| Self-preference | The judge favors output that matches its own style | Don't use the model under test as the judge; consider a different model family or a small judge panel |
| Judge drift | Scores shift when the judge's version or prompt changes | Version the judge together with the case set; recalibrate against human labels |
Also watch for label deference: don't tell the judge which option is the "reference" or the "baseline". Scores from before and after a grader change are not comparable.
Calibrating against human graders. The eval-audit checklist requires validating the judge on a few dozen independently human-labeled cases and reporting the agreement rate. Agreement well below about 90% on clear-cut cases means the judge prompt needs more work before it is used to make decisions. Test with known negatives (an empty string, "I don't know", a confident answer to the wrong question), and run the judge twice on the same output to measure the grader's own variance.
Pairwise grading is more accurate when the criteria are fuzzy and suits comparative questions such as migrations; allow tie or both_bad, and freeze the reference outputs, because regenerating them changes what "win rate" means between rounds. A pointwise rubric gives absolute scores when there is no baseline.
Scenario example
A team compares an old and a new prompt with a pairwise judge, always placing the new prompt's output in position A. The new prompt's win rate is 71%, while blind human graders on 60 cases see only 52%. With the A/B order swapped, the win rate falls to about 50%: that is position bias. Fix it by shuffling A/B per case, re-measuring agreement with human labels, and not using the judge as a gate until agreement reaches an acceptable level.
Key point
The judge needs checking too: even when a judge grades live traffic nightly, keep reading a few responses yourself over time.
(Sources: Anthropic Skills: claude-api — Eval health checklist (When the grader is an LLM judge), Building an Eval for a Claude-Powered Application; Anthropic Academy: Introduction to evals — Build a minimum viable eval, Evals in production: CI, batch, and drift; Anthropic Engineering: Demystifying evals for AI agents)
Experimental design for configuration comparison
The same case can produce different results across runs, so each configuration must run at least twice before you trust its score. In the Meridian example, three cases flipped from fail to pass even though no change touched that field. Distinguish pass@k (at least one success in k runs) from pass^k (success on all k runs): a 75% per-run rate gives pass^3 = 0.75³ ≈ 42%.
Noise floor. The eval-audit checklist estimates the half-width of the 95% confidence interval of the paired difference in pass rate at about 1/sqrt(n·R) (n cases, R runs per case):
25 cases × 2 runs → ≈ ±14 points
100 cases × 2 runs → ≈ ±7 points
Compare the noise floor with the headroom (ceiling minus baseline) and the smallest change worth acting on. If the noise floor is larger, pull these levers in order of cost: more runs (cheapest; a paired design makes them more efficient), more cases, a switch to a pairwise or continuous metric, or iterating on the discriminating cases and then confirming on the full suite.
Controlling confounders:
- Paired comparison: both configurations run on the same cases; compare case by case, then aggregate the differences.
- Infrastructure is an experimental variable: on Terminal-Bench 2.0, the gap between the most- and least-resourced configurations was 6 points (p<0.01); time of day also affects pass rates. Leaderboard gaps under 3 points deserve skepticism.
- Repeat the baseline before the first change to get a noise bar; keep a held-out portion the search loop never reads; split train/test randomly rather than by baseline score, because low-scoring cases will "improve on their own" through regression to the mean.
- Separate infrastructure errors from model errors: timeouts, 429s after retries are exhausted, and unparseable output go to a separate error file instead of being scored 0.
Estimate the budget from a pilot: cost per case × number of cases × number of runs; run the full suite through the Batch API for a 50% discount, and drop cases that always pass or always fail, because they carry no information.
Scenario example
You are comparing two prompts for an assistant that classifies warranty requests. The budget covers 200 calls per configuration; the team acts only on an improvement of 5 points or more. Both 25 cases × 8 runs and 100 cases × 2 runs give a noise floor of about ±7 points, larger than 5. Conclusion: state plainly that the current budget cannot resolve a 5-point effect, then increase the budget or switch to a pairwise judge on paired outputs to gain sensitivity.
Exam tip
If an item says "each configuration ran once, the gap is 2–3 points, so B is better", the answer is almost certainly that the gap is within the noise and you need repeated runs and a paired comparison.
(Sources: Anthropic Skills: claude-api — Eval health checklist (Harness design, Can it detect the change you're after?), Building an Eval for a Claude-Powered Application; Anthropic Academy: Introduction to evals — Iterate the prompt before you upgrade the model; Anthropic Engineering: Demystifying evals for AI agents; Anthropic Engineering: Infrastructure noise in agentic coding evals)
Root-cause isolation from logs and traces
The most important habit is reading transcripts. Store the full trajectory for every case and every run (messages, tool calls, results, errors, grader input/output) so you can trace an anomaly without rerunning.
| Cause | Signal in the trace | Corrective action |
|---|---|---|
| Prompt failure | Failures cluster on one input type and one field; the prompt leaves the rule open | Fix the prompt, rerun the same cases, check every column |
| Retrieval failure | The passage containing the answer is not in the retrieved context | Fix retrieval: BM25, contextual retrieval, higher top-K |
| Hallucination | The answer asserts something the documents in context do not support | Allow "I don't know", quote source sentences first, citations, a verification step |
| Tool/subagent error | A tool span returns an error or times out; a subagent returns a wrong result and the parent agent carries on | Fix the tool, make error messages actionable, check the end state |
| Model mismatch | The model in the response differs from the requested model, or the prompt is already optimized and the score won't move |
Assert the served model; move up a tier only for a genuine capability gap |
An example from Introduction to evals: a report says "the team anticipates no issues with the renewal", the correct answer is null, yet the model still names a licensing risk. All five failures fall in the report type that lacks a risk section, on the same top_risk field: the prompt allows null but never says when to use it. Adding that rule and requiring the model to quote the source sentence before answering took Haiku 4.5 from 84% to 100%.
The April 23 postmortem describes a bug that cleared thinking on every turn and made the agent "forgetful": the symptom looked like a model failure, but the root cause was in the harness.
Exam trap
A low score doesn't tell you whether the model or the prompt is at fault. "Upgrade to a stronger model" is right only when the prompt has been fixed and the score has stopped moving. When failures cluster on one input type and one field, fix the prompt first.
(Sources: Anthropic Academy: Introduction to evals — Iterate the prompt before you upgrade the model; Anthropic Skills: claude-api — Eval health checklist; Claude Code Docs: Observability with OpenTelemetry; Anthropic Engineering: An update on Claude Code quality reports)
Cost and latency optimization from telemetry
Read telemetry to see where cost is concentrated:
- Cache hit rate: the cost-optimization docs use a benchmark of a median 84% of input read from cache, with the top 10% at 94% or more; below about 80%, look for whatever is breaking the cache. Compute it from
cache_read_input_tokens,cache_creation_input_tokens, andinput_tokens. - Turn count: a 40-turn task sends the first turn 40 times, so cost grows roughly with the square of the number of turns.
- Distribution tail: on WideSearch, 2 of 20 tasks accounted for 43% of the cost.
- Output costs 5× as much as input; asking for shorter answers saves about 13%.
| Telemetry symptom | Common cause | Optimization |
|---|---|---|
| Cache hit rate drops after a deploy | A timestamp or status line at the top of the system prompt | Move the changing content to the end of the latest user turn |
| Cache misses when effort or model changes mid-session | The cache is tied to the model and parameters | Run effort sweeps in separate sessions; hand off to a subagent |
| Large input from hundreds of tool definitions | Every tool loaded up front | Tool search with defer_loading |
Many stop_reason: max_tokens |
max_tokens too low for agentic tasks |
Set 64,000; treat max_tokens as a failure |
| Nightly jobs run at standard price | No one is waiting for the results | Batch API, 50% off |
Hold the quality floor. Caching, token hygiene, and Batch are "free wins" that don't reduce quality; model, effort, and output limits are trade-offs you must measure on evals first. The four-step method in the docs: (1) production tasks weighted like real traffic, outcome checks, and cost per task recorded; (2) baseline the tiers at several effort levels and plot score against cost; (3) add a multi-model strategy only if a gap remains; (4) run in shadow on a slice of traffic before switching over fully, then maintain the suite.
Key point
A prompt audit looks for two kinds of problems: legacy instructions such as "double-check" or "be maximally thorough" that waste money; and abandoned thinking configurations, conflicting rules, or manual scratchpads that reduce accuracy.
(Sources: Claude Docs: Optimizing for cost and intelligence; Claude Blog: Reducing cost and improving performance with Claude Platform; Claude Blog: Lessons from building Claude Code: Prompt caching is everything)
Model version migration
| Response | When to choose it | Evidence needed |
|---|---|---|
| Pin | You need stability while evaluating the new model, and there is time before the retirement date | Deprecation schedule, exact model ID |
| Re-tune prompts | Regressions concentrate in behavior a prompt can adjust (overreaction, excess detail, a different default effort) | Regressions by case type |
| Re-baseline evals | A change in tokenizer, price, default effort, or format makes the old numbers incomparable | Recount tokens with count_tokens, rerun the baseline |
| Defer | A severe regression with no fix yet, and the retirement schedule still allows it | The specific gap, the current model's retirement date |
The migration guide in the claude-api skill lists breaking changes: budget_tokens returns a 400 on newer models; Claude Opus 5.5 and Claude Sonnet 5.5 return a 400 for forced tool_choice (any/tool); prefill is rejected starting with the 4.6 models. There are also silent changes: Claude Opus 5.5's default effort is medium, lower than Claude Opus 5's high, so set effort explicitly and rerun the effort sweep. Prompts written for older models are often over-specified, and language like CRITICAL or MUST easily makes newer models overreact. Changing the model string invalidates the existing cache.
A sound process: send one test request, run the full suite on the same cases, read regressions by case type, fix the prompt before concluding the model is worse, then roll out gradually with a soak period.
Scenario example
The current model retires in 10 weeks. On the successor model, a 300-case suite shows unchanged overall accuracy, but the "table extraction" type drops 9 points and output is 35% longer. Traces show the old prompt contains many "MUST list everything" instructions. The sound response: re-tune the prompt for the regressed case type, set effort explicitly, re-baseline cost on recounted tokens, and pin the old model in the meantime. Deferring is not sound because the retirement schedule doesn't allow an extension.
Exam trap
"Pin the old model indefinitely" is not a strategy once a retirement date exists; pinning only buys time to evaluate and re-tune. Conversely, switching immediately because "the overall score is unchanged" ignores per-case-type regressions and cost changes.
(Sources: Anthropic Skills: claude-api — Model Migration Guide, Claude Model Catalog; Anthropic Academy: Introduction to evals — Iterate the prompt before you upgrade the model; Anthropic Engineering: An update on Claude Code quality reports)
Quick summary
- Failure reached production: ask which metric dimension is missing (accuracy, groundedness, latency, cost, safety, security) and whether the grading target is right.
- Grade outcomes and the end state, not the path; use fail-on-any for rare high-risk behavior.
- Cover both directions (should act, should not act); separate "no answer" from "a negative answer".
- Derive the accuracy floor from the cost of a wrong answer; among models that clear it, pick the lowest cost per completed task.
- Release gate: a smoke eval on each PR as a required check; the full suite via Batch; nightly grading of 1–5% of live traffic to catch drift.
- Ground truth from the old model's output skews a migration eval; use a rubric or pairwise grading.
- Judge bias: position (shuffle A/B), verbosity (don't reward length), self-preference (no grading its own output), drift (version and recalibrate).
- Calibrate the judge against a few dozen human labels; with agreement well below about 90%, don't use it as a gate yet.
- Noise floor ≈
1/sqrt(n·R); use a paired design and repeated runs. - Infrastructure and time of run are experimental variables; be skeptical of gaps under 3 points.
- Isolate the cause: prompt, retrieval, hallucination, tool/subagent, model mismatch; fix the prompt before upgrading the model.
- A cache hit rate below about 80% signals that something is breaking the cache; cost grows with the square of the turn count and concentrates in the tail.
- Migration: pin to buy time, re-tune prompts, re-baseline evals and cost, and defer only when the retirement schedule allows.