From Misuse to Mastery: Enhancing Code Generation with Knowledge-Driven AI Chaining
Not on the map. Why?
Abstract (arXiv)
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 summarise 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.
Key facts. Cited by 15 papers in the map (data through 14 Oct 2026). First posted on arXiv 27 Sep 2023.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2024: 8; 2025: 4; 2026: 3.
15 papers.
Sort:
By area:
- 2024Large Language Model-Based Agents for Software Engineering: A Surveycited by 178
- 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
- 2024A Survey on Data Synthesis and Augmentation for Large Language Modelscited by 41
- 2025Agent READMEs: An Empirical Study of Context Files for Agentic Codingcited by 23
- 2024A Pair Programming Framework for Code Generation via Multi-Plan Exploration and Feedback-Driven Refinementcited by 21
- 2024Preference-Guided Refactored Tuning for Retrieval Augmented Code Generationcited by 10
- 2024Towards Exception Safety Code Generation with Intermediate Representation Agents Frameworkcited by 3
- 2026EvoSci: A Bio-Inspired Multi-Agent Framework for the Evolution of Scientific Discoverycited by 3
- 2024Exploring the Integration of Large Language Models in Industrial Test Maintenance Processescited by 2
- 2024Seeker: Towards Exception Safety Code Generation with Intermediate Language Agents Frameworkcited by 2
- 2025VibeCodeHPC: An Agent-Based Iterative Prompting Auto-Tuner for HPC Code Generation Using LLMscited by 2
- 2025Explore-Construct-Filter: An Automated Framework for Rich and Reliable API Knowledge Graph Constructioncited by 0
3 more
- 2025Designing Empirical Studies on LLM-Based Code Generation: Towards a Reference Frameworkcited by 0
- 2026Prompt Coach: An Empirical Evaluation of an Agentic Tutor for Learning Prompt Engineering in Software Developmentcited by 0
- 2026Retrofitting Code Using LLMs to Support Exceptional Behaviorcited by 0
- 2026Retrofitting Code Using LLMs to Support Exceptional Behavior9 Sep 2026
- 2026Prompt Coach: An Empirical Evaluation of an Agentic Tutor for Learning Prompt Engineering in Software Development7 Jul 2026
- 2026EvoSci: A Bio-Inspired Multi-Agent Framework for the Evolution of Scientific Discovery20 May 2026
- 2025Agent READMEs: An Empirical Study of Context Files for Agentic Coding17 Nov 2025
- 2025Designing Empirical Studies on LLM-Based Code Generation: Towards a Reference Framework4 Oct 2025
- 2025VibeCodeHPC: An Agent-Based Iterative Prompting Auto-Tuner for HPC Code Generation Using LLMs26 Sep 2025
- 2025Explore-Construct-Filter: An Automated Framework for Rich and Reliable API Knowledge Graph Construction19 Feb 2025
- 2024Seeker: Towards Exception Safety Code Generation with Intermediate Language Agents Framework16 Dec 2024
- 2024A Survey on Data Synthesis and Augmentation for Large Language Models16 Oct 2024
- 2024Towards Exception Safety Code Generation with Intermediate Representation Agents Framework9 Oct 2024
- 2024Preference-Guided Refactored Tuning for Retrieval Augmented Code Generation24 Sep 2024
- 2024Agents in Software Engineering: Survey, Landscape, and Vision13 Sep 2024
3 more
- 2024Exploring the Integration of Large Language Models in Industrial Test Maintenance Processes10 Sep 2024
- 2024A Pair Programming Framework for Code Generation via Multi-Plan Exploration and Feedback-Driven Refinement8 Sep 2024
- 2024Large Language Model-Based Agents for Software Engineering: A Survey4 Sep 2024
- 2024Large Language Model-Based Agents for Software Engineering: A Surveycited by 178
- 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
- 2025Agent READMEs: An Empirical Study of Context Files for Agentic Codingcited by 23
- 2024Towards Exception Safety Code Generation with Intermediate Representation Agents Frameworkcited by 3
- 2026EvoSci: A Bio-Inspired Multi-Agent Framework for the Evolution of Scientific Discoverycited by 3
- 2024Seeker: Towards Exception Safety Code Generation with Intermediate Language Agents Frameworkcited by 2
- 2025VibeCodeHPC: An Agent-Based Iterative Prompting Auto-Tuner for HPC Code Generation Using LLMscited by 2
- 2026Prompt Coach: An Empirical Evaluation of an Agentic Tutor for Learning Prompt Engineering in Software Developmentcited by 0
- 2026Prompt Coach: An Empirical Evaluation of an Agentic Tutor for Learning Prompt Engineering in Software Development7 Jul 2026
- 2026EvoSci: A Bio-Inspired Multi-Agent Framework for the Evolution of Scientific Discovery20 May 2026
- 2025Agent READMEs: An Empirical Study of Context Files for Agentic Coding17 Nov 2025
- 2025VibeCodeHPC: An Agent-Based Iterative Prompting Auto-Tuner for HPC Code Generation Using LLMs26 Sep 2025
- 2024Seeker: Towards Exception Safety Code Generation with Intermediate Language Agents Framework16 Dec 2024
- 2024Towards Exception Safety Code Generation with Intermediate Representation Agents Framework9 Oct 2024
- 2024Agents in Software Engineering: Survey, Landscape, and Vision13 Sep 2024
- 2024Large Language Model-Based Agents for Software Engineering: A Survey4 Sep 2024
- 2024A Pair Programming Framework for Code Generation via Multi-Plan Exploration and Feedback-Driven Refinementcited by 21
- 2024Exploring the Integration of Large Language Models in Industrial Test Maintenance Processescited by 2
- 2025Explore-Construct-Filter: An Automated Framework for Rich and Reliable API Knowledge Graph Constructioncited by 0
- 2025Designing Empirical Studies on LLM-Based Code Generation: Towards a Reference Frameworkcited by 0
- 2026Retrofitting Code Using LLMs to Support Exceptional Behaviorcited by 0
- 2026Retrofitting Code Using LLMs to Support Exceptional Behavior9 Sep 2026
- 2025Designing Empirical Studies on LLM-Based Code Generation: Towards a Reference Framework4 Oct 2025
- 2025Explore-Construct-Filter: An Automated Framework for Rich and Reliable API Knowledge Graph Construction19 Feb 2025
- 2024Exploring the Integration of Large Language Models in Industrial Test Maintenance Processes10 Sep 2024
- 2024A Pair Programming Framework for Code Generation via Multi-Plan Exploration and Feedback-Driven Refinement8 Sep 2024