AI
New benchmark reveals LLMs struggle with writing program behavior specs, even when coding is strong
CodeSpecBench shows that large language models find it far harder to formalize program intent through executable specifications than to generate working code.
Researchers have developed a benchmark that exposes a blind spot in how well large language models truly understand software behavior. While LLMs have become skilled at writing code from text descriptions, a new study shows they are significantly less capable when asked to articulate what a program should do in formal, testable terms.
The challenge: formalizing program intent#
The team introduced CodeSpecBench, an evaluation framework that measures how accurately LLMs can generate executable behavioral specifications—concretely, sets of preconditions and postconditions that define what a function should accept and what it should produce. Rather than simply checking whether code runs, this approach tests whether models grasp the deeper semantics of a program's intended purpose.
Specifications are encoded as Python functions that can actually be executed and validated against real code, creating a reality-based grading system: a spec either correctly accepts valid behaviors or it wrongly rejects them. This precision matters, because surface-level code correctness does not necessarily translate to genuine understanding of program intent.
Results: sharp decline on complex tasks#
When evaluated across 15 leading LLMs, the results were sobering. While models performed reasonably well on individual function-level tasks, their performance collapsed on repository-level challenges—where the best model achieved only a 20.2% pass rate. This dramatic drop suggests that understanding behavior within a broader codebase context remains a significant hurdle.
More broadly, the researchers found that specification generation is substantially harder than code generation itself. High performance at writing code does not ensure the ability to formally express what that code is meant to accomplish—a distinction that matters for formal verification, testing, and system safety.
Why it matters#
The findings underscore a gap between two different forms of AI competence: the ability to produce functional output versus the ability to reason about and articulate intended semantics. As AI systems move into more critical roles in software development—from code review to automated testing to formal verification—this gap could become a real liability. Benchmarking frameworks like CodeSpecBench help surface these weaknesses early.
The researchers have made their benchmark, data, and code publicly available to advance further work in this area.

