How to Evaluate LLMs: Metrics, Benchmarks, and Hallucination Detection
Evaluating LLMs is harder than training them. This guide covers automated metrics, human evaluation, and production monitoring — the complete toolkit for measuring LLM quality.
Introduction
Evaluating LLMs is harder than training them. This guide covers automated metrics, human evaluation, and production monitoring — the complete toolkit for measuring LLM quality.
Prerequisites
- ✓ Experience using LLMs in applications
- ✓ Basic statistics knowledge
- ✓ Understanding of your evaluation use case
Key Concepts
Step-by-Step Guide
- 1
Define Your Evaluation Criteria
Before evaluating, define what "good" means for your use case. Common criteria: Accuracy (is the answer correct?), Completeness (does it cover all aspects?), Helpfulness (is it useful to the user?), Safety (does it avoid harmful content?), Format (does it follow the required format?).
Tip: Write down your criteria as a rubric with 1-5 scales. This makes evaluation consistent across evaluators and time. - 2
Build a Golden Dataset
Create a dataset of 100-500 questions with reference answers. Include: easy/medium/hard questions, edge cases, adversarial examples, and diverse topics. This dataset is your benchmark for all future evaluations. Never train on it — only evaluate.
Warning: Your golden dataset has a shelf life. If your model changes or your task evolves, update the dataset. A stale dataset gives misleading results. - 3
Use Automated Metrics for Quick Iteration
Automated metrics are fast and cheap but limited: Exact Match (for factual Q&A), BLEU (for translation), ROUGE (for summarization), BERTScore (semantic similarity). Use these for quick iteration during development, but always validate with human evaluation.
pythonfrom evaluate import load exact_match = load("exact_match") bleu = load("bleu") bertscore = load("bertscore") em_score = exact_match.compute(predictions=preds, references=refs) bleu_score = bleu.compute(predictions=preds, references=refs) semantic_sim = bertscore.compute(predictions=preds, references=refs, lang="en") - 4
Implement LLM-as-Judge Evaluation
Use a strong model to evaluate outputs. Provide the question, the response, and a rubric. The judge model rates the response 1-10 with an explanation. This is 10-100x cheaper than human evaluation and correlates ~0.85 with human judgments.
pythonjudge_prompt = """ Rate this response on accuracy (1-10): Question: {question} Reference: {reference} Response: {response} Rate 1-10 and explain: """ - 5
Run Human Evaluation
For final evaluation, use human raters. Best practices: 3 raters per example, calculate inter-annotator agreement (Cohen's kappa > 0.6), use side-by-side comparison (model A vs model B), and blind the raters to which model generated which output.
Tip: Use platforms like Scale AI, Surge AI, or your own team. For specialized domains, use domain experts as raters — general raters may not catch technical errors. - 6
Evaluate for Safety and Hallucination
Hallucination detection: cross-reference outputs against a trusted source, use a second model to verify claims, or use self-consistency (ask the same question multiple ways and check if answers agree). Safety evaluation: use red-team prompts and check for harmful outputs.
Warning: Hallucination rates vary dramatically by topic. Models hallucinate more on obscure topics, recent events, and numerical data. Always evaluate on your specific domain. - 7
Use Standard Benchmarks
For general model comparison, use standard benchmarks: MMLU (knowledge across 57 subjects), HumanEval (code generation), GSM8K (grade-school math), TruthfulQA (hallucination tendency), MT-Bench (multi-turn conversation). Run these with the lm-evaluation-harness framework.
bash# Run MMLU with lm-eval-harness lm_eval --model hf --model_args pretrained=meta-llama/Llama-3-70B \ --tasks mmlu,human_eval,gsm8k \ --output_path results/ - 8
Implement Production Monitoring
In production, monitor: user feedback (thumbs up/down), response length distribution, confidence scores, latency, and error rates. Set up alerts for: sudden drops in user satisfaction, increased hallucination reports, or unusual response patterns.
LLM evaluation is not just about quality — it includes safety, fairness, and alignment monitoring in production. - 9
Set Up A/B Testing
For model updates, use A/B testing: route 10% of traffic to the new model, compare user satisfaction, task completion, and error rates. Statistical significance requires ~1000 interactions per variant. Use Bayesian A/B testing for faster decisions.
Tip: A/B test not just the model but the prompt, the system message, and the response format. Sometimes a prompt change has bigger impact than a model change. - 10
Create an Evaluation Dashboard
Build a dashboard showing: golden dataset scores over time, production user satisfaction trends, hallucination rate trends, and comparison with previous model versions. This dashboard is your source of truth for model quality.
Warning: Dashboards can be misleading. Always look at raw examples, not just aggregate scores. A 90% average can hide a 0% on an important subset.
Summary
LLM evaluation requires multiple methods: automated metrics for quick iteration, LLM-as-judge for cost-effective scaling, and human evaluation for ground truth. Build a golden dataset, define clear criteria, and monitor production continuously. The biggest mistake is relying on a single metric — always triangulate across multiple evaluation methods.
Frequently Asked Questions
For automated metrics: 100-500 examples. For human evaluation: 50-200 examples (with 3 raters each). For production monitoring: all traffic (passive) + 100-500 sampled for active evaluation.
LLM-as-judge correlates ~0.85 with human judgments for general tasks. It is less reliable for: code quality, domain-specific accuracy, and subtle safety issues. Always validate with some human evaluation.
Use self-consistency (ask multiple times, check agreement), cross-reference with trusted sources, or use a fact-checking model. For production, track user-reported hallucinations and investigate patterns.
GPT-5: ~92%, Claude 4: ~90%, Gemini 3: ~89%, LLaMA 3 70B: ~82%. For domain-specific applications, create your own benchmark rather than relying on general ones.
Test Your Knowledge
1. What is the main limitation of BLEU and ROUGE metrics?
BLEU and ROUGE measure surface-level n-gram overlap. A response can have low BLEU score but be semantically correct, or high BLEU score but be wrong. They are most useful for translation and summarization.
2. How well does LLM-as-judge correlate with human evaluation?
LLM-as-judge typically correlates at ~0.85 with human judgments for general tasks. It is a cost-effective proxy but should be validated with human evaluation, especially for domain-specific tasks.
3. What is the most important practice for LLM evaluation?
No single evaluation method is sufficient. Combine automated metrics, LLM-as-judge, human evaluation, and production monitoring for a complete picture of model quality.