3 ms·
Every time this topic comes up I post a similar comment about how hallucinations in code really don't matter because they reveal themselves the second you try t
by simonw 2y ago
Every time this topic comes up I post a similar comment about how hallucinations in code really don't matter because they reveal themselves the second you try to run that code.
I've just written up a longer form of that comment: "Hallucinations in code are the least dangerous form of LLM mistakes" - https://simonwillison.net/2025/Mar/2/hallucinations-in-code/ https://simonwillison.net/2025/Mar/2/hallucinations-in-code/
- woadwarrior01 2y ago> because they reveal themselves the second you try to run that code. In dynamic languages, runtime errors like calling methods with inexistent arguments etc only manifest when the block of code containing them is run and not all blocks of code are run at every invocation of the programs. As usual, the defenses against this are extensive unit-test coverage and/or static typing.
- simonw 2y ago"... only manifest when the block of code containing them is run" Right, that's the exact point I make in my blog post: you have to TEST the code - not just with automated tests, you have to actually try it out yourself as well. https://simonwillison.net/2025/Mar/2/hallucinations-in-code/ https://simonwillison.net/2025/Mar/2/hallucinations-in-code/
- grey-area 2y agoWhere the GAI hallucinates an api it is not always easy to find out if it exists given different versions and libraries for a given task, it can easily waste 10 mins trying to find the promised api, particularly when search results also include generated ai answers. Also there are plenty of mistakes that will compile and give subtle errors, particularly in dynamic languages and those which allow implicit coercion. Javascript comes to mind. The code can easily be runnable but wrong as well (or worse inconsistent and confusing) and this does happen in practice.
- simonw 2y agoMy blog post is all about the fact that "code can easily be runnable but wrong as well" - THAT's the thing you need to worry about, not hallucinated methods.
- margalabargala 2y agoA hallucinated API that is not near-trivially verifiable, is wishful thinking on the part of the AI almost every time.
- CSSer 2y agoMy favorite is when it hallucinates a library that does exist and ostensibly has a relevant title and methods but upon investigation proves to be for a purpose wholly unrelated to the current task. To make matters worse, this discovery will be greeted, every time, by "Ah, you're right!"
- deleted 2y ago[deleted]
- simonw 2y agoYeah, those are pretty frustrating. I've learned not to ask the question "Does library X have feature Y?" because if that feature sounds like a good idea it'll often confidently tell me that it exists when it doesn't.