Large language models are widely used for code generation, yet they rely on an implicit assumption that the task descriptions are sufficiently detailed and well-formed. However, in practice, users may provide defective descriptions, which can have a strong effect on code correctness. To address this issue, we develop SpecValidator, a lightweight classifier based on a small model that has been parameter-efficiently finetuned, to automatically detect task description defects. We evaluate SpecValidator on three types of defects, Lexical Vagueness, Under-Specification and Syntax-Formatting on 3 benchmarks with task descriptions of varying structure and complexity. Our results show that SpecValidator achieves defect detection of F1 = 0.804 and MCC = 0.745, significantly outperforming GPT-5-mini (F1 = 0.469 and MCC = 0.281) and Claude Sonnet 4 (F1 = 0.518 and MCC = 0.359). Perhaps more importantly, our analysis indicates that SpecValidator can generalize to unseen issues and detect unknown Under-Specification defects in the original (real) descriptions of the benchmarks used. Our results also show that the robustness of LLMs in task description defects depends primarily on the type of defect and the characteristics of the task description, rather than the capacity of the model, with Under-Specification defects being the most severe. We further found that benchmarks with richer contextual grounding, such as LiveCodeBench, exhibit substantially greater resilience, highlighting the importance of structured task descriptions for reliable LLM-based code generation.
翻译:大型语言模型被广泛用于代码生成,但它们依赖于一个隐含假设:任务描述足够详细且格式良好。然而,在实践中,用户可能提供有缺陷的描述,这会对代码正确性产生强烈影响。为解决此问题,我们开发了SpecValidator,一个基于参数高效微调的小模型的轻量级分类器,用于自动检测任务描述缺陷。我们在三种缺陷类型(词汇模糊性、欠规格说明和语法格式)上,对三个具有不同结构和复杂度的任务描述基准进行了评估。结果表明,SpecValidator在缺陷检测中实现了F1=0.804和MCC=0.745,显著优于GPT-5-mini(F1=0.469,MCC=0.281)和Claude Sonnet 4(F1=0.518,MCC=0.359)。或许更重要的是,我们的分析表明SpecValidator能够泛化到未见问题,并检测到所用基准原始(真实)描述中的未知欠规格说明缺陷。我们的结果还表明,LLM在任务描述缺陷中的鲁棒性主要取决于缺陷类型和任务描述的特征,而非模型容量,其中欠规格说明缺陷最为严重。我们进一步发现,具有更丰富上下文基础的基准(如LiveCodeBench)表现出显著更强的韧性,突显了结构化任务描述对于可靠的基于LLM的代码生成的重要性。