Lesson 3 of 3 Monitoring Agents, Tools and Vector Stores

Diagnosing Hallucinations, Inconsistency and Flawed Reasoning

This lesson covers troubleshooting frameworks for generative AI failure modes that traditional ML monitoring does not catch: confident hallucinations, inconsistent answers, flawed reasoning and sensitivity to small prompt changes.

Learning outcomes

After completing this lesson, you will be able to:

  • Detect hallucinations with golden datasets.
  • Measure consistency with output diffing.
  • Trace reasoning paths to find where logic failed.

Golden datasets for hallucination detection

Hallucinations are hard to measure on live traffic, because the correct answer is usually unknown. A golden dataset solves this: it is a curated set of inputs with verified reference answers or facts, covering typical, difficult and edge cases. It deliberately includes questions whose correct answer is that the information is not in the documents, because inventing an answer to such a question is a common form of hallucination.

The dataset is run on a schedule and on every change to prompts, models or data, and the outputs are scored for correctness and faithfulness to the sources, by comparison with the reference answers or by an LLM judge. The result is a hallucination rate measured on known ground truth that can be tracked over time. New failure cases found in production are added, so the dataset grows with experience.

The following diagram shows the diagnosis of an assistant that gives contradictory answers, and the fixes.

Diagnosing contradictory answers. Output diffing over 20 repeated runs shows 30% disagreement, and reasoning traces show the model sometimes ignores one rule. Lower temperature, a prompt that checks each rule explicitly and an Automated Reasoning check fix it, and the questions join the golden dataset.
The golden dataset keeps the problem from returning unnoticed.
Select all that apply

A good golden dataset

Exam skills 4.3.6 · 5.1.4

Choose the properties of a useful golden dataset for hallucination detection.

Log in to try this activity Interactive activities are free with an account.

Output diffing for consistency

Output diffing compares responses to the same input across repeated runs, prompt versions, model versions or periods of time. Exact text comparison is too strict for generated text, because two correct answers rarely use the same words. Comparisons therefore use the semantic similarity of the answers' embeddings, field-by-field comparison for structured outputs, and an LLM judge's assessment of whether two answers say the same thing.

The results point to different causes. Low consistency across repeated runs of the same configuration suggests a high temperature or an ambiguous prompt. Differences between versions reveal behaviour changes introduced by a new prompt or model, which can be reviewed before users encounter them.

True or false

Comparing outputs

Exam skills 4.3.6

Check three claims about output diffing.

Log in to try this activity Interactive activities are free with an account.

Reasoning path tracing and specialised pipelines

Reasoning path tracing examines intermediate steps to find where logic went wrong: agent traces show each thought, tool call and observation; logged chain-of-thought or plan outputs show the model's stated reasoning; Step Functions execution history shows each stage. Typical findings are a wrong tool choice, a misread tool result, a plan that skipped a required check or an early assumption that was never revisited.

Specialized observability pipelines automate this analysis: invocation logs and traces stream to S3 or a log subscription, a scheduled job samples interactions, scores them with judges and rules, clusters failures by type (hallucination, refusal, format, wrong tool) and publishes metrics and examples to dashboards. The following table summarises the techniques.

Failure modeDetection technique
HallucinationGolden dataset runs; faithfulness judges; grounding checks
Inconsistent answersOutput diffing across runs and versions
Faulty multi-step reasoningReasoning path tracing in agent traces and workflow history
Unintended change after updateVersion-to-version diffing on fixed inputs
Recurring failure types at scaleObservability pipeline with scoring and clustering
Worked example

Contradictory answers

Users report that asking the same eligibility question twice can produce opposite answers.

Output diffing over 20 repeated runs of affected questions shows 30% disagreement. Reasoning traces show the model sometimes ignores one rule. The team lowers temperature, restructures the prompt to check each rule explicitly, adds an Automated Reasoning check, and adds the questions to the golden dataset with a consistency threshold.

Check yourself

How is hallucination rate measured?

Show answer

Against a golden dataset of verified answers.

Exam Tips

Remember for the exam

  • Golden datasets measure hallucination against verified answers.
  • Output diffing with semantic similarity measures consistency.
  • Trace reasoning paths to find logical errors in agents.
  • Automate scoring and failure clustering in an observability pipeline.