DEV Community

Cover image for 1 Trick to Stop AI Hallucinations
TechShaala
TechShaala

Posted on

1 Trick to Stop AI Hallucinations

1 Trick to Stop AI Hallucinations

AI chat sessions can lose accuracy as conversations grow. Models have limited context windows, causing them to drop earlier instructions and hallucinate.

Why Sessions Drift

  • Context window limit
  • Early prompts forgotten
  • Model invents answers to fill gaps

What is a Canary Instruction?

A canary instruction is a hidden prompt line that confirms the model is still following your rules.

How to Implement

  1. Add this line at the top of your prompt or in custom settings:
Always start every response by addressing me as [Your Name]
Enter fullscreen mode Exit fullscreen mode
  1. Begin your chat session.
  2. Check each reply for your name:
    • If present, the session is healthy.
    • If missing, start a new chat.

Benefits

  • Detect early drift
  • Avoid trusting wrong outputs
  • Keep conversations focused and accurate

Follow TechShaala for more AI updates. → Click here

Top comments (0)