Guide / AI engineering Fundamentals
Evaluation in practice: tooling, online evals and A/B testing
A concrete evaluation workflow: datasets, metrics, RAGAS-style RAG metrics, promptfoo-style CI evals, tracing tools, online evaluation, A/B tests and how to calibrate LLM judges.
Concepts are in Evaluation, guardrails and AI security. This page is the practical workflow interviewers ask for: “how would you actually set this up?”
Fundamentals#
E.1 The evaluation loop#
Define success → build dataset → pick metrics/judges → run offline evals in CI → ship behind a flag
→ online monitoring + A/B test → mine failures → add to dataset → repeat
Treat evals like unit tests plus monitoring: every prompt, model, retrieval or tool change must pass an eval gate.
E.2 Building the dataset#
- Start with 50–200 real examples from production logs or domain experts; add edge cases, adversarial inputs, refusals, multilingual and long-context cases.
- Label what “good” means: reference answers, rubrics (criteria with scores), required citations, or programmatic checks.
- Split: development set (iterate on it) and a held-out test set (touch rarely) to avoid overfitting prompts to the eval.
- Version datasets; add every production failure as a new case (regression suite); tag cases by feature and difficulty.
- Beware of leakage (eval examples appearing in few-shot prompts or fine-tuning data) and stale answers (re-verify references).
E.3 Metrics by task#
| Task | Metrics |
|---|---|
| Classification / extraction | Accuracy, precision/recall/F1, exact match, schema validity |
| Generation | Rubric score from a judge, human preference, factuality, length, style adherence |
| RAG retrieval | Recall@k, precision@k, MRR, nDCG, context recall |
| RAG answer | Faithfulness / groundedness (claims supported by context), answer relevance, context precision, citation correctness |
| Agents | Task success rate, steps to success, tool-call accuracy, invalid action rate, cost and latency per task, recovery from errors |
| Safety | Refusal correctness, jailbreak success rate, PII leakage rate, toxicity |
| Ops | p50/p95 latency, TTFT, cost per request, error rate |
Prefer programmatic checks (JSON valid, SQL runs and returns the expected rows, unit tests pass, regex) wherever possible; they are cheap and objective. Use LLM judges for the rest, and humans to calibrate.
E.4 Tools and where they fit#
| Tool type | Examples | Use |
|---|---|---|
| RAG metric libraries | RAGAS, TruLens, DeepEval | Faithfulness, answer relevance, context metrics using LLM judges |
| Prompt/test harnesses (CI) | promptfoo, OpenAI Evals-style, custom pytest | Run a matrix of prompts × models × test cases with assertions and thresholds in CI |
| Tracing and eval platforms | LangSmith, Langfuse, Arize Phoenix, Braintrust, W&B Weave | Trace every call, store datasets, run evals, compare experiments, annotate with humans |
| Red-teaming | Garak, PyRIT, custom attack suites | Probe jailbreaks and injection |
| Benchmarks | MMLU, HumanEval/SWE-bench, MTEB, domain sets | Model selection only; never a substitute for your own eval |
Example CI gate (conceptually): run 300 cases, fail the build if task accuracy drops > 2 points, schema validity < 99%, p95 cost per request rises > 20%, or any safety case regresses.
E.5 LLM-as-judge done well#
Write a clear rubric with scoring anchors; ask for reasoning then a score (or use pairwise comparison, which is more reliable than absolute scores); randomise order to counter position bias; control verbosity and self-preference bias (use a different model family as judge); use temperature 0; calibrate against human labels (measure agreement, e.g. Cohen’s κ, on 100+ items) and re-calibrate when the judge model changes; keep a human-reviewed sample in every release.
E.6 Online evaluation and monitoring#
- Implicit signals: thumbs, copy, regenerate, edits, abandonment, escalation to human, follow-up questions, task completion.
- Sampling + judges: score a sample (1–5%) of production traces automatically (faithfulness, toxicity, PII); alert on drops.
- Drift detection: input topic distribution, retrieval scores, refusal rates, length, latency and cost over time; model provider changes silently shift behaviour, so pin versions and re-run evals on schedule.
- Human review queues for low-confidence or flagged cases, feeding the dataset.
E.7 A/B testing LLM features#
Randomise by user (consistent assignment), pick a primary metric (task success, resolution rate, conversion) and guardrail metrics (latency, cost, safety incidents, escalations). Compute sample size from the minimum detectable effect, because LLM outputs are noisy and effects are small; run long enough to cover weekly cycles; analyse with confidence intervals; use interleaving or paired comparisons for ranking changes; start with shadow mode and a small canary. Do not conclude from offline eval alone: users may prefer different qualities than your rubric.
E.8 Common mistakes#
Evaluating on the training/prompt examples; a single aggregate score hiding a broken segment (slice by intent, language, customer); judges without calibration; changing the dataset and the system at the same time; ignoring cost and latency in “quality” comparisons; no regression tests for fixed bugs; treating public benchmarks as proof.
Most asked questions#
1. How do you evaluate a RAG system? Separate retrieval (recall@k, MRR) from generation (faithfulness, answer relevance, citation accuracy) using a labelled question set; run in CI; monitor online.
2. How do you evaluate an LLM-as-judge? Compare to human labels on a sample, check agreement and biases, use rubrics and pairwise comparison, and recalibrate on changes.
3. How do you prevent regressions when changing prompts? Version prompts, run the regression suite with thresholds in CI, canary rollout, monitor online metrics.
4. Offline vs online evaluation? Offline is fast, repeatable and safe, but limited by dataset realism; online measures real user value but is slower and riskier; use both.
5. How do you evaluate an agent? End-to-end task success on scenario suites in a sandboxed environment, trace-level metrics (tool accuracy, steps, recovery), cost/latency, and safety tests.
Senior-level questions#
1. “Offline scores improved 8% but the A/B test shows no lift.” Eval set not representative, rubric misaligned with user value, novelty effects, ceiling effect, or the change affects a small traffic slice; slice the analysis, inspect disagreements, and refresh the dataset from production.
2. “Your judge model was upgraded and all scores jumped.” Judge drift; keep judge version pinned, recalibrate with humans, compare old and new judge on the same fixed set before switching, and track scores by judge version.
3. “How many eval examples do you need?” Enough for confidence intervals narrower than the effects you care about: with accuracy ~80%, 400 examples give roughly ±4 points at 95% confidence; use more for subtle differences, paired comparisons to reduce noise, and stratified samples for rare cases.
4. “How do you evaluate without ground truth?” Programmatic checks, consistency checks (multiple samples), pairwise preference by judge or humans, groundedness against provided context, and downstream task metrics.
5. “Design the quality gate for a regulated domain (health, finance).” Expert-labelled sets, zero-tolerance safety cases, mandatory citation/grounding checks, human-in-the-loop for high-risk outputs, full audit logs, versioned approvals and periodic re-validation.
Quiz#
1. Two biases of LLM judges?
Position bias (favouring the first or last answer), verbosity bias (preferring longer answers), and self-preference (favouring outputs from the same model family).
2. What is faithfulness in RAG?
The fraction of claims in the answer that are supported by the retrieved context.
3. Why keep a held-out test set?
To avoid overfitting prompts and configurations to the development set, keeping an unbiased estimate.
4. Which is cheaper and more objective: programmatic checks or LLM judges?
Programmatic checks (schema validation, unit tests, exact match).
5. What guardrail metrics accompany an A/B test of a new prompt?
Latency, cost per request, safety incidents, escalation rate and error rate.