Abstract
This paper aims to extend the code generation capability of large language models (LLMs) to automatically manage comprehensive software requirements from given textual descriptions. Such requirements include both functional (i.e. achieving expected behavior for inputs) and non-functional (e.g., time/space performance, robustness, maintainability) requirements. However, textual descriptions can either express requirements verbosely or may even omit some of them. We introduce ARCHCODE, a novel framework that leverages in-context learning to organize requirements observed in descriptions and to extrapolate unexpressed requirements from them. ARCHCODE generates requirements from given descriptions, conditioning them to produce code snippets and test cases. Each test case is tailored to one of the requirements, allowing for the ranking of code snippets based on the compliance of their execution results with the requirements. Public benchmarks show that ARCHCODE enhances to satisfy functional requirements, significantly improving Pass@k scores. Furthermore, we introduce HumanEval-NFR, the first evaluation of LLMs’ non-functional requirements in code generation, demonstrating ARCHCODE’s superiority over baseline methods.
Introduction
While Large Language Models (LLMs) have become remarkably good at writing code, they often suffer from "tunnel vision." Most current models focus strictly on Functional Requirements (FRs)—the basic logic of mapping inputs to expected outputs. However, real-world software engineering is governed by Non-Functional Requirements (NFRs): efficiency, robustness against invalid inputs, and maintainability. Textual problem descriptions in benchmarks are often verbose or omit these constraints entirely. Consequently, LLMs might produce code that "works" on basic tests but fails in production due to poor time complexity, lack of error handling, or high technical debt.
Methods
ARCHCODE is a framework that leverages In-Context Learning (ICL) to transform vague problem descriptions into structured software specifications. The process follows three main steps:
- Requirement Delineation: Using a few-shot approach, the model takes a problem description and generates a detailed list of requirements. This includes reformulating explicit FRs and extrapolating implicit NFRs (e.g., "this should handle empty lists" or "this must run in $O(n \log n)$ time") based on the model's internal knowledge.
- Requirements-Aware Generation: The model generates multiple code candidates and test cases, both conditioned on the specific requirements identified in step one.
- Targeted Filtering: Unlike existing methods that generate hundreds of random test cases, ARCHCODE generates a small set of test cases tailored to specific requirements (e.g., one test for an edge case, one for a robustness check). Code candidates are then ranked and filtered based on how many of these specific requirements they satisfy.
Datasets and Evaluation
The researchers evaluated ARCHCODE using several benchmarks:
- HumanEval: The standard benchmark for functional correctness in Python.
- CodeContests: A difficult benchmark featuring competitive programming problems requiring complex algorithmic reasoning.
- HumanEval-NFR: A primary contribution of this paper, and the first benchmark specifically designed to evaluate LLMs on four NFR categories: Time Performance, Robustness, Maintainability, and Reliability.
Key Results
ARCHCODE, using GPT-3.5-Turbo as a backbone, achieved results that often surpassed much larger models:
- Outperforming GPT-4: On HumanEval, ARCHCODE reached a 86.36% Pass@1 score, beating GPT-4's 81.55%.
- New SOTA on CodeContests: It achieved 16.52% Pass@1, a significant jump over GPT-4's 6.07%.
- Efficiency: ARCHCODE achieved these results while generating 50x fewer test cases than competing filtering methods like MPSC or CODET, making it much more computationally efficient.
- NFR Mastery: On the new HumanEval-NFR benchmark, ARCHCODE improved the "All NFR" Pass@1 score from a baseline of 2.62% to 25.19%.
Discussion and Insights
The most striking insight is that LLMs already possess the parametric knowledge of what constitutes "good code" (e.g., input validation), but they do not always apply it unless prompted to define it as a requirement first. Furthermore, the paper reveals a "Robustness Gap," showing that handling invalid/unexpected inputs is the hardest NFR for current models to satisfy. The authors also noted inherent trade-offs; for instance, adding extensive error handling to improve robustness can slightly decrease maintainability scores by increasing Cyclomatic Complexity.
Conclusion
ARCHCODE demonstrates that explicitly incorporating software requirements into the LLM generation pipeline leads to more robust, efficient, and maintainable code. While the framework is sensitive to the initial requirement delineation step, it proves that quality-targeted testing is significantly more effective than high-volume random testing. Future work will look to expand the scope to cover more complex architectural requirements and multi-file software projects.
Summary updated