Evaluation & Observability · 90 minutes
Separate retrieval, packing, and generation failures
Use a request trace to tell retrieval, context-packing, and generation failures apart, and report answer quality with a named denominator next to operational signals.
1.5 h
Overview
Learn how to decide whether an AI feature works and how to investigate a failed request. You will separate retrieval quality from answer quality, report rates with named denominators, and read a trace to find where evidence disappeared.
Study time: 90 minutes
Interview format: Conceptual screen with a short trace-reading exercise
By the end you can
- Define an evaluation case with observable success conditions
- Distinguish retrieval quality from answer quality
- Choose between deterministic checks, model graders, and human review
- Calculate simple success rates with clear denominators
- Explain metrics, logs, and traces, and read a trace to locate lost evidence
This topic measures quality and investigates failures. Production & Reliability covers running the application.
Evaluation begins with an observable task
An evaluation gives a system an input, observes its behavior or outcome, and applies a defined scoring rule. “The answer sounds good” is difficult to reproduce. “The answer states the current return window, includes the exception, and cites the supporting policy” can be checked.
Define success before inspecting candidate outputs. Otherwise, a team can unconsciously change the rubric to favor a result it already likes. Include behavior for ambiguous requests, missing information, and unsuccessful execution.
For an agent that closes a ticket, the final database state matters. A fluent message claiming that the ticket was closed does not establish task completion.
Components of an evaluation
| Component | Meaning | Example |
|---|---|---|
| Case | One task with input and scoring information | Ask about custom-product returns |
| Dataset | A collection of cases | Ordinary, exceptional, and unanswerable questions |
| Trial | One execution of a case | Run the current configuration once |
| Grader | Logic or judgment used to assess a result | Check required facts and unsupported claims |
| Outcome | The actual result or environment state | Supported answer, correct abstention, or failure |
| Harness | Code that runs and records trials | Submit fixtures and aggregate scores |
A case can be run multiple times because model output may vary. Keep the case count and trial count distinct. Ten executions of the same question provide different evidence from ten different questions.
Retrieval quality and answer quality
Retrieval quality concerns whether useful, eligible evidence is found and ranked appropriately. Answer quality concerns whether the response correctly uses available evidence and satisfies the user's task.
An assistant can retrieve the correct exception clause and still ignore it. It can also fail to retrieve the clause and then produce an unsupported generalization. These failures may look identical in the final answer but require different corrections.
Inspect the actual context sent to the model, not only the top retrieval results. Context packing can remove a relevant passage after retrieval succeeds.
Useful quality dimensions
| Dimension | Question to ask |
|---|---|
| Correctness | Does the answer satisfy the task's factual or functional requirements? |
| Groundedness | Are claims supported by the supplied evidence? |
| Completeness | Are all required parts addressed? |
| Citation support | Does each cited passage support the associated claim? |
| Format validity | Does the output meet its structural contract? |
| Appropriate abstention | Does the system decline or clarify when evidence is insufficient? |
| Task completion | Did the intended operation actually succeed? |
These dimensions can disagree. An answer may be grounded in an outdated document and therefore wrong for a current-policy question. A valid JSON response can contain fabricated values. A complete answer may be too slow for the product's requirement.
Automated and human grading
Use deterministic checks when expected behavior is precise, such as JSON schema validity, a permitted category, or a database state. Use human review when meaning, ambiguity, or domain judgment matters.
A model-based grader can help assess large sets of free-text answers, but it can make mistakes and favor style over substance. Give it an explicit rubric and compare its judgments with reviewed examples. Treat grader errors as part of the measurement system.
Exact text matching is appropriate only when one exact representation is required. Two different sentences may express the same correct answer. Conversely, a sentence can contain an expected keyword while reversing its meaning.
Positive, negative, and boundary cases
A positive case exercises a task the system should complete. A negative case exercises behavior such as refusing an unauthorized action or acknowledging that evidence is missing. Define these terms for each dataset because “negative” can also mean an incorrect candidate response.
Boundary cases probe distinctions that commonly fail. In a policy assistant, a standard product and a custom product may have different rules. Include both so a system cannot pass by applying the common rule to everything.
Synthetic cases make edge conditions explicit. Representative real-world cases reveal the actual language and task mix. Use permitted, minimized data and retain the source of each case so evaluation limitations are visible.
Worked quality example: assess four outcomes
Predict the outcome
Assess four outcomes
The fictional policy allows standard-product returns within 30 days and excludes custom-printed products from that standard window. For each observed behavior, decide how you would assess it before you reveal the answers.
| Case | Observed behavior | Assessment |
|---|---|---|
| Standard product question | Correct 30-day answer with supporting source | ? |
| Custom product question | The exception passage was in the context sent to the model, but the answer says 30 days | ? |
| Shipping fee question | No fee evidence, answer invents $10 | ? |
| Shipping fee question | States that the supplied policy does not specify the fee | ? |
Calculate rates carefully
Suppose ten attempted cases produce eight successful outcomes, one incorrect answer, and one timeout. Overall task success is 8/10, or 80%. Excluding the timeout would report 8/9 and hide a user-visible failure.
Now suppose a different run of the same ten cases gives six substantive answers, five of them correct. Accuracy among answered cases is 5/6, about 83.3%, while answer coverage is 6/10, or 60%. These metrics answer different questions and should be reported together.
Always name the denominator. Distinguish attempted tasks, completed generations, answered cases, and scored outputs. If a judge fails to grade an output, report the missing judgment rather than silently treating it as a pass.
Metrics, logs, and traces
Metrics summarize measurements, such as error count or latency distributions. Logs record individual events. A trace connects steps belonging to one request, often through spans representing operations such as retrieval, model generation, and tool execution.
For an AI request, useful metadata includes configuration versions, candidate IDs, selected evidence IDs, tool-call outcomes, token usage, and elapsed times. This helps connect a quality failure to the stage that produced it.
Telemetry does not automatically explain correctness. A 200 response in 300 ms can still contain a wrong answer. Quality evaluation and operational signals need to be interpreted together.
Trace-reading exercise
Predict the outcome
Find where the evidence disappeared
S1 is the standard 30-day return rule and S2 is the custom-product exception. A user asks about a custom-printed product, and each trace below ends with the same wrong answer. For each trace, name the first stage that lost or misused S2 and what you would investigate first, before you reveal the answers.
| Trace | Retrieval returned | Context sent to the model | Answer | First evidence loss | Investigate first |
|---|---|---|---|---|---|
| T1 | S1, S2 | S1 | Says the 30-day window applies | ? | ? |
| T2 | S1, S2 | S1, S2 | Says the 30-day window applies | ? | ? |
| T3 | S1 | S1 | Says the 30-day window applies | ? | ? |
Protect evaluation and telemetry data
Prompts, documents, and tool results can contain private information. Store only what is needed for diagnosis, restrict access, and define retention. Stable IDs and configuration metadata can often support investigation without storing complete content.
A request ID belongs in a trace or log. Using every request ID as a metric label creates extremely high cardinality and can make the metric system expensive or unusable. Aggregate metrics by bounded categories such as outcome and configuration version.
Completion checklist
- Define a case with observable success conditions.
- Separate correctness, grounding, and format validity.
- Calculate success without excluding failed attempts.
- Read a trace to locate where evidence disappeared.
- Explain why privacy and metric cardinality affect instrumentation.
Sources
- OpenTelemetry signals Introduces traces, metrics, and logs.
- OpenTelemetry observability primer Explains using telemetry to investigate system behavior.
- Anthropic: Demystifying evals for AI agents Discusses tasks, trials, graders, and outcomes.
- NIST exact binomial confidence limits Statistical background for uncertainty in binary outcomes.
All datasets, answers, traces, measurements, thresholds, and rubrics here are original synthetic teaching material and describe a fictional application. They are not performance claims about a commercial model. Study times and readiness thresholds are editorial estimates. Production metrics and release gates must reflect the intended task and the consequences of failure, and tool-specific telemetry setups should be checked against the selected vendor's current documentation.
Related on CodeSnatch
Lessons, problems, and articles that build the skills this question uses.
AI Engineering
Follows a policy exception through ingestion, eligibility, and packing, a longer version of this trace reading.
System Design
Shows how spans form a trace for one request and how metrics and logs differ, the basics behind each signal.
DSA lesson
Practice finding the first step where state stops matching expectations, the habit reading spans in order needs.
Practice problem
Score a ranking with precision@k and recall@k, a way to measure retrieval quality apart from the final answer.
Community article
A practitioner's RAG failure modes, the eval metrics that catch each one, and the latency and refusal panels beside them.
Practice the interview question
Answer it in your own words before you look at the reference answer.
