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

Institutions

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
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Preconditions and Postconditions as Design Constraints for LLM Code Generation

Omar Ochoa, Alexandra Davidoff, L. H. Newcomb
IEEE Access
Natural Language Processing Techniques
article

Preconditions and Postconditions as Design Constraints for LLM Code Generation

Omar Ochoa, Alexandra Davidoff, L. H. Newcomb
article en

Abstract

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.

IEEE AccessVol. 13
Embry–Riddle Aeronautical University (US)
Openalex Percentile: Top 84%
Natural Language Processing Techniques
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.