← All essays

AI product engineering

Making the thinking legible / 01 / 03 · … min

Write the eval before the prompt

An AI feature without an evaluation set is a demo. How to turn “it feels better” into a number you can ship against.

01 /

The demo trap

Every AI feature starts with a good demo. Someone writes a prompt, tries five inputs, and four of the answers are impressive. The fifth gets a quick fix in the prompt. The team ships.

Then the reports arrive. The fix for the fifth input quietly broke two others nobody looked at. A model update changed the tone. A customer in another language gets answers that are confidently wrong. Each problem is patched by hand, and each patch is judged the same way the first prompt was: by reading a few outputs and deciding they feel better.

Language models are not deterministic functions you can test once. Their behaviour shifts with wording, context, temperature and model version. Without a fixed set of cases to measure against, every change is a guess, and the guesses compound. Building an AI product starts with something less exciting than the prompt: the test it has to pass.

02 /

An eval is a spec you can run

An evaluation set is a collection of realistic inputs, each paired with what a good output must do. It does not need to be large to be useful. Thirty to a hundred cases taken from real usage, or from the situations you are most afraid of, will catch more than any amount of manual spot-checking.

The key move is to write down properties, not exact answers. You rarely know the one right sentence, but you do know that the output must be valid JSON, must cite the document it used, must stay under 120 words, must refuse to give medical dosages, must answer in the user’s language. Those properties are the product specification, written in a form a machine can check.

Fig. 01 / A minimal eval harness in Python
from dataclasses import dataclass
from typing import Callable
import json

@dataclass
class Case:
    input: str
    checks: list[Callable[[str], bool]]
    tag: str                      # the slice this case belongs to

def is_json(out: str) -> bool:
    try:
        json.loads(out)
        return True
    except ValueError:
        return False

def under(n: int) -> Callable[[str], bool]:
    return lambda out: len(out.split()) <= n

def run(model, cases: list[Case]) -> dict[str, float]:
    results: dict[str, list[bool]] = {}
    for case in cases:
        out = model(case.input)
        passed = all(check(out) for check in case.checks)
        results.setdefault(case.tag, []).append(passed)
    return {tag: sum(r) / len(r) for tag, r in results.items()}

Thirty lines is enough to start. The model is any function from text to text, so the same suite can compare prompts, models and providers.

03 /

Grade properties, not strings

Start with checks that are cheap and certain: parsing, length, required fields, forbidden phrases, whether a cited source actually exists. They run in milliseconds, never disagree with themselves, and catch a surprising share of real failures.

Some qualities cannot be checked by code: is the answer helpful, is the tone right, did it actually address the question? Here a second model can act as a grader, scoring each output against a short rubric. That grader is itself a model and can be wrong, so treat it like any other instrument. Have people label a sample, measure how often the grader agrees with them, and refine the rubric until the agreement is high enough to trust. A grader you have never checked is just a more expensive opinion.

04 /

Read the failures, not the average

A single pass rate is comforting and dangerous. An overall improvement can hide a regression in exactly the group of users you cannot afford to fail. Tag every case with the slice it belongs to, and report each slice separately.

Fig. 02 / The average improved. One slice did not.
SlicePrompt v1Prompt v2Change
Refund questions90%97%+7
Dates and deadlines85%95%+10
Non-English78%66%−12
All cases84%86%+2

Illustrative numbers for three equal-sized slices, rounded. Shipping v2 on the total alone would make the product worse for every non-English user.

Then read the failing outputs themselves. Ten minutes with the actual failures teaches more than any dashboard: you see whether the model misunderstood, whether the case was ambiguous, or whether the check was wrong. All three happen, and only one of them is the model’s fault.

05 /

Make the eval the gate

Once the suite exists, run it on every change: a new prompt, a new model version, a new retrieval setting. Treat some checks as must-pass, such as safety refusals and output format, and block the change if any of them fail. Treat quality scores as a trend to watch, not a single threshold to game.

Measure cost and latency in the same run. A prompt that adds three points of quality but doubles the response time is a product decision, not a technical one, and the eval is what makes that trade-off visible. It also changes how model upgrades feel. Without an eval, a new model is a risky migration. With one, it is an afternoon: run the suite, read the diffs, decide.

06 /

Keep it alive

An eval set is never finished. Every failure reported in production becomes a new case, so the same mistake can only happen once. Cases that every version passes easily can be retired or made harder. Over time the set becomes the most precise description of what the product is supposed to do, more precise than any document, because it is checked every day.

That is the real reason to write it first. The prompt is a guess about how to get good behaviour. The eval is the definition of good behaviour. Teams that keep the definition separate from the guess can change the guess as often as they like.