My account

LLM evaluation (evals)

An eval is a test for an AI feature. Collect a set of real and hard example cases, score each answer with code checks, a model judge or people, and run the set on every change to the prompt or the model. Check your model judge against human labels, look at groups of cases and not only the average, and keep learning from production.

Not reviewedWritten with AI helpReading time: 13 minOnline shop exampleTypeScript

Author: bezzad

Contents

The problem: “it looks better to me”

Our shop’s review summaries were too long. A developer changed the prompt: “Write shorter points.” They tried it on five products, liked the results and shipped it.

Two weeks later, support found these problems:

  1. Products with few reviews now got confident summaries from only two reviews.
  2. Mixed reviews lost their “dislikes”. Shorter answers dropped the bad news first.
  3. Reviews in two languages sometimes got a summary in the wrong language.

Five examples cannot show this. And with AI, a small change in one place can quietly break something in another place. Normal unit tests do not catch it, because the answer is text, and it can be a little different each time.

We need tests for AI behavior. They are called evals.

What is an eval?

An eval has three parts:

  1. A set of cases. Inputs, for example the reviews of 150 products.
  2. A way to score each answer. Code checks, a model judge, or people.
  3. A habit of running it. On every change to the prompt, the model, the input data or the code around them.

Think of it as unit tests for a feature whose answers are not exact.

Build the case set

The case set is the most valuable part. Build it with care.

  1. Start from real data. Use real inputs from production, with personal data removed. Made-up examples are often too easy.
  2. Cover the normal cases. Products with many clear reviews.
  3. Add the hard cases on purpose. Few reviews, mixed opinions, long reviews, two languages, jokes, rude text, and a review that tries to give the model orders.
  4. Add every bug. When a bad answer is found in production, add it to the set. Then it can never come back silently.
  5. Tag each case. For example “few-reviews”, “mixed”, “two-languages”, “injection”. Then you can see scores per group.
  6. Start small. 30 to 50 good cases are much better than none. Grow the set over time.
Expected properties, not exact text. You usually cannot write the one correct answer. Write what a good answer must do instead: “mentions the bad battery”, “has no likes when all reviews are negative”, “says nothing about water”.

Ways to score an answer

Use the cheapest check that works. Then add stronger ones where needed.

1. Code checks

Fast, cheap and exact. Use them for everything they can check:

  1. Shape. The answer passes the schema.
  2. Length. At most three points, each under 80 characters.
  3. Safety. No email addresses or phone numbers in the answer.
  4. Rules. If there are fewer than five reviews, there is no summary.
  5. Language. The summary uses the same language as the page.

2. A model as a judge

Some questions need understanding, for example: “Is every point in the summary supported by at least one review?” For these, you can ask a model to judge. This is often called LLM as a judge.

  1. Ask clear, small questions. “Is this point supported by the reviews? Answer yes or no, and quote the review.” This works better than “rate the summary from 1 to 10”.
  2. Give the judge the input too. It needs the reviews to check support.
  3. Score one thing at a time. Support, missing dislikes, tone: separate questions.

3. People

People are the slowest and most expensive judges, but they are the ground truth.

  1. Label a sample by hand, for example 100 cases, with the same yes or no questions.
  2. Use people to check the judge, not to review every answer.
  3. Review a small random sample from production every week.

Check the judge before you trust it

A model judge is also a model. It can be wrong in ways that look fine. Research has reported judges that prefer longer answers, or answers that look like their own. So before you use a judge, compare it with human labels.

Human saysGoodBadJudge saysGoodBad7015bad answers passed312Agreement is 82 of 100, but the judge caught only 12 of 27 bad answers.
Agreement looks good, but the judge passes most of the bad answers. That is the number that matters here.
  1. Agreement alone can lie. If most answers are good, a judge that always says “good” still agrees a lot.
  2. Look at the bad answers. How many bad answers did the judge catch? Here only 12 of 27.
  3. Improve the judge. Make the question smaller and clearer, add examples of bad answers, or ask for a quote as proof. Then measure again.
  4. Check again after changes. A new judge model or a new judge prompt needs a new check.

Run evals like tests

Make evals part of your normal work.

A changeprompt, model, codeRun the eval set150 saved casesComparewith the current versionNo groupgot worseship behind a flagA groupgot worsestop and fixLook at each group of cases,not only the average
Every change runs the eval set and is compared with the current version, group by group.
const results = [];
for (const c of cases) {
  const out = await summarizeFrom(c.reviews);
  results.push({
    id: c.id,
    tags: c.tags,
    validShape: c.expectSummary ? out !== null : out === null,
    noPersonalData: out === null || !hasPersonalData(out),
    supported: out === null || (await judgeSupported(out, c.reviews)),
  });
}
report(results); // pass rate per check and per tag
  1. Run on every change to the prompt, model, model settings or the code that builds the input.
  2. Compare with the current version, not with a perfect score. “Is the new one better or worse than what users have now?”
  3. Look per group. The average can go up while the “few-reviews” group gets much worse.
  4. Run more than once when it matters. Answers vary. A score that changes a lot between runs is not reliable.
  5. Keep the cost in mind. Code checks can run on every commit. Model judges can run on every prompt change or every night.
  6. Also track speed and cost. A better answer that is three times slower may not be better for users.
Group Cases Current version New prompt
Many clear reviews 60 95% 97%
Mixed opinions 40 88% 70%
Few reviews 25 92% 60%
Two languages 15 80% 82%
Injection attempts 10 100% 100%
Average 150 91% 82%

Here the new prompt is better for “many clear reviews”, but much worse for “mixed” and “few reviews”. The average shows only that something got worse, not what. With more easy cases in the set, a gain there could even hide the drop completely.

Online: learn from production

Offline evals check what you thought of. Production shows what you did not.

  1. User feedback. “Was this helpful?” buttons, and reports of wrong summaries.
  2. Behavior. Do people who see the summary buy more, or return less? Compare groups behind a feature flag.
  3. Sampled review. People read a small random sample every week, and add bad cases to the set.
  4. Alerts. Watch the share of failed schema checks, empty summaries and cost per day.

Common mistakes

Mistake Result Right way
“Looks good on five examples” Silent breaks in other cases. A tagged case set, run on every change.
Only easy, made-up cases High scores, bad production. Real data, hard cases, every past bug.
One 1 to 10 quality score Vague and noisy. Small yes or no questions with proof.
Trusting the judge without a check Bad answers pass. Compare with human labels, look at caught bad answers.
Only the average Hidden drops in important groups. Scores per group.
Running evals once before launch Later changes break things. Run on every prompt, model and input change.
Tuning only for the eval set Good scores, poor real quality. Keep adding new cases from production.

Summary in six lines

  1. An eval is a case set, a way to score, and the habit of running it.
  2. Build the set from real data, add hard cases and every past bug, and tag them.
  3. Use code checks first, a model judge for meaning, and people as the ground truth.
  4. Check the judge against human labels, especially on bad answers.
  5. Run evals on every change and compare with the current version, group by group.
  6. Keep learning from production and grow the set.

Done reading this lesson?Mark it as finished so it shows in your lessons list and report card.