LLM Evaluation: Metrics, Benchmarks and Eval Pipelines (with Code)
Key Insights
- Word overlap is not correctness. In this article’s Python example, the wrong answer “Lyon is the capital of France.” scored the same ROUGE-2 (0.60) and ROUGE-L (0.67) as the correct answer. Lexical metrics need factuality checks beside them.
- Classic metrics often miss human judgement. The G-Eval research paper on GPT-4-based evaluation notes that BLEU and ROUGE correlate poorly with human ratings, especially on creative tasks. G-Eval reached a Spearman correlation of 0.514 with humans on summarisation.
- LLM judges are useful but biased. In the MT-Bench and Chatbot Arena study of LLM judges, GPT-4 as a judge reached over 80% agreement with human preferences, the same level humans reach with each other. The study also found position, verbosity and self-enhancement biases.
- Benchmarks are broad, not personal. The MMLU benchmark paper covers 57 subjects, the GSM8K dataset paper introduces 8.5K grade-school maths problems and the BIG-bench paper describes 204 tasks from 450 authors. None of them reflects your users’ prompts.
- Sampling settings change scores. In the original HumanEval paper, Codex solved 28.8% of problems with one sample and 70.2% when 100 samples per problem were drawn. Always report how many samples you generate and how you score them.
- Fluency can hide falsehoods. On the TruthfulQA benchmark’s 817 questions across 38 categories, the best model tested was truthful on 58% of questions, against 94% for humans. The largest models were generally the least truthful.
- Perplexity depends on the test setup. The Hugging Face guide to perplexity shows GPT-2 Large scoring 19.44 or 16.44 on WikiText-2, depending only on the evaluation stride. Compare perplexity only under identical tokenisation and context settings.
- Instruction following can be checked by code. The IFEval instruction-following benchmark uses 25 types of verifiable instructions across about 500 prompts. Rule-based checks like these avoid judge bias entirely.
- RAG needs two scorecards. The Ragas metrics documentation separates retrieval metrics (context precision, context recall) from generation metrics (faithfulness, response relevancy). Response relevancy does not check factual accuracy, so pair it with faithfulness.
LLM evaluation is the process of measuring how well a large language model performs on accuracy, relevance, reasoning, safety and reliability. It tells you whether a model is ready for real users.
Evaluating large language models differs from testing traditional ML models. LLMs generate open-ended responses, and one question can have several acceptable answers, so a simple right-or-wrong check rarely works.
That is why teams combine evaluation metrics, standard benchmarks and automated evaluation pipelines. Systematic testing exposes hallucinations, inconsistent outputs and performance issues before users do.
This guide shows how to select LLM evaluation metrics, use benchmarks wisely and build an automated LLM evaluation pipeline with Python code.
Your roadmap to becoming a Generative AI Engineer
See what you already know, what to learn next and how long the switch to a GenAI engineering role takes. Tap any step for what to study and build.
What's inside8 stages · 30 steps to job-ready
- Python & engineering foundations
- ML & deep learning essentials
- How LLMs work
- Prompting & building LLM apps
- RAG & model customisation
- Agents & tool use
- Production, evaluation & safety
- Portfolio & job readiness
Python & engineering foundations
What to study
- Core Python: data types, functions, classes, modules
- Virtual environments and package management (pip, uv)
- Writing clean, testable scripts
What to build
A command-line script that reads a CSV, cleans it and writes a summary report.
What to study
- SQL joins, aggregations and window functions
- pandas for cleaning and reshaping data
- Working with text data at scale
What to build
A notebook that cleans a messy text dataset and prepares it for a model.
What to study
- Git branching and pull requests
- How REST APIs work: HTTP methods, status codes, auth headers
- Reading and writing JSON
What to build
Call a public API from Python, handle errors and save the results as JSON.
What to study
- Vectors, matrices and dot products
- Probability and distributions
- Gradients and optimisation, intuitively
What to build
Implement cosine similarity and gradient descent from scratch in NumPy.
ML & deep learning essentials
What to study
- Supervised vs unsupervised learning
- Train/test splits, overfitting and evaluation metrics
- scikit-learn workflows
What to build
Train and evaluate a text classifier with scikit-learn.
What to study
- Tokenisation and text preprocessing
- Word embeddings and semantic similarity
- Sequence models (RNN, LSTM) and why transformers replaced them
What to build
Build a semantic search over 500 short texts using sentence embeddings.
What to study
- Layers, activations, loss functions and backpropagation
- Training loops, batching and GPUs
- PyTorch tensors and autograd
What to build
Train a fully connected network on a small dataset and plot its learning curve.
How LLMs work
What to study
- Self-attention and multi-head attention
- Encoder, decoder and encoder-decoder models
- Positional encoding and why scale matters
What to build
Walk through a minimal transformer implementation and explain each block in a short write-up.
What to study
- The Transformers library, model hub and datasets
- Running open-weights models locally
- Fine-tuning a pre-trained model for a task
What to build
Fine-tune a small pre-trained transformer for sentiment or topic classification.
What to study
- Closed vs open-weights model families
- Tokens, context windows, temperature and sampling
- Comparing models on cost, latency and quality
What to build
A comparison table of three models answering the same 20 prompts, with cost and latency.
What to study
- Quantisation, pruning and distillation
- When a small model beats a large one
- On-device and low-cost inference
What to build
Quantise an open model and compare its speed and quality against the original.
Prompting & building LLM apps
What to study
- System prompts, few-shot examples and chain-of-thought
- Prompt test sets and versioning
- Reducing hallucinations through prompt design
What to build
A prompt library with a 30-example test set and before/after scores.
What to study
- Calling LLM APIs: streaming, rate limits, keys
- Serving with FastAPI and simple UIs with Streamlit
- Caching and cost control
What to build
A small chat app with streaming responses, deployed for others to try.
What to study
- JSON schema outputs and validation
- Function / tool calling
- Retries and graceful failure
What to build
An invoice or resume parser that returns validated JSON.
What to study
- Chains, prompts and output parsers
- Document loaders and retrievers
- When a framework helps and when it gets in the way
What to build
Rebuild your chat app with LangChain and compare the code with your plain-API version.
RAG & model customisation
What to study
- Embedding models and similarity search
- Vector databases (e.g. pgvector, Pinecone, Weaviate)
- Chunking strategies and metadata filters
What to build
Index a document set in a vector database and query it with filters.
What to study
- Supervised fine-tuning vs prompting vs RAG
- LoRA and other parameter-efficient methods
- Preparing instruction datasets
What to build
LoRA fine-tune an open-weights model on a narrow task and compare it with prompting alone.
What to study
- Vision transformers and CLIP-style models
- Image captioning and visual question answering
- Combining text and image retrieval
What to build
An image search app that finds photos from a text description.
What to study
- The RAG pipeline end to end
- Re-ranking, hybrid search and citations
- Measuring retrieval quality
What to build
A document Q&A assistant that cites its sources, with a retrieval-quality report.
What to study
- Instruction tuning and reward models
- RLHF and DPO, conceptually and with TRL
- Where alignment fits in real products
What to build
Train a small reward model and run a preference-tuning loop on a toy task.
Agents & tool use
What to study
- ReAct, planning and reflection patterns
- Single-agent vs multi-agent setups
- Memory: short-term, long-term and retrieval
What to build
A research agent that searches, reads and summarises sources on a topic.
What to study
- Model Context Protocol (MCP) servers and clients
- Connecting agents to databases, CRMs and internal APIs
- Permissions and audit trails for tool calls
What to build
An MCP server that exposes two tools from a real API, used by your agent.
What to study
- Graphs, state and checkpoints
- Human-in-the-loop approvals
- Error handling in multi-step workflows
What to build
Rebuild your research agent as a LangGraph workflow with an approval step.
Production, evaluation & safety
What to study
- Docker images for AI apps
- CI/CD basics
- Secrets and environment configuration
What to build
Containerise your RAG assistant and deploy it with a CI pipeline.
What to study
- Building evaluation datasets
- LLM-as-judge and its limits
- Regression testing prompts and models
What to build
An eval harness that scores your assistant on 50 cases and runs on every change.
What to study
- Tracing LLM calls
- Tracking token cost and latency
- Dashboards and alerting
What to build
Add tracing and a cost dashboard to your deployed app.
What to study
- Managed model platforms on AWS, GCP and Azure
- Serverless deployment and autoscaling
- Data privacy and region choices
What to build
Deploy your app on one cloud using a managed model endpoint.
What to study
- Hallucination, bias and privacy risks
- Prompt injection and defences
- PII handling and content filtering
What to build
Add input and output guardrails to your assistant and document the risks you tested.
Portfolio & job readiness
What to study
- GenAI system design questions
- Explaining trade-offs: RAG vs fine-tuning, cost vs quality
- Coding rounds in Python
What to build
Mock-interview notes for three GenAI system design questions.
What to study
- Choosing a domain problem (healthcare, fintech, edtech)
- Writing clear READMEs and architecture notes
- Recording a short demo
What to build
A client-ready AI agent for one domain, with a public demo and write-up.
Fine-tuned text classifier
Adapting a pre-trained transformer to a real task.
Fine-tune a small pre-trained transformer on a labelled dataset, evaluate it properly and compare it with a classic ML baseline.
Structured data extractor
Turning messy documents into clean JSON.
Use an LLM API with schema-validated outputs to extract fields from invoices or resumes, with a prompt test set to track accuracy.
Document Q&A assistant
Retrieval-augmented answers with citations.
Index a document collection in a vector database and build an assistant that answers questions with cited sources and a retrieval-quality report.
LoRA fine-tune of an open model
Customising a model when prompting isn't enough.
Fine-tune an open-weights model with LoRA on a narrow task and document when it beats prompting and RAG, and when it doesn't.
Reward model & preference tuning
Teaching a model what good looks like.
Train a small reward model on preference data and run a preference-tuning loop, with a write-up of what changed.
Multimodal image search
Finding images from plain-language descriptions.
Embed images and text in a shared space and build a search app that retrieves photos from a description.
Tool-using research agent
An agent that plans, acts and asks for approval.
Build a LangGraph agent that searches, reads and summarises sources, calls tools through an MCP server and pauses for human approval.
Deployed GenAI service
From notebook to a monitored production API.
Containerise an LLM app, deploy it on a cloud platform with CI/CD, and add tracing plus a cost and latency dashboard.
Eval harness with guardrails
Proving your AI app works, and stays safe.
Create a 50-case evaluation set, automate scoring on every change, and add input and output guardrails against prompt injection and PII leaks.
Domain AI agent capstone
A client-ready agent for a real industry problem.
Pick a domain such as healthcare, fintech or edtech and ship an agent that combines retrieval, tools, evals and guardrails, with a public demo and write-up.
GenAI glossary 17 terms
Tap a term to see what it means. You will hear these in every GenAI interview.
- LLM
- Large language model: a neural network trained on huge amounts of text to predict and generate language.
- Transformer
- The neural network architecture behind modern LLMs, built around the attention mechanism.
- Token
- A chunk of text (often part of a word) that a model reads and writes. Pricing and limits are counted in tokens.
- Context window
- The maximum number of tokens a model can consider at once, including your prompt and its answer.
- Prompt engineering
- Designing instructions and examples so a model reliably produces the output you need.
- Embeddings
- Numeric vectors that capture meaning, so similar texts end up close together.
- Vector database
- A database built to store embeddings and find the most similar ones quickly.
- RAG
- Retrieval-augmented generation: fetching relevant documents and giving them to the model so answers are grounded.
- Fine-tuning
- Further training a pre-trained model on your own data to specialise it.
- LoRA
- Low-rank adaptation: a parameter-efficient fine-tuning method that trains small add-on weights instead of the whole model.
- Agent
- An LLM system that plans steps, calls tools and acts towards a goal, often over several turns.
- Tool calling
- Letting a model call functions or APIs, such as search or a database query, with structured arguments.
- MCP
- Model Context Protocol: an open standard for connecting AI applications to tools and data sources.
- Evals
- Systematic tests that measure how well an AI system performs on representative cases.
- Guardrails
- Checks on inputs and outputs that keep an AI system safe, on-topic and compliant.
- Hallucination
- When a model states something false or unsupported with confidence.
- Prompt injection
- An attack where malicious text tricks a model into ignoring its instructions.
Close your gaps with a structured programme
The Certificate Programme in Generative AI from CEP, IIT Delhi covers transformers, fine-tuning, RAG, agents and responsible AI through live weekend classes and hands-on projects.
How does LLM Evaluation Work?
LLM evaluation tests a model against a collection of representative inputs. Its responses are compared with expected outcomes or evaluation criteria, then scored with metrics chosen for the task.
The five steps below turn that idea into a repeatable process you can run before every release.
Step 1: Define the Evaluation Objective
Start by deciding what “good” means for your application. Typical dimensions include accuracy, factual correctness, relevance, reasoning, safety and latency.
Goals change with the product. A chatbot needs relevant, safe replies, while a coding assistant needs code that runs. A summarisation system needs faithful coverage, and a RAG application needs answers grounded in retrieved documents.
Step 2: Create an Evaluation Dataset
An evaluation dataset holds prompts plus expected answers, reference outputs or scoring criteria. Include typical requests, edge cases and deliberately challenging inputs, such as ambiguous or adversarial prompts.
The data should mirror real production usage, so scores predict real behaviour. Keep it separate from training and tuning data; otherwise, the model may have already seen the answers.
Step 3: Run the Model on Test Inputs
Send every prompt to the model under consistent settings, such as the same system prompt, temperature and maximum token limit. Changing settings mid-run makes results impossible to compare.
Collect each output with its response time, token usage and any errors. Record the model version and generation settings too, so you can reproduce any score later.
Step 4: Score the Generated Responses
Responses are scored by automatic metrics, model-based evaluators or human reviewers. Each response is compared against a reference answer or against defined quality criteria, such as correctness and clarity.
The right method depends on the task. Exact Match suits short factual answers, while open-ended writing usually needs semantic metrics, rubric-based judges or human review.
Step 5: Analyse Results and Improve the Model
Scores show where the model is weak, but error analysis explains why. Group failures into patterns, such as missing facts, wrong format, unsupported claims or refusals.
Those patterns guide the fix: a better prompt, improved retrieval, a different model or new application logic. Then you evaluate again to confirm the change helped.
Key point: LLM evaluation is a continuous process, not a one-time accuracy test performed before deployment.
What are the Different Types of LLM Evaluation Metrics?
LLM evaluation metrics are measurable indicators of model performance. Some check exact correctness, others measure word overlap, meaning or grounding in source documents.
No single metric captures every aspect of LLM quality. Reliable evaluation combines task-specific measurements, each chosen for what it can and cannot detect.
Accuracy and Exact Match
Accuracy is the proportion of predictions that are correct. Exact Match (EM) checks whether a generated answer matches the reference exactly, usually after lowercasing and removing punctuation.
Both suit classification and structured question answering, where answers are short and fixed. For open-ended responses, they fail: “The capital is Paris” scores zero against the reference “Paris”.
Precision, Recall, and F1 Score
Precision is the share of predicted positives that are correct. Recall is the share of actual positives the model finds. F1 is their harmonic mean, so it drops sharply if either one is low.
Say a model extracts 10 drug names from clinical notes, and 8 are correct: precision is 0.8. If the notes held 16 drug names, recall is 0.5, and F1 is about 0.62.
BLEU and ROUGE Scores
BLEU, introduced for machine translation, measures n-gram overlap between generated and reference text, with a penalty for overly short outputs. It is precision-oriented.
ROUGE is a family of metrics for comparing summaries with reference text, based on n-gram overlap and longest common subsequence. Both reward shared words, not shared meaning, so a correct paraphrase can score low.
BERTScore
BERTScore compares contextual token embeddings from the candidate and the reference, rather than relying only on exact word overlap. It reports precision, recall and F1 based on semantic similarity.
That makes it useful when correct answers use different wording. However, semantic similarity is not factual correctness: “The meeting is on Monday” and “The meeting is on Tuesday” look very similar.
Perplexity
Perplexity measures how well a language model predicts a sequence of tokens. It is the exponential of the average negative log-likelihood per token, so lower values mean better predictive performance on that text.
Scores depend on the tokeniser and test text, so compare models only under identical setups. Perplexity is not a direct measure of helpfulness or factual accuracy; a model can confidently predict false text.
Faithfulness and Hallucination Metrics
Faithfulness measures how well an answer is supported by its source context. Hallucination evaluation checks responses for unsupported or fabricated claims, often by verifying each claim against the context.
For RAG evaluation, context precision and context recall also assess what was retrieved. Source-grounded checks matter most in knowledge-intensive applications, such as legal, medical or policy assistants.
The table below compares these LLM evaluation metrics side by side. Use it to shortlist metrics that match your task before building an evaluation pipeline.
| Metric | What it measures | Common use case |
|---|---|---|
| Accuracy | Correct predictions | Classification |
| Exact Match | Exact answer match | Structured question answering |
| Precision | Correctness of positive predictions | Information extraction |
| Recall | Coverage of relevant positive cases | Entity or information extraction |
| F1 Score | Balance of precision and recall | Classification |
| BLEU | N-gram overlap | Machine translation |
| ROUGE | Reference-text overlap | Summarisation |
| BERTScore | Contextual semantic similarity | Text generation |
| Perplexity | Next-token predictive performance | Language modelling |
| Faithfulness | Support from provided context | RAG and grounded generation |
Key point: Choose metrics based on the task. A high BLEU score, for example, does not necessarily mean an answer is factually correct or useful.
What are LLM Benchmarks?
LLM benchmarks are standardised evaluation datasets and testing procedures. They compare the capabilities of different language models under the same defined conditions.
Because every model faces identical questions and scoring rules, benchmarks offer a shared reference point. They do not, however, test your specific application.
General Knowledge and Reasoning Benchmarks
MMLU tests multiple-choice knowledge across 57 subjects, from elementary maths to law. Reasoning benchmarks go further, testing problem-solving and multi-step reasoning, as in many of BIG-bench’s 204 diverse tasks.
Scores depend heavily on dataset design and evaluation methodology. Prompt format, the number of few-shot examples and how answers are extracted can all change a model’s result.
Mathematical and Coding Benchmarks
GSM8K contains 8.5K grade-school maths word problems that need several reasoning steps. Final numeric answers make scoring simple and objective.
HumanEval evaluates code generation with Python programming problems and hidden unit tests. This execution-based evaluation checks whether generated code passes the tests, reported as pass@k: the chance at least one of k samples passes.
Reading Comprehension and Question Answering Benchmarks
Question-answering datasets test whether a model can find information in a passage and answer correctly. They measure comprehension and response correctness rather than open-ended writing quality.
SQuAD is a reading comprehension benchmark with over 100,000 questions on Wikipedia articles, where each answer is a span of text. Generated answers are scored against the reference answers using Exact Match and F1.
Safety and Alignment Benchmarks
Safety evaluations test whether a model produces harmful, biased or policy-violating outputs. They also check whether it refuses appropriately without over-refusing harmless requests.
Robustness testing uses adversarial prompts, such as jailbreak attempts and prompt injections, to probe for weak spots. Safety must be evaluated alongside capability, because a more capable model is not automatically a safer one.
The table below summarises the most widely cited LLM benchmarks. It shows what each one focuses on and what its score can tell you.
| Benchmark | Primary focus | Evaluation purpose |
|---|---|---|
| MMLU | Knowledge across subjects | General knowledge and reasoning |
| GSM8K | Mathematical reasoning | Multi-step problem solving |
| HumanEval | Code generation | Functional correctness |
| SQuAD | Reading comprehension | Answer extraction and understanding |
| TruthfulQA | Truthfulness | Resistance to common misconceptions |
| BIG-bench | Broad model capabilities | Diverse language-model tasks |
Key point: Benchmarks provide useful comparison points, but performance on a benchmark does not guarantee success in a real production application.
What are the Different Approaches to LLM Evaluation?
LLM responses can be assessed through automated scoring, model-based evaluation and human review. Each approach offers a different balance of scalability, consistency and judgement.
Most mature evaluation frameworks mix several approaches, using cheap automated checks widely and expensive human review where it matters most.
Reference-Based Evaluation
Reference-based evaluation compares each generated answer with a predefined reference output. Metrics such as Exact Match, BLEU and ROUGE quantify how closely the two match.
This approach is fast, cheap and reproducible. It works best when reliable reference answers exist, such as in extraction, classification or short-answer tasks, and poorly when many different answers are valid.
LLM-as-a-Judge Evaluation
In LLM-as-a-judge evaluation, one language model scores the responses generated by another. The judge rates criteria such as relevance, clarity, correctness and instruction-following.
Clear scoring rubrics and calibration against human judgements are essential. The study on judging LLM-as-a-judge found position, verbosity and self-enhancement biases, and scores can vary between runs.
Human Evaluation
Human evaluation uses trained reviewers who score responses against predefined criteria. Expert reviewers are essential for technical, medical, legal and other high-stakes applications.
Humans catch nuances that automated metrics miss, such as subtle errors, tone and real usefulness. The trade-off is cost and time, which makes large-scale human review hard to repeat often.
Pairwise Evaluation
Pairwise evaluation shows two model responses to the same prompt. A human reviewer or evaluator model then selects the better one, and wins are aggregated across many prompts.
It is useful when assigning absolute scores is difficult, because comparing is easier than rating. Swapping the order of responses between runs helps reduce position bias.
The table below compares the four evaluation approaches. Use it to decide which mix suits your budget, scale and risk level.
| Evaluation approach | Main advantage | Main limitation |
|---|---|---|
| Reference-based | Scalable and reproducible | Requires suitable reference answers |
| LLM-as-a-judge | Scales qualitative assessment | Can inherit evaluator-model bias |
| Human evaluation | Captures contextual quality | Time-consuming and costly |
| Pairwise evaluation | Useful for relative comparisons | Does not always provide an absolute quality score |
Key point: A reliable evaluation strategy often combines automated metrics with human review, especially when outputs have real-world consequences.
How to Build an LLM Evaluation Pipeline?
An LLM evaluation pipeline is an automated workflow that tests model outputs against datasets and evaluation criteria. It runs the same checks every time, without manual effort.
Automation makes it easy to compare model versions, catch regressions early and add evaluation to your CI/CD process. Here is how to build one.
Step 1: Prepare the Evaluation Dataset
Store test prompts and expected answers in a structured format, such as JSONL or CSV. Tag each row with its task category, difficulty level and whether it is an edge case.
Keep a held-out test set that is never used to tune prompts or the model. If you optimise against it repeatedly, the scores stop predicting real-world performance.
Step 2: Generate Model Responses
Send each test prompt to the model through the same configuration. Fix the model version, system prompt, temperature and token limits for the whole run.
Log every response with its model version, generation parameters, latency and token usage. Add retries and timeouts, and flag failed requests or truncated responses instead of silently dropping them.
Step 3: Calculate Evaluation Metrics
Apply task-specific metrics, such as Exact Match, F1, BLEU or ROUGE, where reference answers exist. For open-ended responses, add semantic metrics like BERTScore or rubric-based LLM judges.
Then aggregate results across test examples. Report averages overall and per category, because a strong overall score can hide a failing category.
Step 4: Analyse Failures
Filter for answers that are incorrect, incomplete, irrelevant or unsupported by context. Read them, because raw failures reveal problems that averages hide.
Categorise each failure by task type and severity, so critical errors get fixed first. Compare the same examples across model versions to see exactly what improved or regressed.
Step 5: Generate an Evaluation Report
The report should present overall and category-level scores in one view. Track latency and token usage alongside quality metrics, because a better answer that costs twice as much may not be worth it.
Highlight performance regressions against the previous version and list areas requiring improvement. This gives the team a clear go or no-go signal.
How to Evaluate an LLM Using Python? (Code Example)
This tutorial compares generated answers with reference answers in Python, using ROUGE as the metric. It is small enough for beginners and runs in under a minute.
The same pattern, a dataset, a metric and a results check, scales into a production evaluation workflow once you swap in your own data and metrics.
Install the Required Libraries
The Hugging Face Evaluate library gives one consistent interface for loading and computing dozens of metrics. Libraries like this save you from implementing and debugging each metric yourself.
Install Evaluate together with rouge_score, the package that performs the actual ROUGE calculation:
pip install evaluate rouge_score The first time you load a metric, Evaluate fetches the metric module from the Hugging Face Hub, so an internet connection is required.
Create a Small Evaluation Dataset
Next, define the evaluation dataset as three aligned Python lists. Items at the same position form one evaluation case: the prompt, the model’s generated answer and the reference answer.
prompts = [
"What is the capital of France?",
"What is Python?"
]
predictions = [
"Paris is the capital of France.",
"Python is a programming language."
]
references = [
"The capital of France is Paris.",
"Python is a programming language."
] In a real pipeline, predictions would come from your model’s API responses. Both answers here are correct, but the first uses different word order from its reference.
Calculate ROUGE Scores
Now load the ROUGE metric and compare each prediction with its reference. The compute() method returns one aggregated score per ROUGE variant.
import evaluate
rouge = evaluate.load("rouge")
results = rouge.compute(
predictions=predictions,
references=references
)
print(results) When we ran this code (Evaluate 0.4.6, rouge_score 0.1.2, NumPy 2.5.3), it printed the output below. Older NumPy versions print plain floats instead of np.float64(…).
{'rouge1': np.float64(1.0), 'rouge2': np.float64(0.8), 'rougeL': np.float64(0.8333333333333333), 'rougeLsum': np.float64(0.8333333333333333)} Each value is an F-measure between 0 and 1, averaged across both examples. Here is what each variant measures at a high level:
- ROUGE-1: overlap of single words (unigrams).
- ROUGE-2: overlap of consecutive word pairs (bigrams).
- ROUGE-L: the longest common subsequence, which rewards words appearing in the same order.
- ROUGE-Lsum: ROUGE-L computed per sentence, split on newlines, for multi-sentence summaries.
Interpret the Evaluation Results
An averaged score hides which answers lost points and why. Interpreting results means checking individual examples and asking whether the metric reflects real answer quality for your task.
To see where points were lost, pass use_aggregator=False and get one score per example:
per_example = rouge.compute(
predictions=predictions,
references=references,
use_aggregator=False
)
print(per_example) {'rouge1': [1.0, 1.0], 'rouge2': [0.6, 1.0], 'rougeL': [0.6666666666666666, 1.0], 'rougeLsum': [0.6666666666666666, 1.0]} The Paris answer is correct, yet it scores only 0.6 on ROUGE-2 because its word order differs. ROUGE measures text overlap, not factual correctness. The next check makes that limitation concrete:
wrong = rouge.compute(
predictions=["Lyon is the capital of France."],
references=["The capital of France is Paris."]
)
print({name: round(float(score), 2) for name, score in wrong.items()}) {'rouge1': 0.83, 'rouge2': 0.6, 'rougeL': 0.67, 'rougeLsum': 0.67} The wrong answer earns the same ROUGE-2 and ROUGE-L scores as the correct one. Always interpret ROUGE in the context of the task, and never treat it as a standalone quality score.
For production systems, pair it with factuality checks, such as Exact Match on key entities, an LLM judge or human review. Then extend the script to read test cases from a file, store scores per model version and fail the build when scores drop.
How do you Evaluate RAG Applications?
RAG evaluation must assess two things: the quality of the retrieved information and the quality of the final generated answer. Each can fail independently of the other.
A model may write a fluent, confident response and still be wrong because retrieval supplied irrelevant or incomplete context. If you need a refresher on the architecture itself, see how retrieval-augmented generation works [Internal link placeholder: add RAG guide URL].
Context Precision
Context precision checks whether the retrieved passages are relevant to the user’s question. Ragas calculates it as the average precision@k, so relevant chunks ranked near the top score higher.
Low precision matters because irrelevant documents can distract the model. They also fill the context window and raise token costs without adding useful information.
Context Recall
Context recall checks whether the retrieval system captured all the information needed to answer the question. It usually requires a reference answer or reference contexts to compare against.
When relevant documents are missing, the model gives incomplete answers. Worse, it may fill the gap with plausible-sounding guesses that no source supports.
Faithfulness
Faithfulness checks whether the generated answer is supported by the retrieved context. The Ragas faithfulness metric scores it as the number of supported claims divided by the total claims in the answer.
Unsupported statements are a major concern in RAG applications, because users trust answers that appear source-backed. Note that faithfulness only measures consistency with the context; if the context is wrong, a faithful answer is wrong too.
Answer Relevance
Answer relevance checks whether the response actually addresses the user’s question. Ragas notes that this metric does not evaluate factual accuracy; it only measures alignment with the question’s intent.
A response can be fully supported by context yet still irrelevant or incomplete. For example, a user asks about a refund deadline, and the bot accurately quotes the shipping policy instead.
The table below summarises the four core RAG evaluation metrics. The first two measure retrieval quality, while the last two measure answer generation quality.
| Metric | What it evaluates |
|---|---|
| Context Precision | Relevance of retrieved information |
| Context Recall | Coverage of relevant source information |
| Faithfulness | Whether the answer is supported by context |
| Answer Relevance | Whether the answer addresses the query |
Key point: RAG evaluation should separately measure retrieval quality and answer generation quality.
What are the Best Tools and Frameworks for LLM Evaluation?
LLM evaluation frameworks help developers automate testing, compare models, track metrics and identify regressions. They save you from building metric code, judges and reports from scratch.
No tool is universally best. The four below are widely used, but each is designed around a different workflow, so match the tool to your application.
DeepEval
DeepEval is an open-source LLM evaluation framework that supports automated LLM evaluation through Pytest-style unit tests. You write test cases for model outputs much like ordinary Python tests.
Its built-in metrics include G-Eval, RAG, safety and agent metrics, each scored from 0 to 1 against a pass threshold. Because it runs with pytest, it fits naturally into CI/CD pipelines that block regressions.
Ragas
Ragas is a framework for evaluating RAG pipelines, introduced with metrics that do not require human-annotated ground truth. It focuses on how well retrieval and generation work together.
Its metrics cover retrieval quality, such as context precision and recall, and generation quality, such as faithfulness and response relevancy. This makes it well suited to testing retrieval-augmented applications component by component.
LangSmith
LangSmith supports tracing, evaluation and monitoring of LLM applications. Traces record each step of a run, including model and tool calls, which helps you debug failures.
For dataset-based evaluation, you run each application version on a dataset as an experiment, then compare experiments side by side. It supports code, human, LLM-as-a-judge and pairwise evaluators, both offline and on production traffic.
OpenAI Evals
OpenAI Evals is a framework for evaluating LLMs and systems built with them. It lets you test model behaviour against defined criteria and includes a registry of existing evals.
You can write custom evaluation tasks, including private evals on your own data and model-graded evals defined in YAML. Evals can also be configured and run in the OpenAI Dashboard for repeatable testing.
The table below compares these LLM testing tools at a glance. Use it as a starting point, then check each tool’s documentation against your stack.
| Tool | Primary use | Suitable for |
|---|---|---|
| DeepEval | Automated LLM testing | General LLM applications |
| Ragas | RAG evaluation | Retrieval-augmented applications |
| LangSmith | Tracing and evaluation | LLM application development |
| OpenAI Evals | Model and application evaluation | Custom evaluation workflows |
Key point: Select an evaluation framework based on the application’s architecture, metrics, integrations and testing requirements.
Common Mistakes to Avoid During LLM Evaluation
Evaluation results are only as trustworthy as the process behind them. Poorly designed test datasets, mismatched metrics and inconsistent evaluation conditions can all produce misleading scores.
The mistakes below are among the most common in LLM performance testing, and each one can make a weak model look production-ready.
Relying on a Single Evaluation Metric
One score cannot capture every dimension of LLM quality. A model can score well on ROUGE while being factually wrong, as the Python example showed, or be accurate but too slow for users.
Combine task-specific metrics, such as Exact Match or faithfulness, with qualitative assessment from rubric-based judges or human reviewers.
Using Benchmarks as the Only Performance Indicator
Benchmark scores may not reflect production performance. Public benchmark questions can appear in training data, and their tasks rarely match your users’ requests, formats or domain.
Build an application-specific evaluation dataset from real or realistic user queries. Use public benchmarks for shortlisting models, then make the final decision on your own data.
Ignoring Hallucinations and Safety
Fluency does not guarantee factual correctness. LLMs can state fabricated facts in confident, well-written prose, which makes errors harder for users to spot. Learn more about why LLMs hallucinate and how to reduce it.
Test explicitly for unsupported claims using faithfulness checks and fact verification. Add adversarial and policy-sensitive prompts to confirm the model responds safely.
Using Poor-Quality Evaluation Data
Duplicated, biased or unrepresentative test examples distort results. Duplicates over-weight some cases, while a dataset of only easy questions hides weaknesses.
Test datasets should reflect real user behaviour, including typos, vague requests and multi-part questions. Review and refresh them as usage patterns change.
Failing to Re-Evaluate After Changes
Prompt edits, model upgrades, retrieval changes and configuration tweaks can all affect performance, sometimes in unexpected areas. A fix for one task may break another.
Run regression tests on the same evaluation dataset before every production deployment. Compare results with the previous version and block releases that fall below agreed thresholds.
Conclusion
LLM evaluation is not a gate you pass once. Models, prompts, retrieval data and user behaviour all change, and each change can quietly shift quality, cost or safety.
Treat evaluation like software testing: a versioned dataset, metrics matched to each task and regression checks before every release. That discipline turns model choices into evidence-based decisions.
After deployment, the work continues. Monitor live quality, latency and token usage, route failures to human review and feed them back into your test set, so every release is measured against what users actually ask.
If you want hands-on practice building, testing and deploying GenAI applications, explore Certificate Programme in Generative AI , offered by IIT Delhi’s Continuing Education Programme in collaboration with InterviewBit by Scaler (Varsity).
Frequently Asked Questions
How do you create a custom evaluation dataset for an LLM application?
Start with real or realistic user queries from logs, support tickets or domain experts. For each one, record the input, an expected answer or grading rubric, and tags for task type and difficulty.
Add edge cases and adversarial prompts, remove duplicates and version the dataset. Begin with a small, carefully reviewed set, then grow it with failures found in production.
What is the difference between model-level evaluation and end-to-end LLM application testing?
Model-level evaluation tests the LLM on its own, often with benchmarks or fixed prompts. End-to-end testing evaluates the full application, including prompts, retrieval, tools, guardrails and post-processing.
A strong model can still fail inside a weak pipeline, so deployment decisions should rely on end-to-end results.
How can developers test LLM responses for consistency across repeated runs?
Run each prompt several times with identical settings, then compare the outputs using exact match, semantic similarity or judge-based agreement. Track the spread of scores, not only the average.
A lower temperature reduces randomness but may not remove it, so test at the temperature you use in production.
What is the G-Eval framework, and how is it used to assess LLM output quality?
G-Eval is an LLM-as-a-judge method that uses chain-of-thought evaluation steps and a form-filling format to score outputs on criteria such as coherence or relevance.
In its original paper, G-Eval with GPT-4 reached a 0.514 Spearman correlation with human judgements on summarisation. Frameworks like DeepEval offer it as a custom metric.
How do you evaluate whether an LLM follows complex user instructions correctly?
Break each instruction into checkable constraints, such as length, format, required keywords and sections. Verify objective constraints with code, as IFEval does with its verifiable instructions.
Use rubric-based judges or human reviewers for subjective constraints like tone. Scoring each constraint separately shows exactly which instructions the model ignores.
What is the difference between deterministic and probabilistic LLM evaluation?
Deterministic evaluation uses fixed rules that always return the same result for the same output, such as Exact Match, regex checks, JSON validation or unit tests.
Probabilistic evaluation relies on model judgements, such as LLM-as-a-judge scores, which can vary between runs or judge versions. Use deterministic checks wherever possible, and add model-based ones for qualities rules cannot capture.
How can developers detect performance regressions after changing an LLM or its prompt?
Keep a fixed, versioned evaluation dataset and store baseline scores from the current production version. After every change, rerun the same suite under the same settings.
Compare results per example and per category, flag drops beyond agreed tolerances, and review every case that moved from pass to fail.
What is the difference between offline evaluation and online a/B testing for LLM applications?
Offline evaluation runs a fixed dataset before deployment, so it is repeatable and can use reference answers. Online A/B testing splits live traffic between versions and measures real outcomes, such as task success or user ratings.
Offline tests catch regressions safely; online tests confirm real-world impact. Mature teams use both.
How do you measure the latency and token efficiency of an LLM in production?
Log time to first token, total response time, and input and output tokens for every request. Track percentiles such as p50 and p95, because slow outliers hurt user experience more than averages show.
For efficiency, divide tokens and cost by successfully completed tasks, and watch how prompt or retrieval changes shift both.
How can human feedback be incorporated into an automated LLM evaluation workflow?
Collect ratings, corrections or pairwise preferences from users and expert reviewers. Add reviewed failures to your evaluation dataset as new test cases, so the automated suite learns from them.
Human labels also calibrate LLM judges: measure how often the judge agrees with reviewers. Annotation queues can route low-scoring outputs to people for review.
What is the best way to evaluate LLM-generated code beyond text similarity scores?
Run the code. Execution-based evaluation checks whether generated code passes unit tests, which is how HumanEval reports pass@k.
Also check that it compiles, handles edge cases, passes linters and security scanners, and meets performance limits. Always execute untrusted generated code in an isolated sandbox.
How do you establish evaluation thresholds before deploying an LLM application to production?
Start from business risk. Define minimum acceptable scores for critical metrics, such as faithfulness or task success, plus latency and cost limits.
Base them on the current system’s or human reviewers’ performance on your dataset, with stricter thresholds for high-risk categories. Enforce them as release gates in CI, and revisit them as production data arrives.
Sources
- Evaluation metrics
BLEU: a Method for Automatic Evaluation of Machine Translation (Papineni et al., ACL 2002)
ROUGE: A Package for Automatic Evaluation of Summaries (Lin, 2004)
BERTScore: Evaluating Text Generation with BERT (Zhang et al.)
Perplexity of fixed-length models, Hugging Face Transformers documentation
- LLM benchmarks
Measuring Massive Multitask Language Understanding, the MMLU paper (Hendrycks et al.)
Training Verifiers to Solve Math Word Problems, the GSM8K paper (Cobbe et al.)
Evaluating Large Language Models Trained on Code, the HumanEval paper (Chen et al.)
SQuAD: 100,000+ Questions for Machine Comprehension of Text (Rajpurkar et al.)
TruthfulQA: Measuring How Models Mimic Human Falsehoods (Lin et al.)
Beyond the Imitation Game, the BIG-bench paper (Srivastava et al.)
- Model-based evaluation
Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (Zheng et al.)
G-Eval: NLG Evaluation using GPT-4 with Better Human Alignment (Liu et al.)
- RAG evaluation
Ragas documentation: list of available metrics
Ragas documentation: Context Precision
- Evaluation tools and libraries
Hugging Face Evaluate: a quick tour