💡
7
c/ai-innovations•jana_shahjana_shah•1mo ago

Just found a stupid simple way to stop AI chatbots from hallucinating bad code

Been fighting with ChatGPT for weeks giving me code that looked right but wouldn't compile. Got so mad I almost gave up on using it for my Flask project. Then I started pasting the exact error message back into the chat and asking it to explain what caused that specific error line by line. It worked like magic - the suggestions went from broken junk to working stuff in under 10 tries. Has anyone else found a weird trick like this that cuts down on the hallucinations?
4 comments

Log in to join the discussion

Log In
4 Comments
wilson.joseph
Man, @avery_ross I feel that so hard. I'm not great at coding either and sometimes I wonder if the AI just gives up trying to explain things to me. But honestly, that trick with pasting the error messages is solid. I've been doing something similar with Python scripts - just copy the whole error output and ask "why does this break here?" It forces the AI to actually trace through the logic instead of guessing. The other trick that helped me was asking it to write a test case for the function first before writing the actual code. That catches a lot of the dumb mistakes before they even happen. For a beginner like me, small stuff like that makes a huge difference.
5
rose_reed
rose_reed1mo ago
Classic trick, works with people too when you make them repeat the problem back.
2
taylor.reese
@rose_reed I tried that on my buddy last week and he fixed his own problem in 2 minutes flat.
2
avery_ross
avery_ross1mo ago
Haha, I'm so bad at coding that even the AI probably gets dumber just from reading my error messages.
1