NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

ChatCoder: Chat-based Refine Requirement Improves LLMs' Code Generation

Zejun Wang, Jia Li, Ge Li, Zhi JinarXiv 2023

Abstract

Large language models have shown good performances in generating code to meet human requirements. However, human requirements expressed in natural languages can be vague, incomplete, and ambiguous, leading large language models to misunderstand human requirements and make mistakes. Worse, it is difficult for a human user to refine the requirement. To help human users refine their requirements and improve large language models' code generation performances, we propose ChatCoder: a method to refine the requirements via chatting with large language models. We design a chat scheme in which the large language models will guide the human users to refine their expression of requirements to be more precise, unambiguous, and complete than before. Experiments show that ChatCoder has improved existing large language models' performance by a large margin. Besides, ChatCoder has the advantage over refine-based methods and LLMs fine-tuned via human response.

Introduction: The Intent Gap in Code Generation

The primary hurdle in automated code generation is the "intent gap"—the discrepancy between what a user wants and what they actually type. Human requirements are naturally messy, often suffering from vagueness or ambiguity. For instance, a request for the "largest negative number" in a list is fundamentally ambiguous: does it refer to the value closest to zero (e.g., -1) or the value with the largest absolute magnitude (e.g., -99)?

Ambiguity in natural language requirements and the refinement process.

When faced with such ambiguity, Large Language Models (LLMs) typically make a "best guess." If this guess is incorrect, the resulting code is useless, regardless of its syntactic correctness. ChatCoder addresses this by creating a structured "handshake" between the human and the model to refine these requirements before code generation begins.

The ChatCoder Framework

ChatCoder introduces a two-phase dialogue framework designed to mimic the interaction between a software customer and a professional developer.

The two-phase ChatCoder dialogue framework for requirement refinement.

Phase 1: Paraphrase and Extend

Inspired by the IEEE Standard for Software Requirements Specifications (SRS), the LLM analyzes the user's request from six specific software engineering angles:

  • Key Concepts: Defining the objects and actions involved.
  • Method Purpose: Describing the transformation of inputs to outputs.
  • Input/Output Requirements: Clarifying types, formats, and boundaries.
  • Edge Cases: Identifying potential "gotchas" like empty lists.
  • Exceptions and Errors: Planning for failure states.

The human user then reviews this analysis, correcting any misconceptions with minimal effort.

Phase 2: Going-deep and Loop-back

In the second phase, the LLM asks up to five clarifying questions about its remaining confusion. The user provides brief answers. If these questions reveal a fundamental misunderstanding, the user can "loop back" to correct the Phase 1 specifications. The final, high-detail requirement is then used to generate the code.

Experimental Evaluation

The researchers evaluated ChatCoder using two benchmarks: Sanitized-MBPP (257 entry-level tasks) and HumanEval (164 complex problems).

Key Results

The framework yielded significant quantitative improvements:

  • GPT-3.5-turbo on MBPP: The pass@1 rate increased from 57.04% to 71.25%.
  • GPT-4 on HumanEval: Performance improved from 81.10% to 90.24%.

Insights

  • Human-in-the-Loop is Essential: Asking an LLM to refine requirements without human intervention (Auto-Refine) actually decreased performance, as the model tended to hallucinate details for its own wrong assumptions.
  • High ROI: While the final requirements are verbose, the human labor required is minimal—averaging only about 10 tokens of correction per task.
  • Structured Analysis: Forcing the model to consider edge cases and exceptions before coding surfaces bugs that would otherwise be ignored in zero-shot generation.

Conclusion and Future Work

ChatCoder demonstrates that structured, multi-round dialogue can bridge the intent gap in code generation. While effective, the resulting requirements can be verbose, leading to potential "long text" confusion for LLMs. Future research will focus on requirement compression to maintain precision while reducing cognitive load for human reviewers. Additionally, further study is needed to assess how non-technical users interact with such structured technical specifications.

Summary updated

BibTeX
@misc{wang2023chatcoder,
  author = {Zejun Wang and Jia Li and Ge Li and Zhi Jin},
  title = {{ChatCoder: Chat-based Refine Requirement Improves LLMs' Code Generation}},
  year = {2023},
  eprint = {2311.00272},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.00272},
}
Figure