When the AI Hallucinates
Occasionally, the AI may generate output that is incorrect, incomplete, or not grounded in your actual project state. This is referred to as hallucination. Hallucinations usually appear as:- Referencing files, APIs, or features that don’t exist
- Claiming something was “fixed” when nothing changed
- Repeating solutions that don’t resolve the issue
- Providing confident but incorrect instructions
How to Resolve Hallucinations
1. Ground the Model With Facts
Provide real, concrete inputs:- Error logs
- File contents
- Build output
- Exact error messages
“Here is the full error output. Fix only what’s causing this error.”
2. Constrain the Scope
Tell the AI exactly what it can and cannot change. Examples:- “Only modify the home screen component.”
- “Do not add new libraries.”
- “Do not change the navigation structure.”
3. Force Verification
If the AI claims something is fixed, require confirmation. Use prompts like:- “Show me exactly what changed.”
- “Which file was modified and why?”
- “Quote the line that fixes the error.”
4. Reset the Context
If hallucinations persist:- Start a new message with fresh context
- Paste only the relevant files or logs
- Restate the goal clearly
5. Use Images for Clarity
If the issue is visual, attach a screenshot to your prompt:“This button should be blue, but it’s showing as red. See the attached screenshot.”Visual context helps the AI understand exactly what needs to change.
When to Stop Iterating
Stop prompting the AI if:- It repeats the same fix multiple times
- It references non-existent files
- It contradicts itself across responses
- Starting a new conversation
- Simplifying your request
- Breaking the problem into smaller pieces
Best Practices to Avoid Loops
Always paste real logs
Always paste real logs
Copy the actual error message or log output into your prompt. Don’t paraphrase — the exact text matters.
Keep prompts short and specific
Keep prompts short and specific
Focus on one issue at a time. Multi-part prompts are more likely to cause confusion.
Verify every claimed fix
Verify every claimed fix
After the AI says something is fixed, test it. Don’t assume the fix worked until you see it in the preview.
Treat AI output as a suggestion
Treat AI output as a suggestion
The AI is a powerful tool, but it’s not infallible. Use your judgment to evaluate its suggestions.
Key Principle
The AI is strongest when reacting to real inputs, not guessing missing context.