PulseExploreJournal ClubDebatesTrendingResearchersJournals
Instagram
HomeExploreJournal ClubTrending
Synapse
⌘+K
Synapse
January 1, 2025IEEE Access1 citationsOpen Access

Preconditions and Postconditions as Design Constraints for LLM Code Generation

View Full Paper
LNL. H. NewcombADAlexandra DavidoffOOOmar Ochoa

Key Points

  • This work investigates the effects of preconditions and postconditions on class-level code generation using LLMs.
  • Evaluated six state-of-the-art LLMs generating complete software implementations from class-level specifications.
  • Measured initial generation accuracy using the pass@k metric, focusing on Python and C++.
  • Analyzed the impact of incorporating design constraints on models with varying parameter sizes.
  • Incorporating preconditions and postconditions significantly improved accuracy, particularly in Python and C++.
  • Models with fewer parameters showed the most pronounced benefits in code generation accuracy.
  • Initial generation accuracy was quantitatively measured using the pass@k metric.

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.

Ask AI
Helpful
Bookmark
Share
View Full Paper

Cite This Study

Newcomb et al. (2025) studied this question.

synapsesocial.com/papers/6a15510aeecc40546481f625https://doi.org/10.1109/access.2025.3625819
Ask AI
Helpful
Bookmark
Share
View Full Paper