CodeTD: Topology of Attention Detects Hallucinations in Code LLMs
Abstract
As AI-code assistant tools become widespread, automatic assessment of the correctness of generated code becomes a significant challenge. Code LLMs are prone to hallucinations, which may lead to code that does not solve the 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 LLMs' attention maps. Our method quantifies prompt-generation mismatch using 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 outperforms recent baselines. Moreover, CodeTD is transferable between coding benchmarks.
Related
- Adaptive Task Offloading Under Dynamic Topology via Graph Attention-Enhanced Reinforcement Learning for Layered UAV-Enabled Digital Twin Channel Modeling
- Low-Cost Black-Box Detection of LLM Hallucinations via Dynamical System Prediction
- Perfect closure detects injective dimension
- Defining the Crick-Franklin-Watson genes of any robot (equals a finite state machine) and defining the Shannon genetic code attached to each gene. We also define the Krohn-Rhodes complexity of any regular maximal prefix code
- Lifting an [n,k,d] Binary Linear Code to an $[[n,k,d]]$ Quantum Stabilizer Code
BibTeX
@misc{voronkova2026codetd,
title = {{CodeTD: Topology of Attention Detects Hallucinations in Code LLMs}},
author = {Daria Voronkova and Ilya Trofimov and Anton Dmitriev and Eduard Tulchinskii and Evgeny Burnaev and Serguei Barannikov},
howpublished = {arXiv},
year = {2026},
month = sep,
doi = {10.48550/arxiv.2609.07779},
eprint = {2609.07779},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2609.07779},
note = {CC BY 4.0},
}
RIS
TY - UNPB
TI - CodeTD: Topology of Attention Detects Hallucinations in Code LLMs
AU - Daria Voronkova
AU - Ilya Trofimov
AU - Anton Dmitriev
AU - Eduard Tulchinskii
AU - Evgeny Burnaev
AU - Serguei Barannikov
PY - 2026
DA - 2026/09/07
PB - arXiv
DO - 10.48550/arxiv.2609.07779
UR - https://arxiv.org/abs/2609.07779
AB - As AI-code assistant tools become widespread, automatic assessment of the correctness of generated code becomes a significant challenge. Code LLMs are prone to hallucinations, which may lead to code that does not solve the 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 LLMs' attention maps. Our method quantifies prompt-generation mismatch using 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 outperforms recent baselines. Moreover, CodeTD is transferable between coding benchmarks.
ER -