Vol. 33 · Evaluation & Improvement
Core Metrics for LLM Pipelines
One volume about the most useful metrics for LLM systems: from average, variance and standard deviation to accuracy, precision, recall, F1, MRR, MAP, nDCG@k, calibration, pass@k, latency and cost per success. Each card answers four questions: what it measures, how to calculate it, how to read, and where to apply it in the pipeline.
Basic statistics
The average answers the question “how much on average.” This is the most common aggregating metric for judge score, latency, cost, reward and batch quality. A weighted average is needed when observations are unequal: for example, requests differ in the number of tokens or importance.
Source-complete notesformula · Where it helps
texmean = Σx_i / n
weighted mean = Σ(w_i * x_i) / Σw_i
If all observations are equally important -> the usual average.
If the weight is different, use weights.Where it helps
- average judge score
- cost / request
- middle-tail
- Don't just look at the mean latency.
The median shows a "typical" value that doesn't break down from rare emissions. Percentile p95 means 95% of observations are as good as this. For latency and token count, they are usually more important than average.
Source-complete notesformula · Where it helps
texp50 = median
p95 = value below which lies 95% of observations
p99 = value below which lies 99% of observations
Question to the metric:
"how bad is the system's tail?"Where it helps
- p95 latency
- tail token count
- median does not show worst-case
- p99 for SLO
The variance and standard deviation show a spread around the mean. They are needed when it is important not only what the average score is, but also how stable it is from example, for example, from launch to launch and from annotator to annotator.
Source-complete notesformula · Where it helps
texvariance = Σ(x_i - mean)^2 / n
std = sqrt(variance)
The more std, the less predictable the outcome.
The std is measured in the same units as the reference metric.Where it helps
- run-to-run variance
- judge consistency
- std without a mean of little information
- compare
A lot of product and eval metrics are actually just fractions: how many queries worked, how many JSONs were valid, how many answers were grounded, how many times the system failed. This is the most universal type of metric.
Source-complete notesformula · Where it helps
texrate = successes / total
error rate = errors / total = 1 - success rate
The main rule:
Always indicate the denominator.
"87 errors" without "how many" is almost useless.Where it helps
- task success rate
- schema-valid rate
- hallucination rate
- You need a size sample.
One number without uncertainty often overestimates confidence. The confidence interval shows the range of plausible values. Delta shows an absolute difference, lift shows relative growth relative to baseline.
Source-complete notesformula · Where it helps
texFor fraction p:
95% CI ~= p +/- 1.96 * sqrt(p(1-p)/n)
delta = metric_B - metric_A
lift = (metric_B - metric_A) / metric_AWhere it helps
- A/B comparison
- report uncertainty
- delta in pp!= lift in %
- Do not publish a point estimate
Classification and filters
Almost all binary metrics are derived from four numbers. If you do not fix what is a positive class, then it is easy to confuse the meaning of precision, recall and false positive rate. For safety and routing, this is the basic table from which everything starts.
Adjust the decision threshold and watch the four cells and derived metrics recompute.
- Precision
- Recall
- F1
Source-complete notesread · Where it helps
textTP: Model says 'positive' and it's true
FP: Model says 'positive' but it's false alarm
TN: Model says "negative" and it's true
FN: Model said "negative" but missed positive
Accuracy/precision/remember/F1
It's just a different relationship between these four numbers.Where it helps
- toxicity filter
- intent classifier
- spam / abuse detector
- You have to ask positive class.
Accuracy shows a proportion of correct predictions. It is convenient when the classes are more or less balanced. With a strong imbalance, accuracy often looks more beautiful than the model is actually useful.
Source-complete notesformula · when to use
texaccuracy = (TP + TN) / (TP + FP + TN + FN)
error rate = 1 - accuracywhen to use
- balanced-class
- class imbalance makes sense
- Do not use it alone for safety
Precision answers the question, “If a model flagged something, how often is she right?” Recall answers the question, “What proportion of really important cases did the model find?” This is almost always the main pair of metrics for filters, detectors, and routers.
Source-complete notesformula · choose
texprecision = TP / (TP + FP)
recall = TP / (TP + FN)
Precision -> Price of false alarm
recall -> skip pricechoose
- High recall for safety
- High precision for routing
- You can't improve one for free.
- threshold
These metrics are useful when it is separately important to control false locks and dangerous omissions. For safety-review, it is often more convenient to talk about the false negative rate, and for antifraud and moderation, false positive rate is sometimes more important.
Source-complete notesformula · Where it helps
texspecificity = TN / (TN + FP)
FPR = FP / (FP + TN) = 1 - specificity
FNR = FN / (FN + TP) = 1 - recallWhere it helps
- guardrails
- moderation
- abuse detection
- It is important to fix the threshold
F1 is needed when both precision and recall are important at the same time, and you want one final digit. This is a harmonic average: a metric will not allow one side to mask the failure of the other. F-beta allows you to appreciate recall or precision.
Source-complete notesformula · when to use
texF1 = 2PR / (P + R)
F_beta = (1 + beta^2)PR / (beta^2 P + R)
Beta > 1 - More weight recall
Beta < 1 - More precision weightwhen to use
- single headline metric
- model selection
- F1 hides which compromise is chosen
- F2 for safety/triage
Once there are more than two classes or the data is unbalanced, the method of averaging is important. Macro gives all classes the same voice. Weighted gives more weight to frequent classes. Micro counts errors globally. Balanced accuracy and MCC are useful when looking more honestly at imbalanced data.
Source-complete notesformula · selection rule
texmacro = mean(metric c by class)
weighted = Σ(support_c * metric_c) / Σsupport_c
micro = count TP/FP/FN globally, then metric
balanced accuracy = (recall + specificity) / 2
MCC = (TP*TN - FP*FN) / sqrt((TP+FP)(TP+FN)(TN+FP)(TN+FN))selection rule
- macro for fairness by class
- micro
- MCC for imbalance
- Weighted hides minority fail
Retrieval and Ranking
Hit@k answers a simple question: is there at least one useful document in the top-k? For the first retrieval stage, this metric is especially convenient when the generator needs one good support, rather than a complete set of all relevant documents.
Source-complete notesformula · when to use
texHit@k for one request:
1 if there is at least one relevant item in the top-k
0 if not
Hit@k = Average of Requestswhen to use
- first-stage retrieval
- RAG candidate search
- Do not see the quality of order inside the top k
- handy as a ceiling for a generator
Precision@k shows how clean top-k is. Recall@k shows how much of all relevant documents retriever managed to bring. This is a basic pair of metrics for search and candidate generation.
Source-complete notesformula · Where it helps
texP@k = relevant_in_top_k / k
R@k = relevant_in_top_k / total_relevant
P@k -> issue noise
R@k -> Relevance coverageWhere it helps
- search quality
- RAG chunk retrieval
- We need relevance markups.
- look up
The MRR measures how early the first benefit appears. If a user or generator needs one good document, MRR is usually more informative than recalling all relevant items.
Source-complete notesformula · when to use
texRR = 1 / rank_first_relevant
if the relevant item is not found -> RR = 0
MRR = mean(RR for all requests)when to use
- FAQ search
- single-best-doc retrieval
- Ignore second and third useful documents
- Good for QA and support search
Average Precision evaluates the entire ranking at once: the metric increases when relevant documents are higher and appear earlier. MAP averages AP for all queries. This is a convenient metric when not one document is important, but the whole set of relevant elements.
Source-complete notesformula · Where it helps
sqlAP = average Precision@r
at all levels of r, where the relevant document
MAP = mean(AP on request)Where it helps
- document retrieval
- reranker evaluation
- More difficult to explain to a business than Hit@k
- MRR is better when all relevant docs are important
nDCG@k is needed when documents are not just relevant / not relevant, but have levels of utility: for example, 3 = perfect proof, 2 = useful, 1 = partially. The metric rewards important documents at the top and normalizes the result of a relatively perfect sort.
Source-complete notesformula · Where it helps
texDCG@k = Σ(rel_i / log2(i + 1))
nDCG@k = DCG@k / IDCG@k
IDCG = best possible DCG for this query
nDCG is always in the range [0, 1]Where it helps
- reranking
- graded search relevance
- human-labeled passage quality
- It is not binary but graded markup.
Generation, Judge and Reliability
If the problem has an exact correct answer or a strict format, the exact metrics work best. For extraction, tool calling, JSON output and structured QA exact match is often more useful than any soft judge score.
Source-complete notesformula · Where it helps
texExact Match = exact_matches / total
Schema Accuracy = valid_schema_outputs / total
Either it matched or it didn't.Where it helps
- tool calling
- information extraction
- structured QA
- A very strict metric for open-ended chat
Overlap metrics compare model output to reference text for shared tokens, n-grams, or longest common subsequence. They are useful when there are not too many acceptable formulations, but often miss real utility and actual correctness.
Source-complete notesformula · when to use
texROUGE-1 recall = overlap_unigrams / reference_unigrams
BLEU ~= precision in n-grams *brevity penalty
Rouge is more likely to watch "what's covered,"
BLEU is more likely to look at “how similar the text is to the reference.”when to use
- summarization baseline
- translation baseline
- Does not measure factuality directly
- bad for creative chat
Pass@k answers the question: if we allow models to make multiple attempts, what is the probability that at least one of them will be correct. This is the main metric for code generation, unit-test solving and multi-sample decoding.
Source-complete notesformula · Where it helps
texIf n candidates are sampled,
And among them are the correct ones:
pass@k = 1 - C(n-c, k) / C(n, k)
Intuitive:
the probability that among k attempts
It'll be at least one good one.Where it helps
- code generation
- self-consistency decoding
- Increased cost and latency
- It is important to record the sampling policy
When it is difficult to make an absolute estimate, it is easier to ask which of the two answers is better. Pairwise win rate is convenient for comparison of models, prompts and postprocessors. It can be considered human-raters or LLM-as-judge.
Source-complete notesformula · when to use
texwin rate = (wins + 0.5 * ties) / total_comparisons
If the tie is excluded:
win rate = wins / (wins + losses)when to use
- chat quality comparison
- prompt bake-off
- Position bias control
- stronger for ranking than for calibration
Calibration checks whether the stated confidence of the model matches the actual success rate. This is critical for auto-approve, human handoff, self-check and policy-threshold solutions. The model may be accurate but poorly calibrated.
Source-complete notesformula · Where it helps
sqlBrier = mean((p_i - y_i)^2)
where y i = 1 for success and 0 for error
ECE = Average gap between confidence and accuracy
confidence-basketsWhere it helps
- auto-approve thresholds
- confidence-based routing
- ECE Depends on Bucketization
- Do not confuse high confidence with good calibration.
In many LLM systems, the model does not always have to respond. It can refuse, request a person or respond only with high confidence. In this case, accuracy is not enough: you need to watch coverage separately. For RAG, faithfulness almost always lives next to this, that is, the fraction of statements that are actually supported by the context.
Source-complete notesformula · Where it helps
texcoverage = answered / total
abstain rate = abstained / total = 1 - coverage
selective risk = wrong_answered / answered
faithfulness = supported_claims / total_claimsWhere it helps
- abstention policies
- human handoff
- RAG grounding
- You cannot compare accuracy without coverage.
Ops, Product and Pipeline Card
For an LLM product, it is important to distinguish between “when the user saw the first token” and “when the answer ended.” That’s why we usually watch TTFT, end-to-end latency and generation rate. SLOs almost always need p95 or p99, not just the average.
Source-complete notesformula · Where it helps
texTTFT = time_to_first_token
E2E latency = time_to_last_token
tokens/sec = generated_tokens / decode_time
For operational control:
mean + p95 + p99 + tok/sWhere it helps
- serving SLO
- model / infra comparison
- Mean latency is not enough
- Separate prompt and decode time
A good system should not only be qualitative, but also economically sustainable. The average cost per request is useful for budget planning, and the cost of a successful outcome often better reflects the actual effectiveness of the solution.
Source-complete notesformula · Where it helps
texcost/request = total_cost / requests
cost/success = total_cost / successful_requests
If the success rate falls,
Cost per success increases even at the same API price.Where it helps
- model selection
- multi-step pipeline economics
- watch with quality
- Cheaper is not always better than end-to-end.
After offline eval, it is important to see how the system lives in production. Usually, you need a simple funnel: how many tasks are solved automatically, how many went into a fallback or to a person, how many ended in failure. For A/B comparison, delta and lift are added to this.
Source-complete notesformula · Where it helps
texsuccess rate = solved / total
fallback rate = fallback / total
escalation rate = escalated / total
delta = metric_B - metric_A
lift = (metric_B - metric_A) / metric_AWhere it helps
- assistant funnel
- agent handoff monitoring
- online A/B
- You need guardrails near success
The main rule of thumb is that each pipeline step should have its own local metric, and the entire system should have a separate end-to-end success. Don’t expect a single “magical” number to replace the entire diagnosis. A good eval stack is always multi-layered.
Source-complete notesMinimal logic · table · finalist
sqlstep metric -> tells you exactly where the pipeline breaks
end-to-end metric -> says whether the system solves the user's problem
Guardrail metric -> says if you paid for the improvement with hidden risk
Practice:
1. keep local metrics in step
2. keep the overall task success metric
3. keep latency/cost/safety guardrails| Step. | Main metric | What to keep close to | What it does failure mean? |
|---|---|---|---|
| Classifier / Router | Recall, Precision, F1 | macro F1, confusion matrix | The system is going the wrong workflow |
| Safety / Guardrail | Recall, FNR | FPR, escalation rate | Dangerous cases pass or everything is blocked |
| Retriever | Hit@k, Recall@k | P@k, coverage | generator has nothing to rely on |
| Reranker | MRR, MAP, nDCG@k | latency, candidate recall | useful documents, but are too low |
| Extractor / Tool Call | Exact Match, schema accuracy | field-level recall, valid JSON rate | Pipeline breaks down on structural step |
| Generator | task success, win rate, pass@k | faithfulness, judge score | The answer is formally beautiful but useless. |
| Confidence / Abstain | Brier, ECE, coverage | selective risk | The model is overconfident or too silent |
| Serving / Product | p95 latency, cost/success | TTFT, funnel success, lift | Quality does not scale in the product |
finalist
- Local metrics for each step
- One common task success metric
- mandatory guardrails
- Don't argue about the quality of one number
No dead end
Keep moving through the map.
Continue in sequence, switch to a related guide, or return to the seven-track learning map.