The Big Question
So far, the LLM Applications unit has focused on making systems more capable: prompting, retrieval, tools, memory, and agents. LLM application evaluation flips the question.
How do we know the application actually works?
Imagine two travel assistants. One feels smarter. One feels faster. Which is actually better? Or suppose you change one line of a prompt and the result looks better on three examples. Did the system improve, or did you get lucky?
LLM systems are probabilistic. Many outputs can be acceptable, and the output space is enormous. That means quality must be measured statistically rather than judged from a few demos.
Core Intuition
Traditional software often has a clear input-output test. If the function receives 2 + 2, the correct output is 4.
LLM applications are messier. For the travel assistant, a good response may vary in wording while still being correct. The system may call several tools, retrieve documents, ask for confirmation, and produce a final answer. We need to evaluate the whole behavior, not only one string.
The dangerous beginner habit is asking: Does it look good? That is anecdotal testing. Real evaluation asks: across representative cases, how often does it work, how does it fail, what does it cost, and did the latest change regress anything?
Interactive Demo
Application version
| Test prompt | Expected behavior |
|---|---|
| Find the cheapest flight from Vancouver to Tokyo next Friday under $900. | Select a flight under $900 or explain none exists. |
| Check whether I am free before booking. | Call calendar before purchase and ask for approval. |
| Include arrival weather in the itinerary. | Use weather tool and cite forecast time. |
A release should satisfy quality, groundedness, tool accuracy, latency, and cost requirements across a representative evaluation set.
judge score
supported by evidence
right tool and args
aggregate
Known trade-offs
- slower
- higher token cost
- grounding improves, but latency and cost increase
Swap versions and toggles. Notice the trade-off: better grounding and quality can cost more latency and money, and robustness can drop under attacks.
Evaluation As Measurement
At the simplest level, an evaluation dataset is:
The application produces predictions:
A metric scores the outputs:
The scoring function may be exact matching, a rubric score, a retrieval metric, a tool-call check, a human rating, or an LLM judge.
A/B Testing Intuition
In production, users may be randomly assigned to version A or version B. If version A succeeds on of tasks and version B succeeds on , the observed difference is:
A confidence interval asks whether that difference is likely real or could be noise. The practical lesson is not the formula. It is that online changes should be measured on enough traffic to distinguish improvement from luck.
What Should We Measure?
There is no single quality number for LLM applications. The right metrics depend on the product goal.
| Correctness | Did the answer or action satisfy the task? |
| Faithfulness | Are claims supported by retrieved evidence or tool results? |
| Helpfulness | Is the answer useful to the user? |
| Safety | Did the system avoid harmful or unauthorized behavior? |
| Latency | How long did the user wait? |
| Cost | How many tokens, API calls, and tool calls were used? |
| Robustness | Does it work under typos, ambiguity, attacks, and long context? |
| User satisfaction | Do users trust and prefer the experience? |
Quality often lives on a Pareto front. A version can be more accurate but slower and more expensive. Another can be cheap and fast but less robust. Evaluation makes those trade-offs visible.
Offline And Online Evaluation
Offline evaluation runs a fixed dataset before deployment. It is repeatable, safe, and excellent for regression testing. Online evaluation observes real users in production. It captures reality, but it is noisier and requires careful experiment design.
Offline
Evaluation dataset, fixed cases, repeatable metrics, safe before deploy.
Online
Real users, A/B tests, monitoring, ratings, escalations, drift.
Strong teams use both. Offline tests prevent obvious regressions. Online monitoring catches real-world behavior that the test set missed.
| Evaluation type | Purpose | Example |
|---|---|---|
| Unit tests | Deterministic logic | Parser, validator, tool dispatcher |
| Offline benchmarks | General quality before deployment | Run a fixed dataset after each change |
| Golden datasets | Application-specific correctness | Expected answers, tool calls, citations, retrieved chunks |
| Human evaluation | User quality and nuanced judgment | Experts rate helpfulness and safety |
| LLM judge | Automated subjective scoring | A model scores faithfulness, relevance, or style |
| Production monitoring | Real-world behavior | Latency, failures, ratings, drift, escalations |
Benchmarks And Golden Datasets
Public benchmarks such as MMLU, HumanEval, SWE-bench, GPQA, and SimpleQA are useful for general capability signals. But application-specific golden datasets are often more valuable.
For the travel assistant, a golden example might include:
{
"question": "Find the cheapest Vancouver to Tokyo flight under $900.",
"expected_answer": "A flight under $900 or a clear explanation that none exists.",
"expected_tools": ["search_flights"],
"forbidden_tools": ["book_flight"],
"expected_citations": [],
"safety_rule": "Do not book without confirmation."
}Golden datasets should include ordinary cases, edge cases, ambiguous requests, adversarial prompts, long conversations, tool failures, retrieval failures, and known historical bugs.
LLM Application Metrics
Classification metrics like accuracy, precision, recall, F1, and ROC-AUC still matter when the task is classification. But LLM applications add new surfaces.
| Area | Metrics |
|---|---|
| Retrieval | Precision@k, Recall@k, MRR, NDCG |
| RAG answer | Faithfulness, citation correctness, answer relevance, completeness |
| Tool use | Tool selection accuracy, argument validity, execution success |
| Agents | Task completion, planning quality, iterations, recovery, tool efficiency |
| Safety | Refusal quality, policy violations, prompt-injection resistance |
| Product | User rating, retention, conversion, escalation rate |
Agent evaluation is especially trajectory-based. You should inspect task completion, planning quality, tool efficiency, number of iterations, recovery after failures, and whether the agent stopped safely.
Human Evaluation And LLM Judges
Some qualities are difficult to score with exact matching. Helpfulness, tone, relevance, and faithfulness often need judgment.
Human evaluation is high quality but expensive and slow. LLM-as-a-judge uses another model to score outputs according to a rubric. It is faster and cheaper, but can be biased, inconsistent, sensitive to wording, and overly impressed by confident prose.
Evidence: ...
Answer: ...
Rubric:
1 = unsupported, 3 = partially supported, 5 = fully supported.
Pairwise evaluation is often easier than absolute scoring. Instead of asking whether an answer deserves a 4 or a 5, ask which of two answers is better and why.
Regression Testing
Every meaningful prompt, model, retrieval, tool, or orchestration change should rerun evaluation. This mirrors software engineering CI/CD.
Run golden dataset
Compare metrics to baseline
Block deploy if quality drops or safety fails
Deploy
Monitor production
This is how teams avoid shipping a prompt that fixes one demo but breaks twenty hidden cases.
Production Monitoring And Error Analysis
Production monitoring tracks latency, failures, tool errors, retrieval failures, hallucination reports, user ratings, escalations, cost, traffic mix, and drift.
Error analysis classifies failures by component:
| Retriever | Relevant evidence was not retrieved |
| Planner | The agent chose a poor sequence of steps |
| Tool | Wrong tool, bad arguments, timeout, or permission failure |
| Memory | The system forgot constraints or repeated work |
| Prompt | Instructions were ambiguous or contradictory |
| Model | The model hallucinated or misread evidence |
| Application | The wrapper truncated context, mishandled state, or exposed unsafe actions |
This diagnostic mindset matters. A bad answer may be a retrieval bug, planner bug, tool bug, memory bug, prompt bug, model bug, or application bug. The fix depends on the source.
Implementation
Simple Evaluation Framework
def run_eval(dataset, assistant, scorer):
results = []
for example in dataset:
output = assistant(example["input"])
score = scorer(example, output)
results.append({
"id": example["id"],
"output": output,
"score": score,
"passed": score >= example.get("threshold", 0.8),
})
pass_rate = sum(row["passed"] for row in results) / len(results)
average_score = sum(row["score"] for row in results) / len(results)
return {
"pass_rate": pass_rate,
"average_score": average_score,
"results": results,
}Regression Gate
baseline = load_metrics("main_branch_eval.json")
candidate = run_eval(dataset, assistant, scorer)
if candidate["pass_rate"] < baseline["pass_rate"] - 0.02:
raise RuntimeError("Regression: pass rate dropped too much")
if candidate["average_latency_ms"] > 4000:
raise RuntimeError("Regression: latency budget exceeded")
save_report(candidate)Real systems add slice metrics, judge explanations, sampled traces, dashboard links, and owner routing for failures.
Interview Discussion
Why is LLM application evaluation different from traditional testing?
Many outputs can be acceptable, quality is multi-dimensional, and the system may involve retrieval, tools, agents, latency, and cost.
What is a golden dataset?
An application-specific test set with expected answers, tool calls, citations, retrieved documents, or behavior requirements.
Why evaluate retrieval separately from generation?
If the right evidence never reaches the prompt, the generator cannot use it.
What are the risks of LLM-as-a-judge?
Judge models can be biased, inconsistent, sensitive to rubrics, and misaligned with human preferences.
Why is regression testing important?
It prevents prompt, model, tool, or retrieval changes from improving a few demos while breaking many hidden cases.
Active Recall
1. Why is anecdotal testing not enough for LLM applications?
2. What is the difference between model evaluation and application evaluation?
3. What belongs in a golden dataset for a travel assistant?
4. When would you use human evaluation instead of exact matching?
5. What are precision@k and recall@k used for?
6. Why do agents need trajectory-level evaluation?
7. What can go wrong with LLM-as-a-judge?
8. Why should every prompt change rerun the evaluation suite?
Common Mistakes
- Cherry-picked demos. A few impressive examples do not prove the system works.
- Small datasets. Tiny eval sets are noisy and miss edge cases.
- Judge bias. LLM judges can prefer verbose, confident, or stylistically familiar answers.
- Data leakage. If examples appear in training, tuning, or prompt examples, evaluation becomes inflated.
- Metric gaming. Optimizing one metric can degrade real user value.
- Confirmation bias. Developers often notice examples that support the change they wanted to make.
Connection To Building Reliable AI Systems
Evaluation is not something you do after building an AI application. It is part of the application itself. Every meaningful change should be measured, not guessed.
The next step is product design: how to build AI systems that users trust, enjoy using, and can rely on under real-world constraints of latency, cost, safety, observability, and deployment.