Refusing the Impossible: A Taxonomy and Benchmark for Code Hallucination in Large Language Models
Ask a coding model for something that cannot exist — a package that was never published, a compressor that shrinks every input, a decider for a problem proven undecidable — and it writes plausible, compiling code anyway on about 60% of attempts, refusing on only 27%. The authors wrote 270 such impossible prompts across six languages and paired them with 91 near-identical solvable versions; no model ever wrongly refused a solvable one, so this is missing scepticism rather than caution overshooting. Two details should change how you test: fabrication clusters on invented package names (98% of the npm prompts, 89% of the Rust ones) far more than on violations of theory, and how the request is phrased predicts the outcome about 2.5 times better than which model answers it. Put a handful of deliberately impossible tasks in your coding-agent eval and score whether the agent says no.