Preconditions and Postconditions as Design Constraints for LLM Code Generation
Large Language Models (LLMs) have significantly advanced automated code generation, but current methods predominantly rely on natural language descriptions during prompting. This approach encounters challenges when handling complex, class-level software generation tasks due to inherent ambiguity and under-specification. On the other hand, few studies have investigated how formal software engineering constraints, such as explicit preconditions and postconditions as part of the Design-by-Contract paradigm, influence class-level generation tasks. This work addresses this gap through a structured evaluation of six state-of-the-art LLMs generating complete software implementations of a medium complexity system from systematically designed class-level specifications. Results demonstrate that incorporating explicit design constraints during prompting significantly boosts initial generation accuracy (measured via the pass@k metric), particularly in Python but also in C++. Models with fewer parameters saw especially pronounced benefits. These findings suggest integrating structured software engineering constraints and design principles into LLM-based code generation workflows to enhance accuracy and maintainability in automated software projects.
Authors
- Omar Ochoa (ORCID: https://orcid.org/0000-0002-2072-5610)
- Alexandra Davidoff (ORCID: https://orcid.org/0009-0003-1941-6495)
- L. H. Newcomb
Institutions
- Embry–Riddle Aeronautical University (US)
Publication Details
- Journal
- IEEE Access
- Published
- 2025-01-01
- DOI
- https://doi.org/10.1109/access.2025.3625819
- Primary Topic
- Natural Language Processing Techniques
- Type
- article
- Field-Weighted Citation Impact
- 0.00