Abstract
Large Language Models (LLMs) have demonstrated remarkable proficiency in code generation, yet they frequently struggle with complex algorithmic logic on the first attempt. Traditional automated debugging techniques typically rely on iterative, code-level modifications, which often fail to resolve deep structural flaws. This paper introduces NL-DEBUGGING, a novel framework that utilizes natural language (NL) as an intermediate representation for the debugging process. By translating buggy code into a semantic "sketch," refining the logic in plain English based on execution feedback, and then regenerating the code, NL-DEBUGGING shifts the repair process from the syntactic space to the semantic space. Experimental results on competitive programming benchmarks demonstrate that this approach significantly outperforms existing code-level debugging methods, particularly on high-difficulty tasks.
Introduction
The rise of Large Language Models has transformed software development, but the "generate-and-test" cycle remains bottlenecked by the model's ability to fix its own mistakes. Current state-of-the-art debugging methods, such as Reflexion or Self-Debugging, primarily operate by prompting the model to edit the source code directly. While effective for fixing syntax errors or minor typos, these methods often fall into "local optima," where the model makes superficial changes (like adjusting an index by +/- 1) without addressing the underlying algorithmic failure.
This research explores a fundamental shift: using natural language as a bridge. By forcing the model to explain and correct its logic in English before writing a single line of code, can we unlock more profound structural fixes? The authors propose NL-DEBUGGING to test this hypothesis, investigating which natural language formats best facilitate logical repair and why this intermediate step provides a competitive advantage.
The NL-DEBUGGING Framework
NL-DEBUGGING is an iterative, three-stage framework designed to decouple logical reasoning from syntactic implementation:
- Backtranslation: The process begins by taking the buggy code and translating it into a natural language representation. The authors evaluated three distinct formats: Pseudocode (structured, code-like syntax), Key Points (high-level abstract bullets), and Sketches (detailed, structural English descriptions of the algorithm).
- Natural Language Refinement: The buggy code is executed against a set of public test cases. The LLM is then provided with the execution feedback (input, expected output, and actual output) alongside the initial NL representation. The model is tasked with identifying the root cause of the failure and updating the NL representation to reflect a corrected logic.
- Regeneration: Finally, the refined NL representation is translated back into executable code.
This cycle repeats—incorporating new execution feedback at each step—until the code passes all visible tests or reaches a predefined iteration limit (typically 10).
Experimental Setup
The framework was rigorously evaluated using two prominent competitive programming benchmarks:
- APPS: 300 problems spanning Introductory, Interview, and Competition difficulty levels.
- Codeforces: 300 problems across three rating tiers (1200, 1500, and 1800).
Performance was measured using Pass Rate and Pass@1 metrics against hidden private test cases. The authors tested the framework across several state-of-the-art models, including GPT-4o-mini, Claude-3.5-Sonnet, and DeepSeek-Coder-V2-Lite.
Key Insights: Why NL Matters
The Superiority of "Sketches"
The research found that the Sketch format is the most effective intermediate representation. Unlike Pseudocode, which can be too rigid and closely tied to the original buggy syntax, or Key Points, which may be too vague, Sketches provide a structural roadmap that is flexible enough to allow for major logical rewrites while remaining detailed enough to guide the regeneration phase.
Expanding the Modification Space
A critical finding is that NL-DEBUGGING encourages a much larger "modification space." Traditional code-level debugging often results in minimal changes to the program's Abstract Syntax Tree (AST). In contrast, NL-DEBUGGING leads to significantly higher AST Edit Distances and substantial changes in Control Flow. This suggests that by operating in the semantic space, the model is empowered to perform "brain transplants" on the code rather than just minor "cosmetic surgery."
Scalability and Logic
Unlike traditional methods that often plateau after 3-5 debugging attempts, NL-DEBUGGING shows continued improvement as the number of iterations increases. This scalability stems from the fact that the performance gains are driven by successfully fixing the NL sketch; once the English logic is sound, the resulting code is much more likely to be correct.
Results
NL-DEBUGGING consistently outperformed strong baselines, including Self-Edit, LDB, and Reflexion. The gains were most pronounced on high-difficulty problems. For instance, using Claude-3.5-Sonnet on the APPS Competition dataset, the pass rate improved from a baseline of 45.33% to 59.67%. Similarly, GPT-4o-mini saw an improvement from 34.67% to 44.17%. These results indicate that the more complex the logic required, the more beneficial the natural language intermediate step becomes.
Conclusion and Future Work
NL-DEBUGGING demonstrates that natural language is a powerful tool for bridging the gap between execution failure and logical correction. By shifting the focus from code syntax to algorithmic intent, the framework enables LLMs to solve significantly more complex problems.
Future research directions include integrating Tree Search algorithms (such as MCTS) to explore multiple logical paths in the NL space simultaneously. Additionally, the authors suggest that a hybrid approach—combining high-level NL debugging for logic with low-level code debugging for syntax—could provide the most robust solution for real-world software engineering challenges, such as those found in the SWE-bench dataset.
Summary updated