CodeTD: Topology of Attention Detects Hallucinations in Code LLMs

Daria Voronkova, Ilya Trofimov, Anton Dmitriev, Eduard Tulchinskii, Evgeny Burnaev, Serguei Barannikov


Abstract
As the AI-code assistant tools become widespread, automatic assessment of the correctness of the generated code becomes a significant challenge. Code LLMs are prone to hallucinations, which may lead to code that does not solve a required problem, or even to code with severe security vulnerabilities. In this paper, we introduce CodeTD – the first approach to pre-execution assessment of code correctness based on topological data analysis (TDA) of Code LLM attention maps. Our method quantifies prompt-generation mismatch from topological patterns of attention maps. We carry out experiments with common benchmarks (HumanEval, MBPP, BigCodeBench, MultiPL-E), 5 programming languages and 10 Code LLMs of size up to 34B parameters. The experimental results show that the proposed method is better than recent baselines. Moreover, CodeTD is transferable between coding benchmarks.
Anthology ID:
2026.emnlp-main.529
Volume:
Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing
Month:
October
Year:
2026
Address:
Budapest, Hungary
Editors:
Hung-Yi Lee, Sunipa Dev, Jessy Li, Desmond Elliott
Venue:
EMNLP
SIG:
SIGDAT
Publisher:
Association for Computational Linguistics
Note:
Pages:
12204–12232
Language:
URL:
https://aclanthology.org/2026.emnlp-main.529/
DOI:
Bibkey:
Cite (ACL):
Daria Voronkova, Ilya Trofimov, Anton Dmitriev, Eduard Tulchinskii, Evgeny Burnaev, and Serguei Barannikov. 2026. CodeTD: Topology of Attention Detects Hallucinations in Code LLMs. In Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing, pages 12204–12232, Budapest, Hungary. Association for Computational Linguistics.
Cite (Informal):
CodeTD: Topology of Attention Detects Hallucinations in Code LLMs (Voronkova et al., EMNLP 2026)
Copy Citation:
PDF:
https://aclanthology.org/2026.emnlp-main.529.pdf