How Specification Explicitness Shapes Failure in LLM-Generated Code
Elmira Onagh, Maleknaz Nayebi
Abstract
When LLMs turn requirements into code, every underspecified constraint becomes behavior that the model must decide during generation. We test when specifications move beyond structure and begin to control generated behavior. In a controlled experiment, 72 participants implemented and revised Python tasks with an LLM under three levels of specification explicitness. The results show a clear break between lightweight structure and explicit behavioral obligations. Lightweight structure reduced hidden-test failures by only 8.7%. Requiring participants to specify constraints, invariants, negative requirements, edge cases, tie-breaking rules, and exception handling cut failures by 47.2% and reduced the number of distinct failure modes by 20.5%. The largest drops were in failure modes tied to implicit obligations. Invariant violations fell by 66.1%, and unsupported assumptions fell by 59.5%. After a requirement change, specifications with explicit behavioral obligations produced regressions in more submissions, but each affected submission lost less previously correct behavior. Explicit specifications also changed how developers judged generated code. Without explicit obligations, participants overestimated generated-code correctness by about 23 percentage points. With explicit obligations, they produced better code but judged it more cautiously. Thus, the lesson is sharper than "better specifications help." Lightweight structure barely helped, while explicit behavioral obligations nearly halved failures, made regressions shallower, and improved calibration.
Create a lesson
Related papers
Static Analysis Guidance for Secure LLM Code Generation
Shared title terminology · Daniele Lunghi, Alberick Euraste Djiré, Zacharie Chenail-Larcher et al.
Option-GRPO: Hierarchical RL Against AI Slop in Code Generation for Unseen SDKs
Shared title terminology · Prashank Kadam
Systematic Mapping Protocol. Generative AI-Augmented Requirements Engineering: A Systematic Mapping Study of Practices, Specifications, and Reuse in Software Development
Shared title terminology · Fernando Pinciroli
Beyond Source Code: Evaluating Natural Language Specifications for LLM-Based C-to-Rust Translation
Shared title terminology · Biruk Tadesse, Lawrence Arkoh, Marcelo D'Amorim et al.
Eliciting and Mitigating Specification Satisficing in Coding Agents
Shared title terminology · Ruixin Wang, Tianyi Zhang
Spec-Driven PBT: Deriving Semantic Invariants from Code Specifications for Agentic Property-based Testing
Shared title terminology · Aditya Shukla, Kartik Gupta, Ali Alavi et al.