Spec-Harness: Measuring and Improving Behavioral Adequacy of LLM-Synthesized Formal Specifications
cs.SE, cs.AI
Submitted: 2026-03-31
Updated: 2026-09-08
License: http://creativecommons.org/licenses/by/4.0/
The gist: Formal specifications play a central role in ensuring software reliability, yet automatically synthesizing high-quality specifications remains difficult and often requires domain expertise.
Terminology
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.
Sources
- Program Synthesis with Large Language Models
- Reasoning Runtime Behavior of a Program with LLM: How Far Are We?
- Evaluating Large Language Models Trained on Code
- DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligence
- Beyond Code Generation: Assessing Code LLM Maturity with Postconditions
- Qwen2.5-Coder Technical Report
- DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines
- Intent Formalization: A Grand Challenge for Reliable Coding in the Age of AI Agents
- SpecEval: Evaluating Code Comprehension in Large Language Models via Program Specifications
- Code Llama: Open Foundation Models for Code
- A Comparative Study of DSPy Teleprompter Algorithms for Aligning Large Language Models Evaluation Metrics to Human Evaluation
- Re:Form -- Reducing Human Annotations in Scalable Formal Software Verification with RL in LLMs: A Preliminary Study on Dafny
Related papers
- Falsification-Based Verification of LLM-Generated Optimization Models: Sound Test Batteries and Their Detection Limits
- GitSkills: A Dataset of Agent Skills on GitHub
- SABER: Benchmarking Operational Safety of LLM Coding Agents in Stateful Project Workspaces
- PackMonitor: Enabling Zero Package Hallucinations Through Decoding-Time Monitoring
- IntentCoding: Amplifying User Intent in Code Generation
- Incentives and Outcomes in Bug Bounties