Beyond Basic Specifications? A Systematic Study of Logical Constructs in LLM-based Specification Generation

Zehan Chen, Long Zhang, Zhiwei Zhang, JingJing Zhang, Ruoyu Zhou, Yulong Shen, JianFeng Ma, Lin YangarXiv 2026

TL;DR

This paper presents the first systematic study on using Large Language Models (LLMs) to generate advanced logical constructs (like predicates, lemmas, and axioms) for formal program verification. The authors show that modern LLMs can successfully generate these complex abstractions, and that combining them synergistically with basic annotations significantly boosts verification success and robustness without substantial computational overhead.

What Problem Does This Paper Address?

Formal program verification uses mathematical specifications to guarantee that software behaves correctly. Recently, researchers have used LLMs in a "guess-and-verify" loop to automatically generate these specifications (e.g., using the ANSI/ISO C Specification Language, or ACSL).

However, prior work has been stuck in the "shallow end," only generating basic syntactic constructs like requires, ensures, and simple loop invariant clauses. While these work for basic code, they fail completely when a program relies on complex mathematical concepts (like recursive digit summation or sorting algorithms). Human verification engineers solve this by writing high-level logical abstractions—such as helper predicates, lemmas, and axioms. Until now, no one had systematically studied whether LLMs can reliably generate these advanced logical constructs, or how they impact the efficiency and stability of automated verification tools.

Methods

The authors built a comprehensive evaluation framework to test how different types of syntactic constructs affect the verification process.

Fig. 2. Evaluation Framework.

They defined four distinct syntactic configurations for the LLMs to follow:

  1. Config-Basic (CB): The baseline. The LLM is restricted to basic constructs (requires, ensures, assigns, etc.).
  2. Config-Verifiable (CV): Extends the baseline by forcing the LLM to generate strictly verifiable logical constructs (predicate, logic, lemma) that the verification tool must explicitly prove.
  3. Config-Axiom (CA): Extends the baseline by introducing axiom constructs—logical rules assumed to be true without explicit proof by the solver.
  4. Config-Full (CF): Unconstrained. The LLM can freely mix basic and advanced constructs.

The framework passes the generated code and specifications to a formal verification tool (Frama-C). If verification fails, it enters a refinement phase using one of two paradigms:

  • Deletion Paradigm: Erroneous specifications are statically analyzed and simply stripped away.
  • Modification Paradigm: The LLM receives error feedback from the solver and attempts to repair the specifications in a new iteration.

The authors evaluated these configurations across six state-of-the-art LLMs, including GPT-4o, GPT-5, Gemini-2.5-Pro, Qwen2.5-Coder-32B, and Llama-3.1-70B.

Datasets

The study utilized the frama-c-problems dataset, a standard benchmark suite for ACSL-based specification generation. To ensure rigorous testing, the authors cleaned and refined the dataset by enriching the calling contexts of target functions (forcing more complete specifications) and removing duplicate or semantically meaningless examples. The final refined dataset contains 49 representative C program instances covering arithmetic, pointer manipulation, array operations, and complex algorithms.

Key Insights and Ideas

  • LLMs Have the Capability: Modern, high-capability LLMs are surprisingly adept at adhering to complex prompt constraints and generating syntactically valid logical constructs.
  • Strategic Omission: Interestingly, highly capable models sometimes deliberately violate prompt constraints by omitting complex axioms if they realize a program can be verified using simpler, safer constructs.
  • Complementarity over Hierarchy: Advanced logical constructs do not simply replace basic syntax; they complement it. Venn diagram analysis revealed that different configurations verify entirely different subsets of programs. The best results occur when basic and logical constructs are used together (Config-Full), giving the model a larger strategic space to solve the proof.
  • Refinement Trade-offs: The Deletion paradigm is highly efficient in terms of runtime but cannot recover missing information. The Modification paradigm acts as a powerful corrector, significantly boosting verification success rates, though it doubles the end-to-end execution time due to repeated LLM API calls.

Key Results

  • High Compliance: Under the Config-Verifiable setup, models like GPT-4o, GPT-5, and Qwen2.5-Coder achieved near-perfect Correct Syntactic Construct Compliance Ratios (CSCCR), frequently hitting 99% to 100%.
Fig. 3. The CSCCR and Sample Distribution of Two Logical Construct Configurations.
  • Verification Boost: Integrating multiple syntactic constructs (Config-Full) yielded the strongest verification capability. On average, Config-Full verified 16.35% more programs than the basic baseline under the deletion paradigm, and 5.35% more under the modification paradigm.
  • Stability Gains: While introducing axioms (Config-Axiom) on its own caused verification instability due to the solver's expanded search space, combining basic syntax with verifiable logical constructs (Config-Full) effectively mitigated this randomness in high-capability models.

Limitations and Future Work

The primary limitation acknowledged by the authors is the dataset size (49 programs), which, while standard and algorithmically dense for formal verification research, is small compared to typical software engineering benchmarks. Additionally, the study focuses exclusively on C/ACSL.

For future work, the authors point toward constructing larger-scale formal verification datasets and exploring how these logical abstraction capabilities generalize to other popular specification languages like JML (for Java) and Dafny.

Summary updated

BibTeX
@misc{chen2026beyond,
  author = {Zehan Chen and Long Zhang and Zhiwei Zhang and JingJing Zhang and Ruoyu Zhou and Yulong Shen and JianFeng Ma and Lin Yang},
  title = {{Beyond Basic Specifications? A Systematic Study of Logical Constructs in LLM-based Specification Generation}},
  year = {2026},
  eprint = {2602.00715},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.00715},
}
Figure