Justine Acosta
JUSTINE ACOSTA · GMT+8 ·
All articles
BLOG / ARTICLE

Evals: How to Know Your AI Feature Actually Works

You changed the prompt and the output looks better. Is it? Without a way to answer that, every improvement is a guess and every fix is a coin flip.

6 min readAIEvalsPrompt engineering

Here's the loop almost every team falls into. Someone reports a bad output. You tweak the prompt. The bad case looks right now. You ship.

Two weeks later a different case is broken, one that used to work. Nobody knows which change caused it, because nobody was measuring. So you tweak again.

That loop is where a lot of AI features live, and it's an uncomfortable place to run a product from. The way out is evals: a repeatable measurement of whether the thing does its job. It's the least glamorous work in AI engineering and, by a wide margin, the highest-leverage.

Why your existing tests don't cover this

Traditional tests assert equality. Given this input, expect exactly this output. That model breaks here for two reasons.

The output is non-deterministic : the same prompt can produce different text across calls. And more fundamentally, there's often no single correct answer. Twelve different summaries of an article can all be good. Asserting on the string is meaningless.

So evals measure something looser: does the output have the properties we need? That sounds soft, and it's where teams give up. It shouldn't be. Most of what you need to check is entirely concrete.

Build the dataset before you pick a metric

The instinct is to start by choosing what to measure. Wrong order. Start by collecting examples, because the examples will tell you what matters.

Twenty to fifty real inputs. Not synthetic ones you invented: real ones, from your logs or your users. Include:

  • The obvious happy path cases, maybe half.
  • The weird ones. Empty input, enormous input, wrong language, someone pasting an entire contract into a field expecting one sentence.
  • Every case that has ever been reported as broken.

That last category is the engine of the whole system. Every production failure becomes a permanent test case. This is the single habit that separates features that get better over time from features that oscillate.

Store it as data in the repo, not in someone's notebook:

// evals/categorize.jsonc
[
  {
    "input": "I was charged twice for my October invoice",
    "expect": { "category": "billing" },
  },
  {
    "input": "the export button does nothing on safari",
    "expect": { "category": "technical" },
  },
]

Three kinds of checks, in order of cost

Not everything needs a sophisticated evaluation. Reach for the cheapest tool that answers the question.

1. Structural checks. Does the output parse? Does it validate against the schema? Is the category one of the four allowed values? Is the summary under the length limit? Did it avoid inventing a field?

These are ordinary assertions, they cost nothing, they run in milliseconds, and they catch a surprising share of real failures. If your feature returns structured output, and it should, this tier alone gets you a long way.

2. Reference-based checks. For tasks with a right answer: classification, extraction, routing. You have the expected label, so you can compute accuracy directly.

The nuance is that not all errors cost the same. Misrouting a billing question to the technical queue is a minor annoyance. Categorizing an urgent security report as "other" is a real incident. Weight your metric accordingly, or at minimum look at the confusion matrix instead of a single accuracy number: the number hides exactly the failure you care about.

3. Judge-based checks. For open-ended output where there's no reference answer, you use a model to grade the output. This works, and it's also the tier where people fool themselves most, so it deserves care.

Using a model as judge, reliably

Three rules make this reliable.

Judge one criterion at a time. Asking "is this summary good, 1-10" produces noise. Asking "does this summary contain any claim not present in the source document: yes or no" produces a signal you can act on. Decompose quality into specific, binary, checkable properties:

  • Is every factual claim supported by the source?
  • Does it answer the question that was asked?
  • Does it stay in the requested format?
  • Does it avoid the phrases we told it not to use?

Give the judge a rubric, not an adjective. "Professional tone" means nothing to a grader. Spell out what passes and what fails, ideally with one example of each. The judge prompt deserves the same care as the feature prompt.

Validate the judge against humans. Label thirty examples yourself, then run the judge on the same thirty. If they disagree more than a little, the judge needs work, and until it does, its numbers aren't measuring what you think they are. This takes about an hour, and it's an easy step to skip, but skipping it means making decisions on a figure that doesn't mean much.

Also: use a different model for judging than for generating where you can. A model asked to grade its own output is a generous grader.

Measure the things that aren't quality

Quality is one axis. These will end the feature just as fast:

  • Cost per call, and per user per month. This is the number that determines whether the feature survives a finance review.
  • Latency, at p50 and p95. The p95 is what people complain about.
  • Failure rate : schema validation failures, timeouts, API errors. Your fallback path is load-bearing, so know how often it's carrying load.
  • Refusal rate. If the model declines a task it should do, that's a regression, and it's invisible unless you're counting.

Track these alongside the quality metric in the same run. A prompt change that improves accuracy by two points and doubles cost is usually a bad trade, and you can only see that if both numbers are on the same table.

Wire it into CI

An eval suite you run manually is an eval suite you stop running.

Run it on every change to a prompt file or the surrounding code. Print the before-and-after side by side. Fail the build on a regression past a threshold you agree on in advance.

The uncomfortable part is that thresholds are a product decision, not a technical one. 94% accuracy is fine for suggesting tags and unacceptable for routing safety reports. Someone has to decide, in the open, before you're in the middle of a release.

Also: pin your model version. A provider quietly rolling you forward to a new snapshot will move every number you have, and you'll spend a day looking for a change in your code that doesn't exist.

Start smaller than feels right

The reason teams don't do this is that it sounds like a research project. It isn't.

Twenty examples in a JSON file, a script that runs them, and a printed accuracy number is roughly a day of work, and it's the difference between improving the feature and shuffling it. You'll extend the set every time something breaks, which is the point.

If you're adding an AI feature to a product that already works, the eval set comes before the rollout, not after. It's the thing that tells you whether the rollout is safe.