All posts
aitesting

Evals Are the Tests for the AI Features You Ship

You can't assert exact output from a model, but you can assert a lot. How we test an AI feature with a golden set, cheap code checks, a rubric-graded judge, and a CI run on every prompt change.

Muhamad Choirul Adam 3 min readPhoto: Unsplash

Most of what I've written about AI this year is about using it to build software. This one is about shipping it: a feature where the model's output reaches users. We added one that summarizes an inspection report into three lines for a project manager.

The first version worked well in the demo. A week later someone tweaked the prompt to fix one bad summary, and quietly broke five others. Nobody noticed for days. That's what evals are for.

Why normal tests don't fit

A unit test asserts an exact output. A model gives slightly different wording every run, and a prompt change can improve most cases while breaking a few. You need tests that check properties, not strings, and that run across many examples at once.

The setup

Rendering diagram…

1. A golden set from real data

Forty real reports, anonymized, picked to cover the cases that matter: a clean report, one with critical defects, one in broken English, one that's mostly empty. Each has notes on what a good summary must include. Real inputs beat invented ones every time; invented ones are too tidy.

2. Cheap code checks first

Before any model grades anything, plain assertions catch the obvious failures:

summary.eval.ts
const checks = [
  (out: string) => out.split("\n").length <= 3 || "more than three lines",
  (out: string, c: Case) => c.criticalCount === 0 || /critical/i.test(out) || "missed critical defects",
  (out: string) => !/as an ai/i.test(out) || "model talking about itself",
];

These are fast, free, and never flaky. A surprising share of regressions get caught here.

3. A judge with a rubric for the rest

Some things code can't check: is the summary faithful to the report, does it lead with what matters? For those, a second model grades each output against a short rubric:

Score 1-5 for each:
 
- Faithful: every claim appears in the report.
- Priority: the most serious issue comes first.
- Plain: a project manager understands it without the report.
 
Return JSON: { faithful, priority, plain, reason }.

Two rules make the judge trustworthy: a specific rubric, not "is this good?", and a spot-check where I grade twenty cases by hand and compare. When the judge and I disagreed, the fix was almost always a vaguer rubric line than I thought.

4. Run it on every prompt change

Prompts, model versions, and the code around them live in the repo. Any PR that touches them runs the eval and compares the scores against main. A drop beyond a small threshold fails the check, and the PR shows which cases got worse.

What it changed

  • Prompt changes became reviewable. "Fixed case 12, cases 3 and 31 slightly worse" is something a reviewer can judge. "Tweaked the prompt" isn't.
  • Model upgrades became a one-line PR. Switch the model, read the eval diff, decide.
  • Bad outputs turn into cases. When a user reports a bad summary, it goes into the golden set first, and then we fix it. Same habit as writing a regression test before fixing a bug.

The feature is still non-deterministic. But now we know when it gets worse, which is all a test suite ever really promised.