AI agents › Harnesses and loops
What are AI evals? How to measure LLMs and AI agents
AI evals are test cases plus a way to grade them, run the same way each time to see how well an LLM or agent does your task. How they work and how to start.
If you build anything with an LLM, the word evals will probably reach you before long. New models arrive with tables of benchmark scores, and whenever someone suggests rewording a prompt or switching models, the next question tends to be how you’ll know it actually got better. Perhaps it sounds like something only research labs do, but in practice it’s closer to a tool that any team putting AI into a product ends up needing.
AI evals, short for evaluations, pair a set of test problems from your own work with a way to grade the answers, so you can measure how well an AI system does that work, the same way every time. A post by Anthropic’s engineering team likewise describes an eval as a test for an AI system, where you give it an input and apply grading logic to its output (Demystifying evals for AI agents). Unlike ordinary software, though, the system under test often answers the same question differently each time. That’s why an eval usually counts how often the system passes, across many problems and sometimes across several tries of each.
Why evals come up so often now
The more often you change an AI system, the more you need evals. Swap in a newer model, reword a prompt, or add a step to an agent, and some answers get better while others quietly get worse. The Anthropic post, published in January 2026, says that without evals you wait for complaints, reproduce the problem by hand, fix it, and hope nothing else regressed. It adds that when a more capable model comes out, teams without evals face weeks of testing. And since agents work over many turns, calling tools as they go, their mistakes can spread and compound.
Of course, the idea isn’t new. In March 2023, in the GPT-4 Technical Report, OpenAI announced it was open-sourcing OpenAI Evals, its framework for creating and running benchmarks, and the evals repository also shows how to build private evals for your own workflow. Anthropic’s documentation asks you to start by defining success criteria that are specific and measurable (Define success criteria and build evaluations). So “safe outputs” becomes something like “less than 0.1% of outputs out of 10,000 trials flagged for toxicity by the content filter.”
A small eval you can run yourself
Let’s run a tiny eval. The task is to find the date in a sentence and write it as YYYY-MM-DD, so there’s exactly one right answer. The first block holds ten test cases, two prompts to compare, and a grader written in code. Prompt B is prompt A plus one sentence, “Reply with the date only.”, and a “Sentence:” label.
import re
# Ten test cases: a sentence and the one correct answer.
CASES = [
("The meeting moved to March 3, 2024.", "2024-03-03"),
("She was born on 7 July 1998 in Busan.", "1998-07-07"),
("Invoice 2023/11/05 is still unpaid.", "2023-11-05"),
("We launched on the 21st of September, 2021.", "2021-09-21"),
("The lease ends on 2026-01-31.", "2026-01-31"),
("He landed in Seoul on February 29, 2024.", "2024-02-29"),
("Our office reopened on Monday, April 8, 2019.", "2019-04-08"),
("The concert is on 14.02.2027 at 8 pm.", "2027-02-14"),
("Payment received 30 Oct 2022, thank you!", "2022-10-30"),
("The 2019 report was revised on June 5, 2020.", "2020-06-05"),
]
PROMPTS = {
"A": "Write the date in this sentence as YYYY-MM-DD.\n{s}",
"B": "Write the date in this sentence as YYYY-MM-DD. Reply with the date only.\nSentence: {s}",
}
def grade(reply, expected):
# Code-based grader: find the first YYYY-MM-DD and compare it exactly.
found = re.search(r"\d{4}-\d{2}-\d{2}", reply)
return found is not None and found.group() == expected
The grader uses a regular expression, a small pattern language for matching text, to find the first YYYY-MM-DD in the reply and compare it with the answer as is. I gave the questions to Qwen2.5-0.5B-Instruct, a small model with 0.49 billion parameters, running it on my own machine with Hugging Face transformers, and each case gets three tries.
from transformers import pipeline, set_seed
chat = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct", device="cpu")
def ask(prompt, seed):
set_seed(seed) # same seed, same sample, so a rerun prints the same thing
messages = [{"role": "user", "content": prompt}]
out = chat(messages, max_new_tokens=256, do_sample=True, temperature=0.7)
return out[0]["generated_text"][-1]["content"]
TRIES = 3
for name, template in PROMPTS.items():
rows = []
for sentence, expected in CASES:
prompt = template.format(s=sentence)
rows.append([grade(ask(prompt, seed), expected) for seed in range(TRIES)])
print(f"prompt {name}:", " ".join("".join("o" if ok else "x" for ok in r) for r in rows))
n = len(rows)
print(f" tries passed {sum(map(sum, rows))}/{n * TRIES},",
f"pass@3 {sum(any(r) for r in rows)}/{n},", # at least one try passed
f"pass^3 {sum(all(r) for r in rows)}/{n}") # every try passed
With do_sample=True, the model picks each next token at random according to its probabilities, so the same question can get different replies. temperature=0.7 sets how freely it picks, and the other settings come from the model’s defaults. And because set_seed(seed) fixes the random numbers, running the script again prints the same result.
prompt A: oox xxx ooo xox xoo xox xox xxo xxx xxx
tries passed 11/30, pass@3 7/10, pass^3 1/10
prompt B: ooo oxx ooo ooo ooo ooo ooo ooo ooo ooo
tries passed 28/30, pass@3 10/10, pass^3 9/10
Each group of three letters is one case, in the order of CASES, with o for a pass and x for a fail. Prompt A passed 11 of its 30 tries, and prompt B passed 28. Without the eval, the effect of that small change would have stayed a hunch. Of course, ten cases are too few to trust the exact percentages, so next I read some of the replies.
for name, case, seed in [("A", 7, 0), ("B", 2, 1), ("B", 8, 0)]:
sentence, expected = CASES[case - 1]
reply = ask(PROMPTS[name].format(s=sentence), seed)
print(f"{name}, case {case}, try {seed + 1}: {reply!r} passed={grade(reply, expected)}")
A, case 7, try 1: 'The date in the sentence "Our office reopened on Monday, April 8, 2019" is April 8, 2019.' passed=False
B, case 2, try 2: '2098-07-01' passed=False
B, case 8, try 1: '2027-02-14 20:00' passed=True
Prompt A’s reply to case 7 has the right date in the wrong format, so it was marked as a failure, and if your program needs YYYY-MM-DD, it really is one. Prompt B turned 7 July 1998 into 2098-07-01 on case 2. On case 8 it added a time after the date, and my grader, which looks only for the first date, passed it, though a grader comparing the whole reply would have failed it. So choosing a grader is also deciding what counts as correct. A different machine or library version may sample differently, though.
Three ways to grade
Graders come in roughly three kinds, and the Anthropic post compares them in much the same way.
| Grader | Good at | Watch out for |
|---|---|---|
| Code (exact match, regex, unit tests) | Fast, cheap, the same verdict every time | Missing right answers in another form |
| Model (LLM-as-a-judge) | Open-ended answers such as summaries or tone | Biases and cost, needs checking against people |
| People | Judgments that need expertise or taste | Slow and expensive |
When you can, start with code. Anthropic’s documentation, too, describes code-based grading as the fastest and most reliable, though it lacks nuance for complex judgments. For tasks that write code, unit tests become the grader.
Answers that code can’t easily judge, such as summaries or replies to customers, are handed to another model to grade, which is called LLM-as-a-judge. In Judging LLM-as-a-Judge, presented at NeurIPS 2023, Lianmin Zheng and colleagues reported that, leaving out ties, GPT-4’s verdicts agreed with human experts 85% of the time, more than the 81% at which the experts agreed with one another. They found biases too. With position bias, a judge favors an answer because of where it sits, and when the order of two similar answers was swapped, even GPT-4 kept the same verdict only 65% of the time. With verbosity bias, a judge prefers longer answers, and Claude-v1 and GPT-3.5 rated answers padded without any new information as better 91.3% of the time, while GPT-4 did so 8.7% of the time. That’s why the paper asks twice with the order swapped and counts a win only when both verdicts agree.
People are the most trusted graders, but they’re slow and expensive. So, as in the Anthropic post, people often grade a sample by hand and use it as the standard for calibrating the model judge.
How evals differ from tests and public benchmarks
A software unit test expects the same output for the same input and treats a single failure as a bug, while an eval measures a rate, and not every task has to pass. And where the tests and hooks in a harness give an agent feedback while it works, evals measure the whole system across many problems to tell whether a change helped.
Public benchmarks are evals built so that everyone can measure models with the same yardstick. MMLU, from 2020, has 15,908 multiple-choice questions across 57 subjects such as elementary mathematics, US history, and law. SWE-bench, from 2023, collects 2,294 problems from real GitHub issues in 12 Python repositories, and a model’s patch counts as a fix only if it applies and the tests pass. The paper’s abstract reports that even the best model at the time, Claude 2, solved just 1.96%. Scores like these help when you choose a model, but your task isn’t in them.
Benchmarks also wear out. The MMLU paper opens by noting that top models passed human performance on GLUE, an earlier benchmark, within a year, and scores bunching up near the top like this is called saturation. Contamination, where test problems end up in the training data, is another worry, which is why the SWE-bench authors propose adding issues created after a model’s training date.
Why agents get several tries (pass@k and pass^k)
Agent evals often grade the outcome. In τ-bench, released in June 2024 by Shunyu Yao and colleagues at Sierra, a language model plays the user and talks with an agent that has airline or retail tools and policies. At the end, the database state is compared with the goal state. Since agents regularly find valid approaches that eval designers didn’t anticipate, the Anthropic post also suggests grading the outcome over the path the agent took.
The same task can go differently each time, so agents get several tries, and there are two ways to count them. pass@k counts a task as solved if at least one of k tries passes. The 2021 Codex paper used it on HumanEval, a set of 164 problems, and it fits when you can pick the one answer that works. pass^k, proposed in the τ-bench paper, is the chance that all k tries succeed, and it fits work like customer service, where the agent has to be right every time. In that paper, a gpt-4o agent using function calling solved about 61% of retail tasks on a single try, but its pass^8 fell to about 25%.
Prompt A in the example above shows the same gap, with 7 of 10 cases solved by pass@3 but only 1 by pass^3. The papers estimate these numbers from n tries per task, but since my n and k were both 3, plain counting is enough.
Evals during development and in production
The Anthropic post splits the automated evals you run before release, and with every change, into two kinds. Capability evals ask what the agent does well and start at a low pass rate, giving the team a hill to climb. Regression evals ask whether it still handles what it used to and should stay close to 100%, and capability tasks that come to pass reliably can move over to them.
Once real users arrive, production monitoring, A/B tests, user feedback, and reading transcripts come into play, and the same post says that, as in the Swiss cheese model from safety engineering, no single layer catches every issue. That’s why failures found in production come back into the eval set as new cases.
When evals pay off and when to be careful
Evals pay off most when you keep changing a system and can check whether the answers are right. Extraction, classification, code with tests, and agents whose results land in a database are good examples. If no one has decided yet what a good answer looks like, writing down success criteria comes first. The Anthropic post also warns that automated evals can create false confidence if they don’t match real usage patterns.
Building your first eval
You don’t need hundreds of tasks to start. The Anthropic post calls 20 to 50 simple tasks drawn from real failures a great start, and suggests finding them in the checks you already run by hand during development, or in your bug tracker and support queue. Make each task clear enough that two domain experts would reach the same verdict on their own, grade with code where you can, and read some transcripts yourself.
If you’d like to try it now, copy the three blocks above, replace the ten sentences with inputs from your own work where your prompt went wrong, and change grade() to match what correct means for you. I ran the example on October 28, 2026, on macOS with Python 3.13.12, transformers 5.20.2, and PyTorch 2.14.1, on the CPU.
AI tools helped with the research for this post.