cs.SEApr 14, 2026

CodeSpecBench: Benchmarking LLMs for Executable Behavioral Specification Generation

Authors: Zaoyu Chen, Jianbo Dai, Boyu Zhu, Jingdong Wang, Huiming Wang, Xin Xu, Haoyang Yuan, Zhijiang Guo, 

Organizations: The Hong Kong Polytechnic University · University of Edinburgh · UCL · CUHK (SZ) · 

Abstract

Large language models (LLMs) can generate code from natural language, but the extent to which they capture intended program behavior remains unclear. Executable behavioral specifications, defined via preconditions and postconditions, provide a concrete means to assess such understanding. However, existing work on specification generation is constrained in evaluation methodology, task settings, and specification expressiveness. We introduce CodeSpecBench, a benchmark for executable behavioral specification generation under an execution-based evaluation protocol. CodeSpecBench supports both function-level and repository-level tasks and encodes specifications as executable Python functions. Constructed from diverse real-world codebases, it enables a realistic assessment of both correctness (accepting valid behaviors) and completeness (rejecting invalid behaviors). Evaluating 15 state-of-the-art LLMs on CodeSpecBench, we observe a sharp performance degradation on repository-level tasks, where the best model attains only a 20.2% pass rate. We further find that specification generation is substantially more challenging than code generation, indicating that strong coding performance does not necessarily reflect deep understanding of intended program semantics. Our data and code are available at https://github.com/SparksofAGI/CodeSpecBench.

Figures & tables

Appendix figures & tables7 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. Teaching Code LLMs to Reason with Intermediate Formal Specifications

    Jul 5, 2026Minh Le-Anh, Cuong Chi Le, Tien N. NguyenFormal VerificationCode Language Models

  2. Self-Spec Verifiable Code Generation

    Sep 30, 2026Jiaru Qian, Yihong Dong, Yongmin Li +3LLM Self-CorrectionCode Generation

  3. Inferring Code Correctness from Specification

    May 28, 2026Tambon Florian, Papadakis MikeAutomated Software TestingCode Generation Evaluation