Code- SPA : Style Preference Alignment to Large Language Models for Effective and Robust Code Debugging (2025)

Abstract: Large language models (LLMs) have demonstrated impressive capabilities in coding tasks like code generation and debugging. However, code from real-world users is often poorly styled, containing various types of noise, such as structural inconsistencies, stylistic deviations and flawed test cases. To investigate this, we first simulate poorly styled code using eight types of code perturbations, and then demonstrate that the debugging performance of existing LLM-based methods significantly declines on such inputs. Furthermore, to address this, we propose a novel debugging method called Code-SPA, which aligns noisy code with the well-structured style familiar to LLMs, mitigating the impact of stylistic inconsistencies. Specifically, Code-SPA extracts the model’s preferred coding style from a reference snippet, then adjusts the input code by Concrete Syntax Tree (CST)-based transformations and LLM-assisted refinements before debugging. By aligning the code style preference, Code-SPA enhances the debugging performance of both code-specific and general-purpose LLMs on both poorly and well-styled code across the HumanEval, MBPP and EvalPlus datasets.

## introduction in recent years, large language models (llms) have achieved great success in programming tasks, such as @xcite , @xcite , and @xcite . these models have significantly accelerated the productivity of software developers by automating complex coding tasks, such as code generation @xcite @xcite , debugging @xcite , and translation @xcite . despite their impressive capabilities, llms still face significant robustness challenges @xcite @xcite @xcite def ispalindrome(strs): ## related work code large language models early code large language models, such as codex @xcite and codegen @xcite , were among the first to demonstrate the potential of llms in code generation, some models also unify code representation and generation @xcite @xcite . recent advancements in llms have given rise to specialized models for code generation and understanding. models such as @xcite , qwen-coder @xcite and gpt-4 (ope-nai et al., 2024c) have been explicitly designed to handle coding-related tasks. besides, reasoning models like @xcite and @xcite , have also demonstrated impressive coding performance due to their long reasoning ability. debugging with llms large language models have shown significant potential in enhancing debugging tasks by leveraging interpreter outputs @xcite , integrating with external debugging tools @xcite , and decomposing complex debugging problems into smaller, more manageable steps @xcite @xcite @xcite . beyond proposing debugging methods, recent studies have also investigated the effectiveness and limitations of llms in code repair @xcite @xcite . ## conclusion in this work, we investigated the impact of stylistic variations on llm debugging performance, highlighting the challenges llms face when dealing with diverse coding styles. through a comprehensive set of perturbation experiments, including single and multiple perturbations across various base models and datasets, we demonstrated the significant influence of stylistic factors on debugging accuracy. to address these challenges, we proposed code-spa, a novel approach designed to enhance llm robustness to stylistic variations. our experiments demonstrate that code-spa effectively mitigates the negative impact of perturbations, achieving superior or comparable performance to baselines across all evaluated scenarios. this demonstrates the effectiveness of style alignment in enhancing llm debugging capabilities.