LLM evaluation: offline evals, online evals, and metrics
LLM evaluation measures whether an LLM system does its job. How to build the dataset, run offline and online evals, choose metrics, and gate a release.
- Published
- Reading time
- 10 min read
In short
- LLM evaluation measures whether your system does its task well enough to ship, on inputs like the ones it will see. A public benchmark score does not answer that question.
- Build the eval set from real failures and real traffic, and add every new production failure to it.
- Run offline evals as a regression suite on every prompt, model, or retrieval change, and online evals on a sample of live traffic. They catch different problems.
- Report a standard error with every score. On a few hundred cases, a two-point difference is usually noise.
LLM evaluation is the practice of measuring whether a system built on a language model does its job well enough to ship. That means scoring its outputs on inputs like the ones it will see in production, against criteria that describe success for that task. A support bot is evaluated on whether it resolves tickets correctly, not on a general knowledge benchmark.
Good LLM evaluation has three parts: a dataset of realistic cases, checks that score each output, and a statistical habit that tells you whether a change in score is real. This article covers all three, plus the decision they exist to support: whether a change can go to production.
What to evaluate: the task, not the model
Evaluate the task your system performs, with criteria written for it. A model's score on a public benchmark says how it does on someone else's questions. It does not say whether your prompt, retrieval, and tools produce correct answers for your users. Two systems on the same model can differ more than two models on the same system.
Start by writing down what a good output is, as a list of checkable properties. For a support assistant that answers refund questions, the list might be:
- The answer states only refund rules that appear in the policy.
- It answers the question the customer asked.
- It asks for an order number when one is needed and missing.
- It hands off to a person when the customer asks for one.
- It returns valid JSON in the shape the frontend expects.
Each line becomes a check. Some are code, some need a model, and some need a person. That list, not a single quality score, is the evaluation.
Build the dataset from real failures
The dataset decides what your evals can catch, so build it from real inputs, weighted toward the ones that went wrong. Start with 50 to 100 cases drawn from production logs, support tickets, and bug reports, and grow it every time a new failure appears. Cases a developer invents at a desk tend to be easier than real ones.
Each case needs an input and enough information to grade the output: a reference answer, the documents the answer should rely on, or the properties it must have. Label the cases by slice, such as language, customer tier, or question type. A change that improves the average and breaks one slice is a regression for the customers in that slice.
Keep the dataset in version control next to the prompts. When a case turns out to be mislabeled, fix it in a commit, so a score change can be traced to a code change or a data change and not a mystery.
Offline evals: a regression suite for every change
Offline LLM evaluation runs the dataset through the system before a change ships and compares the scores with the current version. Treat it like a test suite: run them in CI on every change to a prompt, a model, a retrieval setting, or a tool definition. Their job is to catch regressions before users do.
Compare against a baseline run on the same cases, not against a number from last month. Models and providers change underneath you, so a fixed target drifts. A paired comparison, the same cases through the old and new versions, also cancels out the difficulty of individual questions, which makes small differences easier to detect.
LLM outputs vary between runs even on the same input. For cases that matter, sample each output more than once and average the scores per case. That is one of the variance-reduction steps Anthropic recommends, covered in the error bars section below.
Online evals: grading live traffic
Online evals score a sample of production traffic after the response has been sent. They catch what a fixed dataset cannot: new kinds of questions, a shift in what users ask, a provider model update that changed behavior, and slow decay in retrieval quality. Run them asynchronously so grading never adds to user latency.
Sample a fixed share of requests plus every request a user flagged, retried, or escalated. Attach each score to the request's trace, so you can ask which prompt version, model, or input size the failures share. The observability article covers that trace, and if your model traffic already passes through a gateway such as Bifrost (an open-source AI gateway by Maxim AI), its request logs are a ready-made source for the sample.
The loop in the figure is the point. A failure found online is triaged, labeled, and added to the dataset, so the offline suite catches it next time. A dataset that never grows from production is testing last quarter's problems.
LLM evaluation metrics, by type
LLM evaluation metrics fall into four types: code checks, reference-based overlap scores, model-graded checks, and human review. They differ in cost, speed, and what they can judge. Use the cheapest type that can decide each criterion, and use human review to keep the others honest.
| Type | Examples | Use it for | Weakness |
|---|---|---|---|
| Code checks | Exact match, JSON schema validation, regex, tool-call argument checks | Format, structure, extracted values, required phrases | Cannot judge meaning or tone |
| Reference overlap | BLEU, ROUGE, embedding similarity to a reference | Translation and short extraction with one right answer | Rewards wording, not correctness |
| Model-graded | An LLM judge with a rubric | Relevance, policy compliance, faithfulness, tone | Has biases, needs calibration |
| Human review | Expert graders with the same rubric | Calibrating judges, high-stakes slices, new criteria | Slow and expensive |
Reference overlap is the type to be most careful with. The G-Eval authors note that BLEU and ROUGE have relatively low correlation with human judgment, especially on creative and open-ended tasks. A correct answer phrased differently from the reference scores poorly, and a wrong answer that reuses its words scores well.
Model-graded checks carry most of the load for open-ended output. They need their own validation, which the LLM as a judge article covers step by step. Add operational metrics to every run as well: cost per case, latency, and tool calls per task. A prompt that gains two points of quality and doubles the cost is a decision, not a win.
RAG evaluation: score retrieval and generation separately
RAG evaluation scores the two halves of a retrieval-augmented system on their own: did retrieval find the right documents, and did generation use them correctly? A single end-to-end score cannot tell you which half failed. A wrong answer from good documents is a prompt problem. A wrong answer from the wrong documents is a retrieval problem.
The Ragas framework, introduced in a 2023 paper by Es and colleagues, defines metrics for each half. Its current documentation names them as follows:
| Metric | Half | What it measures | Needs a reference |
|---|---|---|---|
| Context precision | Retrieval | Whether relevant chunks are ranked above irrelevant ones | Depends on the variant |
| Context recall | Retrieval | How much of the relevant information was retrieved | Yes |
| Faithfulness | Generation | Whether each claim in the answer is supported by the retrieved context | No |
| Response relevancy | Generation | Whether the answer addresses the question | No |
Faithfulness is the metric most teams start with, because it needs no reference answer and catches claims the documents do not support. The hallucination detection article explains how it works and where it falls short. Context recall needs references, so compute it on the offline dataset rather than on live traffic. The RAG evaluation article covers the full metric set, the test set, and how to read a result.
Error bars: when a difference is real
Every LLM evaluation score is an estimate from a finite sample, and small samples move a lot by chance. Report a standard error or confidence interval with every score, and treat differences inside it as noise. Without error bars, teams ship changes that did nothing and revert changes that worked.
Anthropic's paper on the subject, by Evan Miller, makes five recommendations. Report the standard error of the mean, which gives a 95 percent interval of the mean plus or minus 1.96 standard errors. Cluster standard errors when questions come in groups, because clustered errors on popular evals can be over three times as large as naive ones. Reduce variance by resampling answers per question. Compare models with paired differences on the same questions. And use power analysis to size the dataset before you run it.
The arithmetic is short. A suite of 300 cases with an 85 percent pass rate has a standard error of the square root of 0.85 times 0.15 divided by 300, about 2.1 points. The 95 percent interval is roughly plus or minus 4 points. A new prompt that scores 87 percent on that suite has not been shown to be better.
When to block a release
Block a release when a hard criterion fails or when a score drops beyond its error bars, overall or on any slice you have committed to. Everything else is a judgment call to record, not a gate. Gates that fire on noise get ignored, and gates that get ignored stop protecting anything.
Split the checks into two kinds:
- Hard gates must pass on every case. Safety rules, policy violations, leaking data, and invalid output formats belong here. One failure blocks the release.
- Score gates compare against the baseline. A drop larger than the confidence interval blocks the release, measured separately for each slice so an average cannot hide a broken one.
The cost of gating is release speed. A full suite with model-graded checks takes minutes and costs real money on every change. Run code checks on every commit and the full suite before merge, and the cost stays proportionate.
Tools for running evals
Several open-source tools run LLM evaluation suites, and the choice matters less than the dataset you feed them. Pick one that fits where your code lives and how you run tests today. All of the tools below can call an LLM judge and run in CI.
| Tool | Shape | Fits |
|---|---|---|
| promptfoo | CLI and library with declarative configs, MIT license | Prompt comparisons and red-teaming from config files |
| DeepEval | Python, described as similar to Pytest for LLM apps, Apache 2.0 | Teams whose tests already run in pytest |
| Ragas | Python metrics library | RAG metrics in an existing pipeline |
| Inspect | Python framework from the UK AI Security Institute | Model and agent evaluations with reproducible tasks |
Whichever tool you use, keep the dataset and the rubrics in your own repository in a plain format. Tools change. The cases you collected from production are the asset.
Frequently asked questions
What is LLM evaluation?
LLM evaluation is the process of measuring how well a system built on a language model performs its task. It runs the system on a dataset of realistic inputs and scores each output with code checks, model-graded checks, or human review. The scores decide whether a change to a prompt, model, or retrieval setup is safe to release.
What are LLM evals?
LLM evals are the individual tests in an evaluation suite. Each eval pairs an input with a way to grade the output, such as an exact-match check, a JSON schema, a reference answer, or an LLM judge with a rubric. Teams run evals offline in CI before a release and online on a sample of live traffic after it.
What metrics are used to evaluate LLMs?
The common LLM evaluation metrics are code checks such as exact match and schema validation, reference-overlap scores such as BLEU and ROUGE, model-graded scores from an LLM judge, and human ratings. RAG systems add retrieval metrics such as context precision and recall, and faithfulness for the answer. Operational metrics such as cost and latency belong in every run.
How do you evaluate a RAG system?
Score retrieval and generation separately. For retrieval, measure context precision and context recall against documents you know are relevant. For generation, measure faithfulness to the retrieved context and relevance to the question. Separate scores show which half to fix. Ragas defines all four metrics, and faithfulness can run on live traffic because it needs no reference answer.
What is the difference between offline and online evaluation?
Offline evaluation runs a fixed dataset through the system before a change ships, like a regression test suite. Online evaluation grades a sample of real production traffic after responses are sent. Offline evals catch regressions on known cases. Online evals catch new kinds of inputs, drift, and provider changes. Failures found online should become new offline cases.
How many test cases do you need for LLM evals?
Start with 50 to 100 real cases and grow from there. The number you need depends on the size of difference you want to detect. On 300 cases with an 85 percent pass rate, the 95 percent confidence interval is about plus or minus 4 points. To detect a 2-point change reliably, you need a larger set, paired comparisons, or both.
Sources
- 01Ragas: Automated Evaluation of Retrieval Augmented GenerationarXiv:2309.15217
- 02Available metricsRagas docs
- 03Adding Error Bars to Evals: A Statistical Approach to Language Model EvaluationsarXiv:2411.00640
- 04A statistical approach to model evaluationsAnthropic
- 05G-Eval: NLG Evaluation using GPT-4 with Better Human AlignmentarXiv:2303.16634
- 06promptfooGitHub
- 07DeepEvalGitHub
- 08InspectUK AI Security Institute