Chapter 29 of 32

Appendix 13: AI Hallucination Check Prompt

Concepts

WHAT YOU NEED TO KNOW

HALLUCINATION MEANS LOSING GROUND

Hallucination includes invented code, misread errors, repeated fruitless edits, and contradiction of earlier logic. It signals the machine has lost contact with project reality.

DIAGNOSIS NEEDS EVIDENCE

Recent stack traces and summaries of fix attempts let the AI assess its own state. Concrete failure records replace vague feelings that something is wrong.

RISK SCORE FORCES HONESTY

Estimating a probability of being out of sync turns overconfidence into a measured claim. A number makes caution discussable and actionable.

FORTY PERCENT TRIGGERS RECOVERY

A threshold separates normal debugging from resynchronization work. Above the line, the session should stop pushing forward and repair grounding first.

suspect drift → gather traces
  → score risk → recover or proceed

RESET RESTORES BASELINE

Rebuilding a broken file or regenerating from the project outline discards tangled assumptions. Clean ground beats another patch on confused state.

RESYNC WITH REAL FILES

Requesting actual files lets the machine replace its imagined structure with repository truth. Stale internal models cannot be argued away; they must be refreshed.

REMODULARIZE REDUCES COMPLEXITY

Breaking tangled logic into smaller independent components lowers ambiguity. Simpler pieces are easier to verify and harder to hallucinate around.

CLARIFY GOAL AND STATE

Restating objectives and current system conditions removes competing interpretations. Shared understanding must be rebuilt before generation resumes.

CAUTION BEATS CONFIDENCE

Treating uncertainty as a high-risk signal prevents deeper tangles. Erring toward resync keeps debugging honest instead of hopeful.

Explain this chapter with AI

Copy this prompt into ChatGPT, Claude, Gemini, a local model, or another AI.

Apply this chapter with AI

Copy this prompt into ChatGPT, Claude, Gemini, a local model, or another AI.

You can use this prompt to query the AI to determine if it’s hallucinating.


    flowchart TD
    Start([🔍 Suspect Hallucination]) --> A[📋 Paste Recent Stack Traces]
    A --> B[📝 Summarize Fix Attempts]
    B --> C[🤖 AI Self-Diagnosis]
    C --> D{Calculate Hallucination Risk}
    D --> E[📊 Hallucination Risk Score]
    E --> F{Score > 40%?}
    F -- No --> G[✅ Proceed with Confidence]
    F -- Yes --> H[🔄 Choose Recovery Action]
    H --> H1[🔄 Reset a broken file]
    H --> H2[📁 Request actual file(s) to re-sync]
    H --> H3[🧹 Clean regenerate from scratch]
    H --> H4[🔧 Remodularize logic]
    H --> H5[🧭 Clarify goal or system state]
    H1 --> I[✅ Recovery Complete]
    H2 --> I
    H3 --> I
    H4 --> I
    H5 --> I

    style Start fill:#ffcdd2,stroke:#333
    style A fill:#fff3e0,stroke:#333
    style B fill:#e8f5e9,stroke:#333
    style C fill:#fce4ec,stroke:#333
    style D fill:#f3e5f5,stroke:#333
    style E fill:#fff9c4,stroke:#333
    style F fill:#e0f7fa,stroke:#333
    style G fill:#c8e6c9,stroke:#333
    style H fill:#ffccbc,stroke:#333
    style I fill:#4caf50,stroke:#333,color:#fff
  

## 🔍 DIAGNOSTIC: Are You Stuck in a Hallucination Loop?

We've been debugging a project together, and I need you to critically assess whether you are currently hallucinating or out of sync with the actual project structure.

### 📊 Your Task

1. **Estimate the probability (%) that you are hallucinating.**  
   Hallucination includes: making up code that doesn't exist, misinterpreting errors, repeating edits without solving issues, or contradicting earlier logic.

2. **Provide a brief rationale** for your hallucination score.

3. **If the score is above 40%**, suggest one or more of the following recovery actions:

   - 🔄 **Reset a broken file or component**
   - 📁 **Request actual user file(s) to re-sync**
   - 🧹 **Clean regenerate from scratch using project outline**
   - 🔧 **Remodularize**: break current logic into smaller, independent components to reduce complexity and ambiguity
   - 🧭 **Ask the user to clarify the goal or system state**

### ⚠️ Stack Traces

[Paste 3–6 recent stack traces here]


### 🛠️ Fix Attempts

[Summarize or paste AI-generated edits: filenames + key logic]


### 🧠 Required Output

There's a lot of Hallucination Risk Score: [   ]%
Explanation: [Brief reasoning]
Recommended Action(s): [Choose from options above]


Please err on the side of caution. If you're not confident in your current internal representation, treat that as a high-risk signal.