Reducing Hallucinations in LLM-Generated Code via Semantic Triangulation
Yihan Dai, Sijie Liang, Haotian Xu, Peichu Xie, Sergey Mechtaev
Peking University
Key points
From the paper's conclusion- Semantic triangulation is a theory-grounded framework that decorrelates model errors by transforming the original problem into a dissociative variant and checks consistency between independently sampled solutions to both problems.
- We instantiate the framework through four concrete triangulation methods based on problem inversion, decomposition, and solution enumeration.
- Our tool increases the probability of selecting a correct program by 16% over baselines (test generation, metamorphic testing, and auto-formalized specifications) and achieves 7% higher reliability and 7% higher F1 score in selection-or-abstention scenarios.
Abstract
Large language models (LLMs) can generate executable code from natural language descriptions, but the resulting programs frequently contain bugs due to hallucinations. In the absence of formal specifications, existing approaches attempt to assess correctness using LLM-generated proxies such as tests or auto-formalized specifications. However, these proxies are produced by the same imperfect models and thus often corroborate rather than catch errors, especially when the model exhibits correlated errors. We introduce semantic triangulation, a theory-grounded framework that decorrelates model errors by transforming the original problem into a dissociative variant---one likely requiring a fundamentally different algorithm---and checks consistency between independently sampled solutions to both problems. We identify theoretical requirements for this framework, and we prove that under a formal model of LLM hallucinations, these properties confer higher confidence in program correctness. We instantiate the framework through four concrete triangulation methods based on problem inversion, decomposition, and solution enumeration. Evaluated on LiveCodeBench and CodeElo across GPT-4o, DeepSeek-V3, and Gemini 2.5 Flash, our tool increases the probability of selecting a correct program by 16% over baselines (test generation, metamorphic testing, and auto-formalized specifications) and achieves 7% higher reliability and 7% higher F1 score in selection-or-abstention scenarios, while being the only method that consistently handles inexact problems admitting multiple valid solutions.
Read the paper
Discussion · 1
Science Skim's AI key points, plus readers' public thoughts
- Semantic triangulation is a theory-grounded framework that decorrelates model errors by transforming the original problem into a dissociative variant and checks consistency between independently sampled solutions to both problems.
- We instantiate the framework through four concrete triangulation methods based on problem inversion, decomposition, and solution enumeration.
- Our tool increases the probability of selecting a correct program by 16% over baselines (test generation, metamorphic testing, and auto-formalized specifications) and achieves 7% higher reliability and 7% higher F1 score in selection-or-abstention scenarios.
Readers' thoughts
No reader thoughts yet.
Related papers
- From Observation to Explanation: Mechanistic Interpretability of LLM-Generated Code for Principled RepairarXiv · 2026
- GraphAlignCoder: Aligning Program and Proof Graphs for Code GenerationarXiv · 2026
- Large Language Model Powered Symbolic ExecutionProceedings of the ACM on Programming Languages · 2025
- Code as Explanations: Executable and Verifiable LLM ExplanationsarXiv · 2026
- Hallucinations of Large Language Models in Cross-Language Code Translation: Phenomena and MitigationarXiv · 2026
- HalluciNOT: execution grounded detection and targeted repair of symbolic drift hallucinations in large language model reasoningDiscover Computing · 2026