arXiv:2509.26546cs.SEcs.LG2025-09被引 6

让大模型代码推理结果可验证,提升开发信任度

Towards Verified Code Reasoning by LLMs

  • 将大模型的推理过程转为形式化表达,用验证工具自动检查
  • 在20个未初始化变量案例中正确验证13例,8个等价性判断中发现6处错误
  • 适合需要高精度的代码审查、新代码理解与自动化生成场景

尽管基于大模型的智能体能够处理多种代码推理任务,但其答案并不总是正确,这限制了其在高精度场景下的应用:如协助工程师理解新代码库、代码评审,或确保自动生成的代码满足特定要求(如修复漏洞、提升可读性、实现功能)。由于缺乏可信度,每次回答都需人工核验,消耗人力且降低开发效率。本文提出一种自动验证代码推理智能体答案的方法:提取其推理步骤的形式化表示,并利用形式化验证与程序分析工具进行检验。我们在20个由检测工具发现的未初始化变量错误和20个程序等价性查询上测试该方法。结果显示,在未初始化变量问题中,形式化验证成功确认了13/20例推理正确;在程序等价性判断中,成功识别出8例中的6个错误结论。

原文摘要 · Abstract (English)

While LLM-based agents are able to tackle a wide variety of code reasoning questions, the answers are not always correct. This prevents the agent from being useful in situations where high precision is desired: (1) helping a software engineer understand a new code base, (2) helping a software engineer during code review sessions, and (3) ensuring that the code generated by an automated code generation system meets certain requirements (e.g. fixes a bug, improves readability, implements a feature). As a result of this lack of trustworthiness, the agent's answers need to be manually verified before they can be trusted. Manually confirming responses from a code reasoning agent requires human effort and can result in slower developer productivity, which weakens the assistance benefits of the agent. In this paper, we describe a method to automatically validate the answers provided by a code reasoning agent by verifying its reasoning steps. At a very high level, the method consists of extracting a formal representation of the agent's response and, subsequently, using formal verification and program analysis tools to verify the agent's reasoning steps. We applied this approach to a benchmark set of 20 uninitialized variable errors detected by sanitizers and 20 program equivalence queries. For the uninitialized variable errors, the formal verification step was able to validate the agent's reasoning on 13/20 examples, and for the program equivalence queries, the formal verification step successfully caught 6/8 incorrect judgments made by the agent.

代码推理大模型验证形式化验证智能编程

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。