arXiv:2508.12358cs.SEcs.AI2025-08中稿 · the NIER track of …被引 12

LLMs常误判正确代码不满足需求,复杂提示反而加剧错误。

Uncovering Systematic Failures of LLMs in Verifying Code Against Natural Language Specifications

  • 用统一提示评估代码与自然语言需求的匹配度
  • 正确代码被错误标记为不合规或含缺陷,误判率高
  • 提出改进提示策略,适合代码审查与智能助手场景

大型语言模型(LLMs)已广泛用于软件开发中的需求工程、代码生成与评审。工程师常依赖LLMs判断代码是否满足任务要求,以提升代码质量。然而,现有研究未明确其能否可靠验证代码与自然语言规范的一致性。本文通过通用提示在主流基准上评估代码正确性,发现LLMs频繁将正确实现误判为“不符合要求”或存在潜在缺陷。令人意外的是,采用更复杂的提示(如包含解释和修正建议)反而导致更高误判率,暴露出其作为代码审查助手的重大可靠性问题。我们进一步分析误判根源,并提出两种改进提示策略。首次揭示了LLMs在代码与需求对齐上的系统性局限,为自动化代码审查与任务导向智能体提供了新洞见与实用指导。

原文摘要 · Abstract (English)

Large language models (LLMs) have become essential tools in software development, widely used for requirements engineering, code generation and review tasks. Software engineers often rely on LLMs to assess whether system code implementation satisfy task requirements, thereby enhancing code robustness and accuracy. However, it remains unclear whether LLMs can reliably determine whether the code complies fully with the given task descriptions, which is usually natural language specifications. In this paper, we uncover a systematic failure of LLMs in evaluating whether code aligns with natural language requirements. Specifically, with widely used benchmarks, we employ unified prompts to judge code correctness. Our results reveal that LLMs frequently misclassify correct code implementations as either ``not satisfying requirements'' or containing potential defects. Surprisingly, more complex prompting, especially when leveraging prompt engineering techniques involving explanations and proposed corrections, leads to higher misjudgment rate, which highlights the critical reliability issues in using LLMs as code review assistants. We further analyze the root causes of these misjudgments, and propose two improved prompting strategies for mitigation. For the first time, our findings reveals unrecognized limitations in LLMs to match code with requirements. We also offer novel insights and practical guidance for effective use of LLMs in automated code review and task-oriented agent scenarios.

代码审查大模型局限自然语言需求

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