paperbot · PL 论文追踪

全部论文 待读 收藏

P2 From Misuse to Mastery: Enhancing Code Generation with Knowledge-Driven AI Chaining

从误用到精通:用知识驱动 AI 链增强代码生成
ASE 2023 38th IEEE/ACM International Conference on Automated Software Engineering (ASE)2023匹配度 2/10 · 该论文聚焦用知识驱动提示链提升 LLM 代码生成中的异常处理质量,本质属于提示词工程/LLM 能力增强,而非用户关注的静态分析、形式化验证、浮点或贝叶斯程序分析,也未将 LLM 用于改进静态分析。引用 51 inbox
Xiaoxue Ren, Xinyuan Ye, Dehai Zhao, Zhenchang Xing, Xiaohu Yang
crossref: 2026-09-12dblp: 2026-09-12arxiv: 2026-09-12

AI 速览

一句话:提出知识驱动提示链 KPC,将代码生成拆为迭代检查-重写 AI 链,显著提升 LLM 异常处理质量。

大语言模型在自动代码生成上表现突出,但生成高质量可靠代码仍困难,尤其缺乏良好编程实践。本文先进行实证研究,总结 LLM 异常处理的三大挑战:异常处理不完整、不正确以及滥用 try-catch;并比较不同粒度提示,发现细粒度知识驱动提示效果最佳。基于此,提出知识驱动提示链式代码生成方法 KPC,将代码生成分解为含迭代检查-重写步骤的 AI 链,并链接细粒度知识提示,帮助 LLM 考虑异常处理规范。作者在从 Java 官方 API 文档抽取的 3,079 个代码生成任务上评估,静态评价指标分别提升 109.86% 与 578.57%,动态验证在抽样数据集上减少 18 个运行时 bug。

问题
LLM 自动代码生成质量与可靠性不足,尤其在异常处理上存在不完整、不正确和滥用 try-catch 的问题。
方法
通过实证比较不同粒度提示,提出 KPC:将生成过程分解为知识驱动提示链,并以迭代检查-重写步骤注入异常处理规范。
评估
在 3,079 个 Java 官方 API 文档抽取的代码生成任务上做静态评估与抽样动态验证,静态指标最高提升 578.57%,并减少 18 个运行时 bug。
原文摘要(Abstract)

Large Language Models (LLMs) have shown promising results in automatic code generation by improving coding efficiency to a certain extent. However, generating high-quality and reliable code remains a formidable task because of LLMs' lack of good programming practice, especially in exception handling. In this paper, we first conduct an empirical study and summarize three crucial challenges of LLMs in exception handling, i.e., incomplete exception handling, incorrect exception handling and abuse of try-catch. We then try prompts with different granularities to address such challenges, finding fine-grained knowledge-driven prompts works best. Based on our empirical study, we propose a novel Knowledge-driven Prompt Chaining-based code generation approach, name KPC, which decomposes code generation into an AI chain with iterative check-rewrite steps and chains fine-grained knowledge-driven prompts to assist LLMs in considering exception-handling specifications. We evaluate our KPC-based approach with 3,079 code generation tasks extracted from the Java official API documentation. Extensive experimental results demonstrate that the KPC-based approach has considerable potential to ameliorate the quality of code generated by LLMs. It achieves this through proficiently managing exceptions and obtaining remarkable enhancements of 109.86% and 578.57% with static evaluation methods, as well as a reduction of 18 runtime bugs in the sampled dataset with dynamic validation.

链接与引用

DOI 原文 · arXiv · PDF(开放获取) · DBLP

BibTeX
@inproceedings{abs-2309-15606,
  title = {From Misuse to Mastery: Enhancing Code Generation with Knowledge-Driven AI Chaining},
  author = {Xiaoxue Ren and Xinyuan Ye and Dehai Zhao and Zhenchang Xing and Xiaohu Yang},
  booktitle = {ASE},
  year = {2023},
  doi = {10.1109/ase56229.2023.00143}
}