# Evals

> The Evals are systematic tests that measure the quality and reliability of AI model outputs.

## What are evals for LLM apps and how do I write them?

The sets of test cases with expected results used to measure how well a model or prompt solves a task. Allow comparing models and detecting regressions after changing prompts, similar to tests in regular code.

- Topic: Quality & Operations
- Type: practice

## Example

Wrong:

```js
const answer = await summarize(sampleText);
console.log(answer); // looks good
```

Right:

```js
const cases = [
  { input: refundEmail, expect: (out) => out.category === 'refund' },
  { input: emptyEmail, expect: (out) => out.category === 'unknown' },
];
for (const c of cases) {
  const out = await classify(c.input);
  if (!c.expect(out)) failed.push(c);
}
console.log(`${cases.length - failed.length}/${cases.length} passed`);
```

A fixed set of cases with pass checks, including edge cases, gives a score you can compare after every prompt or model change.

## Common mistakes

- Testing only a few happy-path examples by hand and calling it evaluated.

## Key points

- The eval set uses real or realistic inputs, including hard and edge cases.
- Each case has a clear pass criterion, such as an exact match, a check function or a grading rubric.
- Evals run on every prompt or model change, and scores are compared with the previous run.

## Interview questions

### What is the difference between evals and unit tests?

Unit tests expect the same output every time. Evals measure how often a non-deterministic model passes, so results are scores, not just pass or fail.

### How many test cases does an eval need?

Start with a few dozen real cases, including hard and edge cases, and add every bug found in production as a new case.

### How do I evaluate open-ended answers?

Use check functions where possible, and an LLM judge with a clear rubric for the rest, validated against human labels.

## Related cards

- [LLM-as-a-Judge](https://wonderium.dev/ai/llm-as-a-judge.md)
- [Benchmark](https://wonderium.dev/ai/benchmark.md)
- [Dataset](https://wonderium.dev/ai/dataset.md)
- [LLMOps](https://wonderium.dev/ai/llmops.md)
- [Regression](https://wonderium.dev/engineering/regression.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/evals
- Last updated: 2026-11-25
