Sub topic 3
Handling Uncertainty in LLM Application Evaluation
Assume basic Python, experience calling an LLM API, and familiarity with means and proportions. LLM outputs can change between runs because of sampling, model updates, tool results, and changing prompts. A single score can therefore mislead you.
Handling Nondeterminism and Reporting Uncertainty
Run each important case more than once, or evaluate a fixed dataset with a recorded model version and seed when the API supports one. Report the mean score and an uncertainty interval, not only the mean.
A bootstrap confidence interval repeatedly resamples the per-case scores. It estimates how much the measured mean might vary across similar samples.
import random
def bootstrap_ci(scores, n_resamples=1000, seed=0):
rng = random.Random(seed)
n = len(scores)
means = [
sum(rng.choices(scores, k=n)) / n
for _ in range(n_resamples)
]
means.sort()
return means[25], means[975] # approximate 95% interval
print(bootstrap_ci([1, 0, 1, 1, 0, 1, 1, 1, 0, 1]))Compare versions on the same cases. A small score difference is less convincing when the intervals overlap widely.
Evaluating Retrieval and Grounded Answers
For a retrieval-augmented generation (RAG) system, separate retrieval quality from answer quality:
- Recall at k asks whether known relevant documents appear in the top
kresults. - Precision at k asks how many of those results are relevant.
- Faithfulness asks whether each answer claim is supported by the retrieved context.
A correct answer with missing evidence may indicate a retrieval failure. Relevant documents with an unsupported answer may indicate a generation or grounding failure.
Error Analysis and Regression Testing
Group failures by cause: retrieval miss, incorrect answer, unsupported claim, formatting error, timeout, or unsafe response. Review examples from each group and add representative failures to the evaluation set.
Run a small deterministic subset in continuous integration (CI), the automated process that checks changes before merging. Fail the build when a critical metric drops below its threshold. Keep broader, slower judge and human evaluations outside the blocking CI path.
Multi-Step, Safety, and Online Evaluation
For agents, score the final result and the trace: tool choice, arguments, ordering, retries, and stopping behavior. Test invalid tool results and partial failures.
Safety evaluations should include prompt injection, sensitive-data requests, harmful instructions, and adversarial wording. Check both refusal behavior and whether the system avoids leaking retrieved or tool data.
In production, monitor success rates, latency, cost, user corrections, reports, and sampled human reviews. Compare cohorts and alert on changes rather than treating every individual failure as a regression.
Exercise
An updated RAG system improves answer accuracy from 0.82 to 0.84 but has a wide, overlapping confidence interval. What should you do?
Show answer
Avoid declaring an improvement. Run more representative cases, inspect paired failures, and check retrieval and faithfulness scores separately.