Dev tools
LLM Evaluation: How to Test an AI App
LLM evaluation shows whether your AI app actually works. Learn to build a golden dataset, use code checks and LLM-as-a-judge, and catch regressions early.
LLM evaluation is how you find out whether an AI app actually does its job, and whether it still does after you change something. Language models don't behave like normal code. The same prompt can give different answers, a small prompt edit can fix one case and break three others, and a new model version can change behaviour overnight. Without evaluation, every change is a guess.
This guide explains how to test an AI app in practice: what to measure, how to build a test set, when to use simple code checks and when to use another model as a judge, and how to catch regressions before your users do. You don't need a big platform to start. A spreadsheet of examples and a short script are enough for the first version.
Why LLM Evaluation Is Different
With traditional software, you write a test like "2 + 2 must equal 4," and it passes or fails the same way every time. AI apps make that harder:
- Many right answers. A support reply can be worded a hundred ways and still be correct.
- Randomness. The same input can produce different outputs.
- Quality is fuzzy. Tone, helpfulness and completeness aren't simple yes-or-no checks.
- Everything is connected. Changing the prompt, the model, the retrieval step or a tool definition can affect every answer.
So LLM evals measure behaviour across many examples and report scores, not single pass-or-fail results. The goal is to know, with numbers, whether a change made things better or worse.
Start With a Golden Dataset
A golden dataset is a fixed set of example inputs with a description of what a good answer looks like. It's the foundation of everything else.
How to build one
- Collect real inputs. Use actual user questions, support tickets or documents where you can. Real data beats invented examples.
- Cover the important cases: common requests, tricky edge cases, questions the app should refuse, and inputs in every language you support.
- Write the expected outcome. Not necessarily the exact answer, but what it must contain, must not contain, or how it should behave.
- Start small. Thirty to fifty well-chosen examples is a useful first set. Grow it over time.
- Add every bug. Each time your app fails in production, add that input to the set so the failure can't quietly return.
Keep the golden dataset separate from any data you use to tune prompts or fine-tune a model. Otherwise you're testing on the answers you studied, and the scores will look better than reality.
Three Kinds of Checks
Use the cheapest check that can do the job.
1. Code-based checks
Simple rules your code can verify, quickly and for free:
- The output is valid JSON with the right fields.
- A classification is one of the allowed labels.
- The answer includes a required phrase, link or number.
- The answer doesn't contain banned words or personal data.
- The response stays under a length limit.
If your app returns structured data, our guide to LLM JSON output covers how to make the format itself reliable, which makes these checks much easier.
2. Reference comparisons
When there's a known correct answer, compare against it: exact match for labels and numbers, or a similarity score for text. These work well for extraction, classification and question answering with clear facts.
3. LLM-as-a-judge
For qualities that rules can't capture, such as helpfulness, tone, faithfulness to a source document or completeness, you can ask another language model to grade the output. This is called LLM-as-a-judge.
Give the judge a clear rubric, not a vague question. "Does the answer use only facts from the provided document? Answer yes or no, then explain" works far better than "Is this answer good? Rate 1–10."
Calibrate your judge
An LLM judge is itself a model, with its own blind spots. Known problems include favouring longer answers, favouring answers written in its own style, and inconsistent scores. Before you trust a judge:
- Have a person label 30 to 50 examples.
- Compare the judge's grades with the human labels.
- Adjust the rubric until they mostly agree.
- Re-check now and then, especially when you change the judge model.
A Simple Evaluation Script
You can start with a few lines of Python. This example checks that answers include what they must and avoid what they mustn't:
CASES = [
{"input": "Where is my order #1234?",
"must_include": ["1234"], "must_not_include": ["refund approved"]},
{"input": "Can I get a refund after 60 days?",
"must_include": ["30 days"], "must_not_include": []},
]
def run_evals(cases, ask):
"""ask(text) -> answer string: your app, prompt and model together."""
failures = []
for case in cases:
answer = ask(case["input"]).lower()
ok = all(s.lower() in answer for s in case["must_include"]) and \
not any(s.lower() in answer for s in case["must_not_include"])
if not ok:
failures.append({"input": case["input"], "answer": answer[:200]})
score = 1 - len(failures) / len(cases)
return score, failuresRun it before and after every change. If the score drops, look at the failures before you ship. As your needs grow, open-source tools and hosted platforms can add judges, dashboards and history, but the idea stays the same.
Regression Testing: Run Evals on Every Change
The biggest win from evaluation is regression testing: running your eval set every time something changes and blocking changes that make results worse.
Things that should trigger a run:
- Any prompt edit.
- A new model or model version.
- Changes to retrieval, such as document splitting, the embedding model or search settings.
- New or changed tool definitions.
- Changes to the system's guardrails or filters.
Fast code checks can run on every commit. Slower and more expensive judge-based evals can run before each release. Decide your threshold in advance, for example "no drop of more than a few points against the current version," and stick to it.
Dealing with randomness
Because outputs vary, a single run can mislead you. Run important evals several times and look at the average, set the model's temperature low for tests where you want consistency, and don't react to tiny differences that disappear on the next run.
What to Measure
Pick a few metrics that match what your app is for:
- Correctness: does it give the right answer or take the right action?
- Faithfulness: for apps that answer from documents, does it stick to the source? This matters most for retrieval-based apps, and it's one of the trade-offs discussed in our comparison of fine-tuning vs RAG.
- Format: does it follow the required structure?
- Safety: does it refuse what it should, avoid leaking data and resist manipulation such as prompt injection?
- Tone and helpfulness: does it sound right for your brand and actually solve the problem?
- Speed and cost: how long does each answer take, and how many tokens does it use?
Don't try to measure everything. Three to five metrics that track real user value are worth more than twenty that nobody reads.
Evaluating in Production
Offline tests can't predict everything real users will do. Once the app is live:
- Log inputs and outputs (with privacy rules in place).
- Sample real conversations and score them with the same checks and judges.
- Collect user feedback, such as thumbs up or down, and review the negatives.
- Turn failures into test cases in your golden dataset.
This closes the loop: production shows you new problems, and your eval set makes sure each one stays fixed.
LLM Evaluation Mistakes to Avoid
- Testing only happy paths. Include edge cases, refusals and hostile inputs.
- Trusting an uncalibrated judge. Check it against human labels first.
- Changing the test set and the app at the same time, which makes scores impossible to compare.
- Chasing a single number. Read the failures, not just the score.
- Waiting too long. Start with a small eval set on day one and improve it as you go.
FAQ
What is LLM evaluation?
It is the process of testing a language model or AI app against a set of examples to measure how well it performs on things like correctness, format, safety and tone. It tells you whether the app works and whether changes make it better or worse.
What is a golden dataset?
A golden dataset is a fixed collection of example inputs with a description of what a good output looks like. Teams run it against their AI app after every change to compare results over time.
What is LLM-as-a-judge?
It is a method where one language model grades the output of another against a rubric, such as whether an answer is faithful to a source document. It's useful for qualities that simple code checks can't measure, but it should be checked against human judgement.
How many examples do I need for LLM evals?
Thirty to fifty well-chosen examples is a good start for most apps. Grow the set over time, especially by adding every real failure you find in production.
How often should I run evals?
Run fast checks on every change to prompts, models, retrieval or tools, and fuller evaluations before each release. Also score a sample of real production traffic regularly to catch problems your test set missed.