LLM Evaluation & Quality Metrics

Chapter opener illustration: LLM Evaluation & Quality Metrics.

"Without data, you're just another person with an opinion. Without evaluation, you're just another model with a prediction."

EvalEval, Chronically-Skeptical AI Agent
Looking Back

You have built something (Parts III-VIII). How do you know if it works? This chapter is the eval chapter: classical metrics, LLM-as-judge, eval-driven quality gates, observability, OpenTelemetry, long-context benchmarks, and the experimental rigor that separates "ships features" from "ships working features." Eval is the most under-invested part of every team's LLM stack; this chapter is the corrective.

Chapter Overview

Building LLM applications is only half the challenge; knowing whether they actually work is the other half. Unlike traditional software where correctness is binary, LLM outputs are probabilistic, subjective, and context-dependent. A model that performs brilliantly on one prompt may fail catastrophically on a slight rephrasing. This fundamental uncertainty makes rigorous evaluation, principled experiment design, and continuous observability essential for every LLM project.

This chapter covers the complete evaluation and monitoring lifecycle. It begins with core evaluation metrics (perplexity, BLEU, ROUGE, BERTScore, LLM-as-Judge) and standard benchmarks (MMLU, HumanEval, MT-Bench, Chatbot Arena). It then addresses experimental design with statistical rigor, including bootstrap confidence intervals, paired tests, and ablation studies. Specialized evaluation for RAG and agent systems follows, covering RAGAS metrics, trajectory evaluation, and frameworks like DeepEval and Phoenix.

The chapter also covers testing strategies for LLM applications (unit tests, red teaming, prompt injection testing, CI/CD integration), evaluation-driven quality gates, and arena-style evaluation with Elo ratings. Advanced topics include LLM-as-Judge reliability and debiasing, long-context benchmarks (Needle-in-a-Haystack, RULER, LongBench), human feedback tooling, research methodology for LLM papers, and inference performance benchmarking across hardware platforms. Observability, monitoring, and reproducibility practices are covered in the companion sections later in this chapter.

Big Picture

You cannot improve what you cannot measure. This chapter covers LLM evaluation methods including automated metrics, human evaluation, and LLM-as-judge approaches. The evaluation frameworks here apply to every system built in this book, from simple API calls to complex multi-agent pipelines.

Note: Learning Objectives

Prerequisites

Sections

Lab 42: Build an Eval Harness With Inspect AI Plus Three Custom Metrics

Objective

Stand up a reusable evaluation harness using inspect-ai (the AISI framework) that scores an LLM on a custom dataset with both standard and custom metrics. By the end you will have a CI-runnable eval suite, plus a clear feel for the difference between leaderboard metrics and what you actually need to track.

Steps

  1. Step 1: Define the task. Pick something narrow: "summarize a news article in 3 sentences" or "answer a coding interview question." Curate 50 high-quality examples in tasks.jsonl.
  2. Step 2: Install Inspect. pip install inspect-ai. Write a task in the @task decorator pattern: solver = generate(), scorer = model_graded_qa().
  3. Step 3: Run baseline. inspect eval my_task.py --model openai/gpt-4o-mini. View the report in the Inspect UI. Note overall accuracy.
  4. Step 4: Add a custom metric. Define a custom scorer that combines: (a) F1 of key entities present, (b) ROUGE-L, (c) length penalty for >120 words. Register it with @scorer.
  5. Step 5: Multi-model sweep. Re-run against 3 models (gpt-4o-mini, claude-haiku-4.6, llama-3.3-70b via Together). Generate a comparison table with all metrics.
  6. Step 6: Wire into CI. Add a GitHub Action that runs inspect eval on every PR, fails if the score drops >5 points. This is the regression-evals pattern Chapter 44 builds on.

Expected Output

Expected time: 3 hours. Difficulty: intermediate. Artifact: a Git-versioned eval suite + CI integration.

What's Next?

Next: Chapter 43: Specialized Evaluation, RAG, Agents, Multimodal, Long-Context. The metrics in Chapter 42 (BLEU, ROUGE, accuracy, perplexity) were designed for the pre-LLM world and quietly miss what matters in 2026. Chapter 43 covers the new evaluation surface: RAG faithfulness and groundedness, agentic trajectory eval, code-gen pass@k, multimodal grounding, and the long-context benchmarks (Needle-in-a-Haystack, RULER) that expose the gap between context-window-marketing and context-window-reality.