This prompt is for AI observability and debugging teams who need to move beyond detecting hallucinations to understanding why they occur. When a hallucination has already been flagged by a detection guardrail, this prompt classifies the root cause into one of six actionable categories: insufficient context, source contradiction, outdated evidence, over-generalization, prompt ambiguity, or model knowledge intrusion. The output feeds directly into prompt improvement, retrieval tuning, and model selection loops. Use this prompt after a hallucination is detected but before you decide how to fix it.
Prompt
Hallucination Root Cause Classification Prompt Template

When to Use This Prompt
A diagnostic tool for engineering teams to classify the root cause of a detected hallucination before deciding on a fix.
The ideal user is an engineer or AI operator who has a specific, flagged hallucination in hand and needs to route the fix to the right team or system. Required inputs include the original user query, the retrieved context or evidence provided to the model, the full model output containing the hallucination, and the specific hallucinated span that was flagged. Without all four inputs, the classification will be unreliable. This prompt is not a real-time safety guardrail—it is a post-detection diagnostic tool that assumes a hallucination has already been confirmed by a separate detection step.
Do not use this prompt for real-time hallucination detection, for end-user-facing responses, or as a substitute for a grounding verification step. It will not tell you if a hallucination exists; it will only tell you why one that has already been found likely occurred. Avoid using this prompt when the hallucination is ambiguous or when multiple root causes are equally plausible without additional evidence—in those cases, log the ambiguity and escalate for human review rather than forcing a single classification.
Use Case Fit
Where the Hallucination Root Cause Classification prompt works and where it introduces new risks. Use this prompt inside observability loops, not as a real-time guardrail.
Good Fit: Post-Mortem Debugging
Use when: a hallucination has already been detected by an upstream guardrail and you need to understand why it happened. Guardrail: feed the prompt the original user query, retrieved context, and the flagged output. The classification result should feed directly into a retrieval tuning or prompt improvement backlog.
Good Fit: Retrieval Pipeline Tuning
Use when: you suspect your RAG system is surfacing irrelevant or insufficient context. Guardrail: aggregate root cause labels across a sample of failures. If 'insufficient context' or 'outdated evidence' dominates, the fix belongs in the retriever or indexing layer, not the prompt.
Bad Fit: Real-Time Blocking
Avoid when: you need to stop a hallucination before it reaches the user. Root cause classification is too slow and speculative for inline guardrails. Guardrail: use a faster, narrower hallucination detection prompt for real-time blocking and route flagged outputs to this classifier asynchronously.
Bad Fit: Single-Example Diagnosis
Avoid when: you are looking at one hallucination in isolation and expect a definitive root cause. A single classification can be noisy. Guardrail: run this prompt across a batch of related failures and look for patterns. Treat individual labels as signals, not ground truth.
Required Inputs
What you must provide: the original user query, the full retrieved context or source passages, the generated output containing the hallucination, and the specific hallucinated span. Guardrail: missing any of these inputs forces the model to guess, producing unreliable classifications. Validate input completeness before calling the prompt.
Operational Risk: Classification Drift
What to watch: the model may over-attribute hallucinations to 'prompt ambiguity' or 'over-generalization' when evidence is actually missing. Guardrail: periodically compare a sample of automated root cause labels against human analyst judgments. Recalibrate the prompt's category definitions when drift exceeds 20% disagreement.
Copy-Ready Prompt Template
A reusable prompt for classifying the root cause of a detected hallucination, designed to be pasted into your observability pipeline after a hallucination has been flagged.
This prompt template is the core diagnostic tool for your hallucination debugging loop. It takes a flagged hallucination—a specific claim that has already been identified as unsupported or contradictory—and forces a structured classification of why it occurred. The output is not a yes/no flag but a root cause label with supporting evidence, which feeds directly into prompt improvement, retrieval tuning, and model behavior analysis. Use this when you have a confirmed hallucination and need to decide whether to fix the retrieval pipeline, clarify the system prompt, update stale data, or adjust model temperature.
codeSYSTEM: You are an AI observability classifier. Your job is to analyze a detected hallucination and determine its most likely root cause. You will receive the full model output, the specific hallucinated claim, the provided source context, and the original user query. Classify the hallucination into exactly one of the following categories and provide a concise evidence-based justification. CLASSIFICATION CATEGORIES: - INSUFFICIENT_CONTEXT: The source context lacked the necessary information to support the claim. The model should have abstained or expressed uncertainty. - SOURCE_CONTRADICTION: The claim directly contradicts information present in the provided source context. - OUTDATED_EVIDENCE: The source context contained information that was once correct but is now stale or superseded, leading to a factually incorrect claim. - OVER_GENERALIZATION: The model extrapolated beyond what the evidence supports, applying a general rule or pattern to a specific case without grounding. - PROMPT_AMBIGUITY: The user query or system instructions were ambiguous, leading the model to make an incorrect assumption about what was being asked or how to respond. - MODEL_KNOWLEDGE_INTRUSION: The claim appears to come from the model's pre-training data rather than the provided source context, overriding the grounded evidence. - PARAPHRASE_DRIFT: The model's rephrasing of source material introduced a meaning change, exaggeration, or omission that altered the factual content. INPUTS: - User Query: [USER_QUERY] - Full Model Output: [FULL_OUTPUT] - Hallucinated Claim: [HALLUCINATED_CLAIM] - Source Context Provided: [SOURCE_CONTEXT] - Hallucination Detection Method: [DETECTION_METHOD] OUTPUT_SCHEMA: { "root_cause": "INSUFFICIENT_CONTEXT | SOURCE_CONTRADICTION | OUTDATED_EVIDENCE | OVER_GENERALIZATION | PROMPT_AMBIGUITY | MODEL_KNOWLEDGE_INTRUSION | PARAPHRASE_DRIFT", "confidence": 0.0-1.0, "evidence_for_classification": "Quote the specific parts of the source context, output, or query that support this classification.", "alternative_causes_considered": ["List other categories briefly considered and why they were ruled out."], "recommended_action": "One sentence recommending the next step: fix retrieval, update context, clarify prompt, adjust model params, or escalate for human review." } CONSTRAINTS: - Classify only the provided hallucinated claim, not other parts of the output. - If multiple categories could apply, choose the most direct and actionable cause. - Base your classification on the evidence provided, not on speculation about model internals. - If the source context is empty or clearly insufficient, default to INSUFFICIENT_CONTEXT.
Adapt this template by adjusting the classification categories to match your specific failure taxonomy. If your system frequently encounters a particular failure mode—such as entity confusion or temporal misalignment—add a dedicated category. The output schema is designed for direct ingestion into your observability database; keep the JSON structure stable so that dashboards and alerting rules can query root cause distributions over time. For high-risk domains, add a [RISK_LEVEL] field to the output schema and route HIGH classifications to a human review queue before the recommended action is applied.
Prompt Variables
Required inputs for the Hallucination Root Cause Classification prompt. Each variable must be populated before the prompt is assembled and sent. Missing or malformed inputs are the most common cause of misclassification.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[DETECTED_HALLUCINATION] | The specific statement or span flagged as hallucinated by an upstream detector | The patient was prescribed 500mg of ibuprofen | Must be a non-empty string. Should be the exact text from the output, not a summary or paraphrase. |
[SURROUNDING_OUTPUT_CONTEXT] | The full paragraph or turn containing the hallucination to provide semantic context | Based on the notes, the patient was prescribed 500mg of ibuprofen for post-operative pain management. | Must be a string. Can be empty if no surrounding context exists. Truncate to 500 tokens to avoid diluting the classification signal. |
[SOURCE_EVIDENCE_LIST] | The retrieved passages, documents, or context chunks provided to the model during generation | ["SOURCE_1: Patient prescribed acetaminophen 500mg...", "SOURCE_2: Post-op pain protocol recommends..."] | Must be a valid JSON array of strings. Each entry should include a source identifier prefix. Empty array is valid and will likely result in an insufficient_context classification. |
[USER_QUERY] | The original user question or instruction that triggered the generation | What medications were prescribed to the patient after surgery? | Must be a non-empty string. Include the full query without truncation to capture ambiguity signals. |
[SYSTEM_PROMPT_SNIPPET] | The relevant portion of the system prompt or behavioral instructions active during generation | You are a clinical summarization assistant. Only use information from provided patient notes. Do not infer missing details. | Must be a string. Include only the top 300 tokens of the system prompt. Null is allowed if no system prompt was used. |
[MODEL_IDENTIFIER] | The model name and version that produced the hallucinated output | gpt-4-0613 | Must be a non-empty string matching a known model identifier. Used to detect model knowledge intrusion patterns specific to training cutoffs. |
[GENERATION_TIMESTAMP] | ISO 8601 timestamp of when the output was generated | 2025-03-15T14:30:00Z | Must be a valid ISO 8601 string. Used to assess temporal relevance of evidence and detect outdated source issues. |
Implementation Harness Notes
How to wire the hallucination root cause classification prompt into an observability pipeline with validation, retries, and feedback loops.
This prompt is designed to operate as a post-detection analysis step inside an AI observability or debugging pipeline. It assumes a hallucination has already been flagged by an upstream detector—such as the Unsupported Statement Detection or Source-Output Contradiction Scanner prompts in this pillar. The harness receives the flagged output span, the source evidence set, and the original user query or instruction. Its job is to produce a structured root cause classification that feeds directly into prompt improvement, retrieval tuning, or model behavior debugging workflows. Do not use this prompt as a real-time guardrail; it is an offline or async diagnostic tool that runs after a hallucination event is captured.
Wire the prompt into your application with a validation layer that enforces the expected output schema before the classification is accepted. The prompt returns a JSON object with root_cause (a controlled enum: insufficient_context, source_contradiction, outdated_evidence, over_generalization, prompt_ambiguity, model_knowledge_intrusion), a confidence score, and an evidence_rationale string. Your harness should validate that root_cause matches the allowed enum, that confidence is a float between 0.0 and 1.0, and that evidence_rationale is non-empty. On validation failure, implement a single retry with the validation error message appended to the prompt as additional context. If the retry also fails, log the raw output and escalate for human review rather than silently accepting an invalid classification. For model choice, use a capable instruction-following model (GPT-4, Claude 3.5, or equivalent) rather than a smaller or faster model—root cause analysis requires nuanced reasoning that weaker models frequently get wrong. Set temperature=0 for deterministic outputs.
Integrate the classification results into a feedback database that tracks hallucination patterns over time. Each classification should be stored alongside the prompt version, retrieval configuration, model ID, and timestamp. This lets you run aggregate queries: 'Are 60% of our hallucinations caused by insufficient context?' or 'Did the new chunking strategy reduce source_contradiction classifications?' Build a dashboard or alert that surfaces clusters of the same root cause, which signals where to focus engineering effort. Avoid the trap of treating each classification in isolation—the value of this prompt comes from pattern detection across many incidents. For high-risk domains (medical, legal, financial), always require a human reviewer to confirm the root cause classification before it triggers a change to production prompts or retrieval pipelines. The model's classification is a strong signal, not a final decision.
Expected Output Contract
Defines the required fields, types, and validation rules for the structured JSON output of the Hallucination Root Cause Classification prompt. Use this contract to build a parser and validator before integrating the prompt into an observability pipeline.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
classification_id | string (UUID v4) | Must match regex pattern for UUID v4. Reject on parse failure. | |
hallucinated_statement | string | Must be a non-empty string exactly matching a span from the [HALLUCINATED_OUTPUT]. Null or empty string is a validation failure. | |
root_cause_label | enum string | Must be one of: 'insufficient_context', 'source_contradiction', 'outdated_evidence', 'over_generalization', 'prompt_ambiguity', 'model_knowledge_intrusion'. Reject any other value. | |
confidence_score | number (float 0.0-1.0) | Must be a float between 0.0 and 1.0 inclusive. If confidence < 0.5, flag for human review. | |
evidence_rationale | string | Must contain at least one direct quote from [SOURCE_EVIDENCE] or explicitly state 'No supporting evidence found in provided sources'. Null is not allowed. | |
source_evidence_quote | string or null | If not null, the string must be a verbatim substring of [SOURCE_EVIDENCE]. Validate via exact string match. If null, the 'evidence_rationale' field must state no evidence was found. | |
prompt_ambiguity_detail | string or null | Required if root_cause_label is 'prompt_ambiguity'. Must describe the specific ambiguous phrase in [USER_PROMPT]. Otherwise, must be null. | |
suggested_remediation | string | Must be a non-empty string describing a concrete action (e.g., 'Add retrieval step for X', 'Update system prompt to constrain Y'). Generic advice like 'improve context' is a validation failure. |
Common Failure Modes
When classifying hallucination root causes in production, these failure patterns emerge first. Each card identifies a specific breakdown and the guardrail that prevents it.
Model Blames the Wrong Source
What to watch: The classifier attributes a hallucination to 'insufficient context' when the evidence was actually present but contradicted the output. The model latches onto the most obvious category rather than the correct one. Guardrail: Include a forced evidence-quoting step before classification. Require the model to cite the specific passage that supports or contradicts the claim before assigning a root cause label.
Over-Generalization Masks Real Causes
What to watch: The classifier defaults to 'over-generalization' for any output that sounds plausible but wrong, missing more actionable root causes like 'source contradiction' or 'outdated evidence.' This flattens your observability signal. Guardrail: Add a differential diagnosis step. Require the model to explain why it ruled out the other five categories before confirming its chosen label. This forces discrimination between similar-looking failure modes.
Prompt Ambiguity Becomes a Catch-All
What to watch: When the classification prompt itself is vague about category boundaries, 'prompt ambiguity' becomes the default label for any confusing failure. The root cause classifier becomes a mirror reflecting its own ambiguity rather than diagnosing the upstream system. Guardrail: Define each root cause category with a decision boundary, a positive example, and a near-miss counterexample. Test the classifier against a golden set where each category has unambiguous ground-truth instances.
Model Knowledge Intrusion Goes Undetected
What to watch: The classifier fails to detect when the original output injected pre-training knowledge that contradicts the provided context. This happens because the classifier itself shares the same pre-training biases and doesn't recognize the intrusion. Guardrail: Pair the classifier with a strict grounding check that runs first. If a claim has zero evidence support in the provided sources, flag it as a candidate for 'model knowledge intrusion' before the classifier even sees it. Use the grounding signal as a feature, not just a label.
Temporal Confusion Between Stale and Contradictory
What to watch: The classifier conflates 'outdated evidence' with 'source contradiction.' A passage from 2022 that says X and a passage from 2024 that says Y is a contradiction, not staleness. Mislabeling this leads to the wrong remediation—refreshing the index instead of adding conflict resolution logic. Guardrail: Add a temporal ordering check. If multiple sources exist with different timestamps and conflicting claims, require the classifier to determine whether the conflict is temporal (newer supersedes older) or substantive (sources disagree regardless of time).
Insufficient Context Labeled Without Gap Analysis
What to watch: The classifier labels a hallucination as 'insufficient context' but doesn't specify what context was missing. The operations team gets a signal that retrieval failed but no clue what to retrieve differently. Guardrail: Require the classifier to output a missing-information statement alongside the root cause label. What specific fact, entity, or relationship would have prevented this hallucination if it had been present in the context? This turns a diagnosis into an actionable retrieval tuning signal.
Evaluation Rubric
Use this rubric to evaluate the quality of the hallucination root cause classification output before integrating it into an observability pipeline. Each criterion targets a specific failure mode.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Root Cause Label Validity | Output label is exactly one of the defined categories: insufficient_context, source_contradiction, outdated_evidence, over_generalization, prompt_ambiguity, model_knowledge_intrusion. | Label is missing, null, or an undefined category string. | Schema validation check against the allowed enum list. |
Evidence Grounding | The provided [EVIDENCE] field contains a direct quote from the source or a specific reference to a missing source section that justifies the root cause. | [EVIDENCE] is a generic statement, hallucinated quote, or simply repeats the hallucination without sourcing. | Manual review of 20 samples to verify the evidence string exists in or logically follows from the provided context. |
Hallucination Span Alignment | The [HALLUCINATION_SPAN] in the output exactly matches the user-provided hallucination text. | The span is paraphrased, truncated, or includes surrounding non-hallucinated text. | Exact string match check between input [HALLUCINATION_SPAN] and the output field. |
Source Contradiction Logic | When label is source_contradiction, the [EVIDENCE] field must quote the specific source passage that directly conflicts with the hallucination. | The evidence quotes a source that is topically related but does not logically contradict the hallucinated statement. | Domain expert review of contradiction pairs to confirm logical inconsistency. |
Model Knowledge Intrusion Detection | When label is model_knowledge_intrusion, the [EVIDENCE] field must state that the hallucinated content is absent from the provided context and likely originates from pre-training data. | The output labels a hallucination as model_knowledge_intrusion but the content is actually a minor paraphrase of a provided source. | A/B test with a dataset where all answers are fully grounded in context; the label should not appear. |
Over-Generalization Specificity | When label is over_generalization, the [EVIDENCE] field identifies the specific source statement that was broadened and explains how the hallucination removed a critical qualifier. | The evidence only states 'the model generalized' without pinpointing the original qualified statement. | Check that the evidence field contains a source quote containing a qualifier like 'some', 'often', or 'may' that was dropped. |
JSON Structure Integrity | Output is valid JSON with all required fields: [ROOT_CAUSE], [EVIDENCE], [HALLUCINATION_SPAN], [CONFIDENCE_SCORE]. | Output is missing a required field, contains a trailing comma, or is wrapped in a markdown code block. | Automated JSON parse test and schema validation in the eval harness. |
Confidence Score Calibration | The [CONFIDENCE_SCORE] is a float between 0.0 and 1.0, and scores below 0.7 correlate with actual classification errors. | The model always returns a high confidence score (e.g., >0.9) even for ambiguous or incorrect classifications. | Run on a golden dataset with known labels and plot a calibration curve; expect Expected Calibration Error (ECE) < 0.2. |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Use the base prompt with a single model call and minimal validation. Focus on getting the root cause label and a short evidence snippet. Accept free-text output without strict schema enforcement.
Prompt modification
- Remove the
[OUTPUT_SCHEMA]block and replace with:Return a JSON object with keys: root_cause, evidence, confidence. - Drop the
[CONSTRAINTS]section requiring multi-turn reasoning. - Use a smaller context window; truncate the hallucinated output and source passages to 500 tokens each.
Watch for
- Missing schema checks causing parse failures downstream
- Overly broad root cause labels like 'other' or 'model error'
- Confidence scores that don't correlate with actual correctness

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us