Abstract
Large Language Models (LLMs) like ChatGPT and GitHub Copilot have significantly advanced automated code generation. However, these models often exhibit a lack of robustness, where minor prompt variations lead to inconsistent or incorrect outputs. This paper introduces COCO (COncretizing instructions), a novel testing technique that exposes this brittleness. COCO extracts structural features from a model's initial output and incorporates them back into the original prompt as explicit requirements. By testing whether models can maintain logic when asked to follow constraints they previously satisfied naturally, COCO identifies significant semantic inconsistencies. Evaluation on HumanEval and APPS benchmarks shows that COCO detects substantially more bugs than existing paraphrasing-based methods and can be used to improve model robustness through fine-tuning.
Introduction
While LLMs have revolutionized automated code generation, they suffer from a significant "robustness gap." Ideally, if a user asks a model for a specific function in two slightly different ways, the resulting code should remain semantically identical. In practice, minor tweaks to a natural language prompt often lead to wildly different—and frequently incorrect—code logic.
Existing methods for testing this robustness typically rely on general Natural Language Processing (NLP) techniques like paraphrasing or back-translation. However, these methods often fail to respect the unique structure of source code, frequently mangling programming-specific tokens like variable names or library calls. COCO (COncretizing instructions) addresses this by using the model's own output to generate more specific, structured instructions that test the stability of its reasoning.
Methodology
The core innovation of COCO is a feedback loop approach called Concretization. Instead of arbitrarily changing the words of a prompt, COCO makes the prompt more specific based on the features the model already implemented in its first attempt.
As illustrated in the workflow above, the process follows three main steps:
- Code Feature Extraction: The system takes the code generated from an original prompt and parses it into an Abstract Syntax Tree (AST). It extracts features across six levels: dependencies (imports), classes, methods, statements (loops/conditionals), expressions, and variables.
- Concretized Instruction Construction: COCO transforms these features into natural language using predefined templates. For example, if the initial code used a
forloop, COCO appends the requirement: "The code is implemented with a for loop." - Consistency Checking: The model is then prompted with this new, "concretized" instruction. COCO checks for three types of inconsistencies: syntax errors, test execution differences (comparing output against unit tests), and feature disappearance (where the model fails to include the requested feature).
The "Already Satisfied" Paradox
A key insight of this research is that if a model is truly robust, adding a requirement that the model has already met should not change the semantic output. If a model generates a loop naturally but fails when explicitly asked to "use a loop," it indicates a deep-seated instability in the model's underlying logic.
In the example above, the original code correctly calculates a product of signs. When the instruction is concretized to explicitly require a for loop (which the model used anyway), the newly generated code introduces a bug by multiplying the product by the value i instead of its sign, dropping the pass rate from 100% to 70%.
Evaluation and Results
The researchers evaluated COCO using the HumanEval (164 problems) and APPS (10,000 problems) benchmarks across eight models, including ChatGPT, GitHub Copilot, CodeGen, and InCoder.
COCO significantly outperformed existing state-of-the-art robustness testing methods:
- Detection Power: COCO detected 466.66% more inconsistencies than PEGASUS (a paraphrasing tool) and 104.02% more than Translation-Pivoting.
- Unique Bug Discovery: Nearly half (45.43%) of the robustness issues identified by COCO were unique and could not be detected by other methods.
- Robustness Boosting: By fine-tuning models on the concretized instructions generated by COCO, the authors reduced robustness inconsistencies by 18.35% to 53.91% without degrading general performance.
- Efficiency: The system is highly performant, with concretized instruction generation taking an average of only 1.59 milliseconds.
Conclusion
COCO demonstrates that current code-generation models are more brittle than their high pass rates might suggest. By leveraging the semantic structure of code rather than relying on generic NLP paraphrasing, COCO provides a more effective way to audit and improve the reliability of AI-driven development tools. Future work will involve expanding the tool to support languages beyond Python and exploring more advanced sampling algorithms to navigate the vast search space of potential code features.
Summary updated