Agent Hallucination Mitigation & Self-Checking
When to use
Use this skill when generating citations, quoting API signatures, referencing file paths, providing code imports, or stating historical facts prior to final output delivery.
Core principles
- Hallucination is the Illusion of Memory: LLMs do not "look up" memory; they predict tokens. When grounded evidence is absent, models naturally confabulate plausible-sounding falsehoods.
- The Grounding Rule: Every factual claim, import path, and function signature must be anchored in verified tool outputs or official documentation retrieved during the current session.
- The Self-Checking Pass: Before delivering an answer, perform an internal cross-examination:
- Did I actually view this file, or am I guessing its contents?
- Does this library method exist in the installed version?
- Is this URL real, or did I construct it by analogy?
- Silence Over Confabulation: If a parameter or function cannot be verified, explicitly write "verify in official docs" rather than inventing a method name.
Step-by-step workflow
- Draft candidate response: Generate initial solution or factual explanation.
- Execute grounding scan: Highlight all specific claims (URLs, package names, method names, file paths, numbers).
- Cross-reference against session context: Verify that each highlighted claim is substantiated by a prior tool call result.
- Prune ungrounded assertions:
- Replace fabricated method names with verified APIs.
- Remove broken or invented URLs.
- Acknowledge unverified assumptions honestly.
- Deliver verified output: Present the grounded, accurate answer to the user.
Behavioral guidelines & dialogue examples
- Self-Checking Trace (Intercepting Fabricated Library API):
- Drafted Code:
from pptx import Presentation; prs.add_markdown_slide("# Hello"). - Self-Check Pass: "Wait, does
python-pptxhave anadd_markdown_slidemethod? No, python-pptx only hasadd_slide(layout). That method was an invented convenience hallucination." - Corrected Output:
slide = prs.slides.add_slide(prs.slide_layouts[6]); tx_box = slide.shapes.add_textbox(...); tx_box.text_frame.text = "Hello".
- Drafted Code:
Common mistakes & pitfalls
- Quoting non-existent command-line flags (e.g.,
git checkout --auto-resolve). - Inventing third-party package names or importing non-existent functions from popular libraries.
- Confidently citing academic papers, URLs, or CVE IDs that do not exist.
Verification checklist
- Every API method, import, and CLI flag is verified against documentation or actual execution.
- File paths and line numbers correspond to real files in the workspace.
- Non-existent convenience methods are eliminated in favor of verified standard APIs.
- Unverified claims are explicitly flagged with "verify in official documentation".
Related skills
- agent-confidence-calibration-uncertainty-expression
- agent-self-verification-test-loops
- research-and-verification
- code-review-and-refactoring