Evals and Unit Tests
In this article
- List everything that belongs to the system under test, and say why changing one part of it gives a new system to measure.
- Sort a behaviour of an AI feature into a hard invariant for a deterministic check or a quality that needs an eval.
- Write a success criterion as an observable outcome 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
Here is a release that passes every test and still ships a bug. Brightline, a home-internet provider, runs a support assistant on its website. It answers customers, can look up an order, can issue a refund of at most $50, and can hand a conversation to a person on the support team. The team moves the assistant to a newer model, the whole unit test suite stays green, and the assistant starts telling some customers they have 30 days to ask for a refund. The help page gives 14. Brightline, its pages and its model names are invented for this example.
Why did no test notice, and what kind of check would have? The answer splits an AI feature's behaviour into two kinds: rules a short program can decide by reading the output, and qualities with many right answers, which need an eval.
What actually changed
The change looks like one line: the model version goes from orbit-flash-2 to orbit-flash-3. From here on, orbit-flash-2 is the baseline and orbit-flash-3 is the candidate.
But the reply a customer reads is not produced by the model alone. It comes out of a whole configuration:
- the model version;
- the prompt, kept as a prompt version, one saved, unchangeable state of the prompt text;
- four tools, functions the application runs when the model asks:
lookup_order,issue_refund,search_helpandescalate_to_person(reason, note); - the help pages that
search_helpreturns, 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 every request, such as temperature.
A new prompt, a model swap or a reworked tool can each silently break behaviour that used to work [2]. An assistant that searches a policy page or calls a tool is also judged on those steps, not only on its last message [1]. So what you test is the whole configuration, the system under test. Change any one item in the list, even only the model, and you have a different system, and its behaviour has to be measured again.
Why the unit tests stayed green
After the switch the team runs its unit tests. One gives the reply parser a stored sample reply and checks that it splits into the message for the customer and the list of tool calls. Another calls lookup_order with an order id and checks that the right record comes back. Both pass.
Before you read on: could either of them have caught the 30-day reply?
No. The parser test reads a reply someone saved once; it never asks the model anything. lookup_order is ordinary code that fetches a database row. Neither test runs what the model says, so swapping the model cannot turn them red. Unit tests give a clear pass or fail on code that must behave the same way through every change [1], and the code around the model is exactly that kind of code. They stop at the edge of the model.
Two kinds of behaviour
Brightline's requirements come in two kinds. The first is the refund rule. Every issue_refund call carries an amount. A call above $50 with no approval from a person breaks the rule, and one such call is a failure, however polite and accurate the rest of the conversation was. A program can read the recorded tool calls and decide: $50 holds, $50.01 without approval breaks it. A rule like this is a hard invariant. The check is deterministic: given the same record, it gives the same verdict every time. Code can grade a check like this automatically [3], and code checks are fast, cheap and reproducible [4].
The second is the refund guidance itself. A customer asks how long they have to ask for a refund. search_help returns the help page, which gives 14 days. Here are two replies the assistant could give:
> 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?
Both are correct. Now suppose the test stores reply A and asserts that the reply equals it. B fails, though nothing in it is wrong. Worse, you do not need a model change to see this: send the identical question twice and one run can come back as A and the next as B, because of non-determinism [5]. Exact matching suits answers with one clear-cut form, such as a category label [3]. For free text, a fixed equality check is brittle: it rejects valid variations that do not match the stored pattern [4].
So the expected value stops being a string and becomes a property of the outcome: the reply states the 14-day window from the help page. That sentence is a success criterion. It names something anyone can observe, what the reply states or which tool the assistant called. "Gives good refund advice" names nothing a check could decide; two reviewers would argue about it [3].
Checking criteria like this over many saved questions, on one named system, and comparing the results with another version is an eval. One saved question with its criterion is a case, and the part that decides a case, reading the record and returning pass or fail with a reason, is a grader.
The eval loop
Every eval repeats the same few steps. In pseudo-code, with invented names:
for each case:
reply, tool_calls = system.run(case.input)
verdict, reason = grade(case, reply, tool_calls)
summarise the verdicts of the run
compare the candidate's summary and failed cases with the baseline'sRun the refund-window case on the candidate. The record holds one tool call, search_help, and the reply "You have 30 days to request a refund." The grader 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 $50 check is deterministic, but what it checks is not: the model chooses whether to refund, and how much, afresh in every conversation. So the check runs on every case of the eval, not once as a unit test.
Baseline, candidate and regression
A failing case on the candidate is not yet news. Maybe the assistant always got that question wrong. To know, you need the baseline: the configuration in production, the one with orbit-flash-2, run on the same cases. If the baseline's replies state 14 days and the candidate's state 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 [2,4].
The 30-day reply is easy to miss. Ask the candidate the question yourself and it may well say 14 days; ask again, or in other words, and 30 can appear. A fault that shows in some replies and not in others slips past one hand-checked question, and even past one run of each case, because a case that passed once can fail the next time [4]. That is why a regression is measured over many cases that mirror what customers ask [3], each run more than once [4]; the rest of this topic builds those parts.
Sorting a behaviour
The rule has two halves:
- If one break fails the case and a program can read the answer from the record, it is a hard invariant: write a deterministic check, and run it on every case, because the model produces what it checks.
- If several outputs can be right, or the same input can give different outputs, write an observable success criterion and run it as an eval against the baseline.
Unit tests and the eval check different things, so the orbit-flash-3 release needs both: the unit tests for the parser and lookup_order, the eval for what the assistant says and does.
:::note In an interview "How would you test an LLM feature?" Split the answer: unit tests for the deterministic code, deterministic checks for hard rules on every eval case, and observable success criteria compared against a baseline for everything with many right answers. :::
Common mistakes
- Asserting the exact reply. A stored string fails correct rewordings and flips between runs. Test a property of the outcome instead.
- A criterion nobody can check. "Handles refunds well" invites argument. Name what the reply states or which tool it calls [3].
- Testing "the model". Editing the prompt or a help page is also a new system under test, and needs the eval run again.
- Judging the candidate alone. A failure only becomes a regression when the baseline passed the same case.
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.
- Demystifying evals for AI agents. Anthropic. Checked 24 Oct 2026.
- Evaluation best practices. OpenAI. Checked 29 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.