Skip to content

Spec-Harness: Measuring and Improving Behavioral Adequacy of LLM-Synthesized Formal Specifications

Mar 2026 · 3 citations · 44 references
Computer Science

TL;DR

Comparisons of classical and prompt-based JML synthesis approaches are compared, and it is found that prompt optimization through verification feedback raises pass rates but reaches a clear ceiling, and Spec-Harness is introduced, a framework that measures the behavioral adequacy of a specification along four dimensions of precondition and postcondition correctness and completeness.

Abstract

Formal specifications play a central role in ensuring software reliability, yet automatically synthesizing high-quality specifications remains difficult and often requires domain expertise. Recent work has applied large language models to generate specifications in the Java Modeling Language (JML), reporting high verifier pass rates. But passing a verifier only confirms that an implementation is consistent with a specification, not that the specification is meaningful. A trivial postcondition such as ensures true satisfies any verifier while saying nothing about the code. How much behavior, then, does a verifier-accepted specification actually capture? In this work, we first compare classical and prompt-based JML synthesis approaches under a unified setup, and find that prompt optimization through verification feedback raises pass rates but reaches a clear ceiling. We then introduce Spec-Harness, a framework that measures the behavioral adequacy of a specification along four dimensions of precondition and postcondition correctness and completeness, using Hoare-triple based symbolic verification and input/output mutation. Spec-Harness reveals that many verifier-accepted specifications, including optimized ones, are behaviorally weak, over- or under-constraining inputs and outputs in ways the verifier cannot see. Finally, we show that Spec-Harness works as a feedback signal that helps coding agents synthesize specifications with higher behavioral adequacy, including general-purpose agents such as Codex CLI and Claude Code, as well as VeriAct, a JML-specialized agent we build for this study.

View source

Similar papers

Preprint Oct 2026

Are LLM-Generated Formal Specifications Faithful to Their Requirements? A Study on Bimodal Formal Specification Generation

Formal specification generation is a critical step towards formal verification and correctness assurance of software. Recently, large language models have been widely adopted in automatic generation of formal specifications. However, existing LLM-based specification generation approaches often assume that the input pro...

Wen-Han Wang, Shi-Ming Chen, Ze-Yu Sun et al. · 0 citations
Open access Sep 2026

From Formal Specifications to Simulations: Generating Executable Hardware Models for Early Validation

This work presents a model-driven code generator transforming static USF specifications into executable software simulations that abstract cycle-accurate timing and helps shorten validation cycles, ultimately reducing the risk of costly design flaws.

Robert Kunzelmann, Raphael Kunz, Stephanie Ecker et al. · 0 citations
Book Open access Oct 2026

Accurate Specification Recovery for Effective Test Generation

This dissertation aims to make specification recovery from imperfect code accurate, evidence-driven, and uncertainty-aware, so that it consistently yields effective bug-finding tests.

Jun-Da Zhao · 0 citations
#artificial intelligence Preprint Oct 2026

claimcheck: Measuring and Improving Specification Faithfulness

Formal verification proves that a program satisfies its specification, but says nothing about whether the specification captures what the author meant. As LLMs increasingly write both code and specifications, a gap between the author's natural-language requirement and the specification becomes a live risk. A machine-ch...

Martín Amster, One An, Holly Baker et al. · 0 citations

Self-Spec Verifiable Code Generation

VeriCodeBench is introduced, a benchmark for self-spec verifiable code generation, where the LLM relies solely on its own generated specification and code throughout the entire process, and CodeNova is introduced to enhance the capabilities of LLMs in self-spec verifiable code generation.

Jia-Ru Qian, Yihong Dong, Yong-Ming Li et al. · 0 citations
Preprint Oct 2026

From Natural Language to Verified C: Verification-Guided Generation with ACSL Specifications

AI-assisted code generation amplifies the demand for automated formal verification. Generated programs must not only be executable but also accompanied by machine-checkable evidence of correctness. Existing approaches can synthesize functionally plausible code or plausible-looking specifications from natural-language p...

Zian Wang, Qin Li, Wei-Song Sun et al. · 0 citations

Related blog posts

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.