Evals and Unit Tests
In this article
- Name what belongs to the system under test, and say why changing one part of it makes a new system.
- Sort a behaviour of an AI feature into a hard invariant for a deterministic check or a target for an eval.
- Write an observable success criterion that accepts every right wording of a reply.
- Explain why green unit tests and one hand-checked question cannot rule out a regression.
- Terms defined here: system under test, hard invariant, eval, baseline, regression.
Overview
A team replaces the model behind a feature that works. The unit tests, small programs that each check one piece of the code, all come back green, and the release looks safe. Whether customers still get right answers is a separate question.
In an invented example, Brightline, a home-internet provider, runs a support assistant on its website that answers customers and can look up an order, issue a refund of at most $50 and hand a conversation to a person on the support team. Its team wants to move the assistant from orbit-flash-2, the model version in production (one fixed release of a model), to orbit-flash-3; both names are invented. Afterwards you can tell which behaviours a short program can settle by reading the output, and which need an eval: many saved questions run on the new version and the old one, with the results compared.
What the switch changed
The obvious answer to what the team is testing is "the model", but the reply a customer reads comes from more than that. Brightline's assistant builds each reply from this configuration, all of it invented:
- the model version,
orbit-flash-2; - the prompt, the text the model is given to start from, saved as a prompt version, one saved, unchangeable state of that text;
- four tools, functions the application runs when the model asks:
lookup_order,issue_refund,search_help, which returns Brightline's help pages, andescalate_to_person; - the help pages themselves, which the application hands to the model as text to answer from;
- the refund rule: "The assistant may refund at most $50 without approval; above $50 it asks a person for approval."
- settings sent with each request, such as temperature, the subject of Temperature and Sampling.
Swapping the model, editing the prompt or reworking a tool can each quietly break something that used to work. And an assistant that looks up a policy page or calls a tool is judged on those steps as well as on its final words. So what is under test is the whole configuration, the system under test. Change any one line, even only the model, and you have a new system whose behaviour must be measured again. [1,2]
Why every test passed
After the switch to orbit-flash-3, the candidate, the team runs its unit tests. One hands the application's parser a stored sample reply and checks that it splits into a message for the customer and a list of tool calls. Another calls lookup_order with order id 4471 and checks that the right record comes back. Both pass. Would either catch a reply that tells a customer the wrong refund window?
Neither can. The parser test reads a reply someone saved once, and lookup_order is ordinary code that fetches a record. No line of either test asks the model anything, so swapping the model cannot turn them red. That is what they are for: unit tests give a clear pass or fail on the deterministic code around the model, the code that must keep working through every change. What the model says lies outside them. [1]
Two kinds of behaviour
Brightline's requirements come in two kinds. The refund rule is the first: one break is a failure, however good the rest of the reply. Each issue_refund call carries an amount, and an amount above $50 with no escalate_to_person call asking a person for approval breaks the rule. A program reads the recorded tool calls and decides. Such a rule is a hard invariant. A deterministic check decides it: code that gives the same verdict every time it reads the same output. Checks written in code are the fastest and most reliable kind. [3]
The second kind is the refund guidance itself. A customer asks how long they have to ask for a refund, search_help returns the help page, and the page gives 14 days. Two replies the assistant could give, both invented:
> A: You can ask for a refund within 14 days of your order. > > B: Our help page gives you 14 days from the order date. Shall I look up your order to check?
Both are right. A test that stores A and asserts the reply equals it fails B, a correct reply, over wording alone. The same happens with nothing changed: send the identical question twice and one run can come back as A and the next as B (non-determinism). Exact equality suits answers with one clear-cut form, such as a category label. For a reply in free text, a fixed pass-or-fail comparison is often the wrong tool. [1,3]
So the expected value moves from a string to a property of the outcome: the reply states the 14-day window from the help page and no other window. That sentence is a success criterion. It names something anyone can observe, what the reply states or which tool the assistant called, where "the assistant gives good refund advice" names nothing a check could decide. Checking such criteria over many questions, and comparing the results between versions, is an eval. [1,3]
The eval loop
Every eval repeats the same few steps; call them the eval loop. It takes two inputs: a named system under test and a list of cases. Each case is an input plus what counts as success, which someone on the team writes down, here from the help page. How the cases are chosen and written is the subject of Eval Datasets, and how they are checked the subject of Eval Graders. As pseudo-code with invented function names:
def eval_run(system, cases):
results = []
for case in cases:
reply, tool_calls = system.run(case.input)
verdict, reason = check(case, reply, tool_calls)
results.append((case.id, verdict, reason))
return summarise(results)
compare(eval_run(candidate, cases), eval_run(baseline, cases))check is a grader, the part of the eval that decides one case: it reads the recorded reply and tool calls against the case's criterion and returns pass or fail with the reason. summarise gathers the verdicts of one run, and compare lays the candidate's summary and its failed cases beside those of the baseline, the earlier version it is measured against, on the same cases. [1,2,3]
Run the refund-window case on the candidate. The record comes back with one tool call, search_help, and the reply "You have 30 days to request a refund." The check for the case's criterion fails it, with the reason "states 30 days; the help page gives 14". The $50 check reads the same tool calls, finds no issue_refund call, and passes.
That second check is deterministic, but its input is not: the model picks the refund amount afresh in every conversation, so a pass on one case says nothing about the next. The $50 check therefore runs on every case of the eval, not once like a unit test.
Baseline, candidate and regression
The 30-day failure on the candidate is not yet news: the assistant might always have got that case wrong. At Brightline the baseline is the configuration in production, the one with orbit-flash-2. If the baseline's reply stated 14 days and the candidate's states 30, a behaviour that worked has broken after a change. That is a regression, and only running the same cases on both systems shows it. [1,2,3]
The 30-day reply is easy to miss. Ask the candidate the question yourself and it may well say 14 days; ask in other words, or again, and 30 can appear. A fault that shows in some replies and not others slips past one hand-checked question and past one run of each case. So it is measured over many automatically checked cases that mirror what customers ask. [1,3]
Because one case can come back differently from run to run, each case is also run more than once; how to read a case that passes some runs and fails others comes later in this topic.
Sorting a behaviour
The sorting rule has two halves. If one break of a rule fails the case and a program can read the answer from the record, check it deterministically, as with the $50 rule. If several outputs can be right, or the same input gives different outputs, write an observable success criterion and run it as an eval over representative cases, against the baseline. Unit tests and the eval check different things, so a release of orbit-flash-3 needs both. [1,3]
Common mistakes
- A criterion nobody can check. Symptom: two reviewers disagree on whether a reply "handles refunds well". Fix: name what the reply states or which tool it calls, such as "states the 14-day window from the help page". [3]
Sources
- Why evaluate agents (Google ADK docs). Google. Checked 24 Oct 2026.
- Regression Testing and CI/CD (MLflow docs). MLflow project. Checked 24 Oct 2026.
- Define success criteria and build evaluations. Anthropic. Checked 24 Oct 2026.
Check yourself
Check yourself
Question 1 of 5
A library assistant (invented) can call "renew_loan(book_id, weeks)"; the model picks "weeks", and any number is accepted. Policy: at most 3 weeks per renewal. Which check should each eval case run?
Your first check counts towards your result.