LLM Evaluation Metrics

Standard software testing relies on deterministic assertions. LLM testing relies on statistical distributions. Choosing the wrong metric leads to "benchmark chasing" where a model improves on paper but regresses in the hands of users.

The Hierarchy of Metrics

Metric TypeExampleUse CaseLimitations
DeterministicExact Match, JSON Schema ValidityCode Gen, Extraction, Structured I/OToo rigid for creative tasks.
N-Gram OverlapROUGE-L, BLEUSummarization, TranslationPenalizes synonyms; blind to factual correctness.
Model-BasedBERTScore, G-EvalSemantic alignment, nuanceHigh cost; potential "Judge Bias".
Human-in-the-LoopLikert Scale, Pairwise PrefFinal product validationExtremely slow and expensive.

Code-Specific Metrics

For engineering tasks, n-gram overlap is useless. We use Pass@k. A model generates n samples for a coding problem. If c samples pass the unit tests, the probability that at least one of k samples passes is:

\text{Pass@k} = 1 - \frac{\binom{n-c}{k}}{\binom{n}{k}}

Practitioner Note: In production, always report Pass@1. Pass@10 and Pass@100 are often used to inflate results in academic papers.

RAG-Specific Evaluation (RAGAS)

Evaluating a Retrieval-Augmented Generation system requires breaking the problem into two parts: retrieval quality and generation quality.

  1. Faithfulness: Does the answer derive only from the retrieved context? (Prevents hallucination).
  2. Answer Relevance: Does the answer actually address the user's prompt?
  3. Context Precision: Is the retrieved context actually useful for answering the question?

The LLM-as-Judge Pattern

Using a model like GPT-4o to grade a smaller model (e.g., Llama 3) is now the industry standard for subjective tasks.

# Reference rubric for a Judge LLM
JUDGE_PROMPT = """
Evaluate the assistant's response based on Accuracy and Conciseness.
Score 1-5. 
A score of 5 means the answer contains zero hallucinations and no fluff.
Context: {retrieved_context}
Question: {user_query}
Response: {assistant_response}
"""

CRITICAL: Judge Calibration. You must manually grade 100 samples alongside the Judge LLM. If your agreement rate is below 80%, your rubric is too vague.

Public Benchmarks to Watch (2026)

Further Reading