LLM evaluation turns prompt improvement from guesswork into a repeatable engineering process. This guide shows how to build a practical test set, score responses, compare models, estimate usage cost and latency, detect hallucinations, and add prompt regression checks before release.
Overview
A prompt that produces one impressive answer is not necessarily a better prompt. Reliable evaluation asks whether the prompt works across the requests your application is expected to handle, including ambiguous inputs, long documents, missing information, malformed data, and adversarial instructions.
For most AI development projects, evaluation should measure four related outcomes:
- Quality: Is the response correct, relevant, complete, and usable?
- Safety and reliability: Does the system avoid unsupported claims, private-data leakage, prompt injection failures, and unsafe actions?
- Operational performance: Does it meet latency, token, throughput, and availability requirements?
- Economics: Can the application deliver its required quality within its expected usage budget?
These dimensions should be tracked separately. A model may produce more accurate answers while using more tokens, taking longer to respond, or failing a required output format. Combining every result into one score can hide trade-offs that matter in production.
Start with a small evaluation suite rather than trying to test every possible prompt. A focused set of representative cases is easier to inspect, maintain, and run whenever you change a prompt, model, retrieval configuration, or application workflow. For a broader testing architecture, see the LLM Evaluation Test Suite guide.
How to estimate
Use a fixed evaluation workflow so that each prompt or model version is tested under comparable conditions.
1. Define the decision you are making
Write down what “better” means before reviewing outputs. For example, you may be deciding whether a new prompt improves support-ticket classification, whether a smaller model is adequate for summarization, or whether a retrieval change reduces unsupported answers.
2. Build a representative test set
Include normal cases, difficult cases, boundary cases, and known failures. Label each example with useful metadata such as task type, language, document length, customer segment, or expected difficulty. Keep a separate holdout set when possible so that prompt changes are not optimized only for examples the team has repeatedly inspected.
3. Run controlled comparisons
Hold the user input, retrieved context, system instructions, generation settings, and output schema constant while comparing prompt versions or models. Record the model identifier and configuration used for every run. If a provider or application changes behavior over time, the recorded configuration helps explain why results moved.
4. Score with a rubric
Use deterministic checks where possible. A JSON parser can verify whether required fields are present and valid. A citation checker can confirm that referenced documents exist in the supplied context. Human review or an evaluator model can assess qualities such as helpfulness, completeness, and tone.
A reusable five-point rubric can use the following dimensions:
- Correctness: 0 = wrong or unsupported; 1 = partially correct; 2 = correct.
- Instruction following: 0 = ignores key requirements; 1 = partly follows them; 2 = follows them fully.
- Grounding: 0 = contradicts or invents information; 1 = partly supported; 2 = supported by the provided context.
- Format: 0 = unusable format; 1 = minor deviations; 2 = valid and complete format.
Define what qualifies for each score before evaluation begins. If an evaluator model is used, validate it against a sample of human-labeled responses instead of treating its judgment as an unquestionable ground truth.
5. Calculate outcome, cost, and latency
For a quality metric, use:
Pass rate = passing test cases ÷ total test cases × 100
For a weighted score, calculate each response score, add the scores, and divide by the maximum possible score. Weight critical cases separately if an error in one category is more serious than an error in another.
For usage planning, use recorded or estimated values rather than assumptions:
Estimated monthly tokens = requests per month × average input tokens + requests per month × average output tokens
If your provider charges different rates for input and output, apply the current provider rates to each component. Do not copy a price into a permanent benchmark; store pricing inputs separately and update them when the provider changes its published terms.
Inputs and assumptions
A useful evaluation record should contain enough information for another developer to reproduce the result. Capture these inputs:
- Prompt version, including system, developer, and user instructions.
- Model name or deployment identifier and relevant generation settings.
- Test-case ID, input, expected behavior, and any supplied context.
- Input and output token counts, when available.
- Time to first response and total response latency.
- Parser errors, tool errors, refusals, retries, and timeouts.
- Human, automated, or hybrid score and the reason for any failure.
Separate factual correctness from stylistic preference. A concise answer and a detailed answer may both be acceptable, while an invented fact is not. Also distinguish a model failure from an application failure. Missing retrieval context, truncated input, a broken tool call, or an incorrect post-processing step may be responsible for a poor final answer.
For applications using retrieval, test both answer quality and retrieval quality. An answer cannot be fairly judged as grounded if the correct source was never included in the context. For text-to-SQL systems, execute generated queries in a safe test environment and check their results, not only whether the SQL appears syntactically valid.
Worked examples
Suppose a team has 40 test cases for a summarization prompt. Version A passes 30 cases against the agreed rubric, while Version B passes 34. Their pass rates are 75% and 85%, respectively. That suggests an improvement, but the team should inspect the six changed cases rather than relying on the aggregate alone.
Now divide the test set into categories:
| Category | Cases | Version A passes | Version B passes |
|---|---|---|---|
| Short documents | 15 | 13 | 14 |
| Long documents | 15 | 9 | 13 |
| Ambiguous requests | 10 | 8 | 7 |
The overall result favors Version B, but its performance on ambiguous requests declined. The release decision may therefore depend on whether ambiguity is common and whether a clarification step can address the regression.
For cost estimation, assume an illustrative workload of 10,000 requests per month, with an average of 1,200 input tokens and 300 output tokens per request. The estimated monthly volume is 12,000,000 input tokens and 3,000,000 output tokens. Apply the current input and output rates for the selected model to those two quantities. If 15% of requests are retried, multiply the expected request volume by 1.15 rather than ignoring retries. This example uses hypothetical volumes; replace them with measurements from your application.
For pairwise comparison, show evaluators the responses from two versions in a randomized order and ask which is better, whether they are equivalent, or whether both fail. Pairwise results are especially useful when absolute scoring is difficult, but retain the failure reasons so the team knows what to change.
When to recalculate
Run the full evaluation suite before releasing a new prompt, model, retrieval pipeline, output schema, tool definition, or safety control. Run a smaller smoke suite on every code change that can affect the AI workflow. Add a regression test whenever a production incident reveals a failure mode.
Recalculate cost estimates when request volume, average context length, output limits, retry rates, model selection, batching strategy, or provider pricing changes. Recalculate latency estimates when infrastructure, streaming behavior, tool calls, concurrency, or prompt length changes. Keep the date and assumptions next to every benchmark so an old result is not mistaken for a current promise.
Before approving a release, use this checklist:
- Did the test set include normal, difficult, and known-failure cases?
- Were prompt and model versions recorded?
- Did quality improve without unacceptable safety or format regressions?
- Were hallucinations and unsupported claims reviewed?
- Were latency, token usage, retries, and estimated cost measured?
- Were changes inspected by category rather than only by average score?
- Was at least one holdout or newly added test set used?
Evaluation is most valuable when it becomes part of the development workflow rather than a one-time benchmark. Store test cases in version control, review score changes alongside code changes, and keep failed examples available for future prompt testing. When designing prompts, the reliable AI prompts framework and few-shot prompting guide can help explain why a change may improve one category while harming another.