Manuscript Offprint
arXiv:2610.38214Skeleton Coding: Program Structure as a Specification for Agents
Abstract
Coding agents are typically provided end-to-end behavioral specifications that the code they produce should satisfy, such as tests and input-output examples. How many such specifications must a developer provide, and which ones, for the agent to produce the developer's intended program? We argue that this cannot be determined a priori, for it depends on the structure of the implementation, which is left to the agent to decide. An agent first commits to a structure—a decomposition into data types, modules, and functions—which fixes a class of candidate programs; behavioral specifications then select a program within that class. A set of tests that suffices for one structure may leave another badly underdetermined, requiring different edge cases or exponentially more examples. Since the structure is chosen by the agent, developers cannot ensure their specification is complete without reverse-engineering it from thousands of lines of generated code. To resolve this, we introduce Skeleton Coding, in which developers jointly specify the structure—in high-level, code-like format—alongside behavioral specifications. Theoretically, we model AI-assisted coding as a control problem, and show that skeletons can reduce exponentially the number of tests developers must supply to steer an agent toward an acceptable program. Empirically, across four models and three benchmarks, the best-performing skeleton specifications reduce mean test error by 48.4% relative to the best end-to-end behavioral specifications. Even when the agent can query a complete reference implementation, adding a skeleton reduces mean test error relatively by up to 27.0%. Skeletons also narrow the average gap between small and large models by about 52.4% while lowering implementation cost by 15-26×, and reduce code erosion by 24.7% on average.
1 Introduction
Coding agents are shifting the role of developers from writing code to controlling an agent into producing an acceptable code base. This raises a key question: how can developers specify their intent and safely guide the agent toward producing an acceptable program, while minimizing their effort?
A common ideal has been to move toward the separation of concerns [1] offered by specification-driven development [2]: The developer's job should not be to dictate how to implement the code base, but to specify what behavior any acceptable result must have — through prompts, examples, tests, or formal contracts — and verify that the result fulfills that intent.
*Equal contribution sorted alphabetically Corresponding authors: agolatka@amazon.com, aachille@amazon.com

(a)
(b)
(c)
Figure 1: Behavioral specifications do not pinpoint correct programs. (Left) We ask a coding agent to implement a code base from ProgramBench given its documentation and a fraction of its test suite. We then measure error rate across the hidden suite. On average, no number of tests provided results in a program that passes all hidden tests. (Middle) Even providing a full behavioral specification is not enough: We measure the pass rate with access to an oracle providing the full and exact input-output behavior. Even so, adding a skeleton with local contracts increases the pass rate averaged across models by 10.9% relative to the same setup without a skeleton on ProgramBench. (Right) A skeleton specifying the local contract for slicing a strided view.
Ideally, this separation of concerns between the what and the how promises to free developers from the laborious task of writing code. However, we show that it can actually exponentially increase the effort required.
The separation fails because how many tests are needed, and which ones, is not a property of the function being implemented but of the structure of its implementation. Consider for example implementing the indexing rules of NumPy: fully specifying all their edge cases takes many tests and examples, yet most of them follow naturally from a single structural choice — implementing arrays as strided views of memory [3, 4] — which no example or end-to-end test can express. Yet it is the agent, not the developer, that chooses the structure. A test suite that suffices for one design can leave another badly underdetermined, so a developer cannot know whether their tests are sufficient without further extensive manual testing, or inspection of thousands of lines of generated code.
Based on this, we argue that the most effective control action for developers is to partially break the separation, and jointly specify structure and behavior. To this effect, we introduce Skeleton Coding, in which developers specify the structure of an application directly, in high-level, code-like form: data types, module boundaries, function signatures, data flow, per-function contracts, and invariants — leaving the actual implementation to the agent (Section A.1). These are the decisions where skilled developers traditionally add the most value, and that end-to-end tests cannot express.
Formally, the coding agent faces an identification problem [5, 6, 7]. Let be the programs the agent can produce and the developer's goal set of acceptable programs. Given input-output observations of a reference program, the agent must find a program in . It first commits to a design—a decomposition into data types, modules, and functions—which restricts the search to a class , and tests then select a program within it. Even when the training of the model results in a strong prior, some tasks require exponentially many observations before the agent succeeds with

Figure 2: Value of different types of specifications. We generate specifications of different kinds and measure the error rate of a coding agent using them. No matter the format, behavioral specifications that describe only end-to-end behavior underperform specifications that describe the developer's intended structure. Of the structural specifications, code-like specifications that describe function signatures and invariants outperform design files in natural language. Adding overly detailed specifications decreases the accuracy of smaller models.
high probability. Figure 1 (left) illustrates the problem: supplying more tests raises the pass rate, yet on average no number of tests yields a program that passes the full suite. From the developer's side, this is a control problem: find the cheapest specification that makes the agent sample a program from (Section 2). Unfortunately, the optimal depends on , which the developer does not see.
Skeleton coding addresses the issue by letting the developer supply . Instead of carving out the goal set one test at a time, developers can shrink the hypothesis class and provide the optimal tests for it. This can cut the number of needed tests exponentially, for several reasons. First, skeletons can quickly reduce the dimension of the hypothesis space. But, less intuitively, even when two skeletons lead to search spaces of the same size, a well-chosen hypothesis class may need exponentially fewer tests to identify the correct program than a poorly chosen one (Theorem 2.1). Second, with end-to-end tests alone the program's internal state is hidden: an error in one component is visible only if it propagates to the output. By exposing intermediate interfaces, a skeleton makes that state observable, so for example a dataflow composing function can be identified with local tests, whereas end-to-end tests may need (Theorem 2.2). Third, some requirements, such as internal implementation details, are not observable from outputs at all and no number of tests can enforce them. A skeleton can instead state them directly (Theorem 2.3).
Developers rarely begin with a complete specifications; they adapt it to correct issues and steer the agent toward the goal. However, since prompting a model does not perform Bayesian conditioning [8], there is no guarantee that providing additional specifications will eventually converge to the goal. However, adding formally verifiable contracts [9, 10, 11] to the skeletons circumvent the issue (Theorem 3.1). Even when informal contracts are not used, an imperfect verifier can still ensure faster convergence to a valid implementation (Theorem 3.2).
Because skeletons resemble code, teams can version, diff, review, and revise them alongside the implementation as requirements evolve. A persistent skeleton also records which decisions are

Figure 3: Skeletons and tests shrink the set of programs the agent considers: (a) Without a skeleton, the agent's prior spreads over all programs. (b) Fixing a skeleton restricts the agent to programs with that skeleton. (c) Each set of end-to-end tests further keeps only the programs that agree with the reference on the tested inputs.
requirements, so agents can rewrite cleanly when adding functionality instead of accreting patches to preserve accidental behavior, a major contributor to “AI code slop” on long-lived code bases [12].
Empirical results. To show the value of skeletons and structural specifications, we compare the pass-rate with and without skeletons across various coding benchmarks and architectures. On SCBench [12] and SDDBench (Section B), structural specifications raise mean pass rate from 72% to 89% and from 29.0% to 74.2%, whereas even the best purely behavioral specifications gain at most 9.4 percentage points (Figure 2). Surprisingly, on ProgramBench [13], where the coding agent is provided with a full behavioral-specifications (an oracle binary), skeletons still raise relative pass rate by 10.9% (Figure 1, right). Skeletons also narrow the gap between small and large models [14]: with a detailed skeleton, a small model comes within 5–8 percentage points of the largest model's pass rate at 15–26× lower implementation cost (Figure 5). Aside from outperforming behavioral specifications, our proposed code-like skeletons outperform structural specifications provided as prose design documents (Figure 6). In terms of code maintainability, skeletons reduce code erosion by 24.7% where behavioral specifications increase it (Figure 7). In iterative repair, they reach similar error rates with 32% fewer queries to the reference executable (Figure 8).
The simplest form of specifications are behavioral specifications, which describe the expected input–output behavior of programs in through a set of examples . Note that end-to-end tests are a special case with finitely many examples, while property testing [15] and formal contracts [16] can be viewed as specifications that implicitly characterize infinitely many such pairs. For clarity, in the following we focus on the case where is finite and given by end-to-end tests.
A good set of tests is such that, after prompting the agent with , it will generate with high probability a program in . That is, letting denote the agent's distribution over programs after prompting with the task alone, we want:
for a small . However, producing tests is expensive for the developer. Hence, we are interested in the minimum number of tests needed:
where the minimum is over all test suites [17, 7, 18].
A program, however, can also be specified by describing its architecture. We call a skeleton as a partial abstraction of a program, describing its data types, module boundaries, permitted calls and data flow, and function declarations with signatures, but omits their implementation (see Figure 1).
Specifying a skeleton restricts the search space to the subset of programs sharing the same skeleton. In turn, this can drastically change the number of tests required to generate a program in . Let and denote the agent distribution restricted to by (Figure 3b), the minimum number of tests required when using the skeleton is:
The rest of this section shows that appropriately specifying can, with little developer effort, exponentially reduce .
But first, what happens when the developer does not specify a skeleton? The agent will have to select an architecture based on alone. Let denote the probability of the model selecting a given architecture, then the probability of success is an average over the agent's choices:
Tests act on both factors: they select a program within each skeleton, and they reweigh the skeletons by the prior mass of their surviving programs. A developer who supplies a skeleton removes the agent's choice and replaces the average with a single term. Even when no tests are specified, this can still raise the success probability exactly when the success rate of the developer chosen skeleton exceeds the agent's average .
2.1 Structure determines what tests are needed
Specifying a skeleton restricts the hypothesis class the coding agent needs to consider. By itself, this can quickly reduce the number of tests needed to reach the goal (Figure 3) by simply reducing the search space (when intersects with ). However, even when the two skeletons admit the same number of programs, a developer can reduce exponentially the number of tests needed by designing the skeleton smartly, as the following theorem shows.
Theorem 2.1 (Exponential separation between skeletons). For every , there are a target function and two skeletons for it, each admitting programs with distinct behaviors under a uniform prior, such that for every

Figure 4: A strong skeleton makes better use of tests. Visualization of how tests affect the two skeletons of Theorem 2.1.
Moreover, a suite of tests that guarantees success under would lead to success probability only under .
The two skeletons (described in the Appendix) differ in how informative end-to-end tests are. Under , each test excludes at most a single program, while under , each test rules out half of the incorrect programs (Figure 4).
The second part of the theorem shows why a developer cannot determine the required test suite to guarantee success without knowing the structure of the yet-to-be-written program. Suppose the developer creates an optimal test suite that guarantees success under the assumption the agent uses the architecture . If the agent chooses instead, the same optimal test suite will fail with high probability.
One may wonder if providing designed for should not implicitly bias the agent toward picking . But the reverse is actually true: by Equation (3), conditioning on shifts the agent toward the skeleton under which they are uninformative, because that skeleton loses the fewest programs. In Figure 1 (right), we show this empirically: even when the agent has a full behavioral specification, supplying a skeleton raises its pass rate, although the observations available to the agent are unchanged.
2.2 Interfaces make internal state observable
A second way in which skeletons reduce the number of tests needed is by changing what tests can observe [19]. An end-to-end test exposes a fault only if the faulty code runs, corrupts the program state, and the corruption propagates to the output [20]. When later computation masks the corruption, a faulty program returns the correct output on almost every input, and end-to-end tests must search for the few inputs that reveal it. The interfaces of a skeleton name the intermediate values, so each component can be tested directly.
Consider for example a program that reads one input bit at each of stages and carries one bit of state:
Let be this skeleton. An end-to-end test observes only . However, having specified , the developer can also specify local tests for each of the components , and observe the intermediate hidden state . The following theorem shows that this too reduces exponentially the number of tests the developer needs to specify.
Theorem 2.2 (Exponential separation between local and end-to-end tests). Let the goal be to implement the identically zero function. There is a prior over the transition tables, with , under which
and in particular . Conversely, under any prior giving mass to the correct solution, local tests suffice to identify .
Note that the program has only unknown bits (the truth table of each ), yet its output can hide where a disagreement arose. In the proof, each incorrect program differs from the reference on a single input [7], which end-to-end tests must find by search. A local test needs no such search, because it observes a component before later computation can mask it [21]. The skeleton provides this observability through its interfaces and contracts. For example, in Figure 1 (left), we show that although the agent can run the reference executable on any input, its pass rate approaches that of the full test suite only as the evaluation tests themselves are supplied. The bottleneck is finding the inputs that reveal an error.
2.3 Some requirements are invisible to output tests
The acceptable set could exclude programs that compute the same function, but whose implementation the developer does not consider acceptable. For example, a developer may exclude implementations that use too many resources or have poorly maintainable code. However, those programs cannot be distinguished by end-to-end tests that observes only the values a program returns as the next proposition quantifies.
Proposition 2.3 (Behavioral tests preserve odds within a behavior class). Let be a reference implementation, and let be the programs in that have the same input-output behavior. Suppose the goal set considers only a subset of those acceptable. Then, for every test set :
so whenever exceeds this ratio.
In this situation, the only control input developers have to increase the chance of generating an acceptable program is to specify the skeleton . Code quality is one such requirement. In Figure 7, we show that structural specifications reduce erosion relative to the task-only condition, while behavioral specifications can actually increase it.
2.4 What makes a good skeleton
In section 2.2, we have seen that skeletons can reduce the developer's effort by allowing specification of internal components. However, a good skeleton should also structure the implementation to

Figure 5: Skeletons bridge the gap between large and small models: Skeleton specifications significantly improve performance of smaller models, leading to accuracy similar to that of larger models at a lower cost. In particular, the entire cost-performance Pareto frontier (dashed) is formed mostly by small models with structural specifications.
reduce cross-component dependencies [22]. Let be the components of a program in . Let be the smallest number of local tests to specify a behavior for the component . Even when each component has an acceptable behavior, their composition might not [23] and additional end-to-end tests need to be provided to pin-point a globally coherent implementation. Let be the smallest number of end-to-end tests that rule out unacceptable programs in .
Theorem 2.4 (The cost of a skeleton splits into description, local tests, and compatibility). For every skeleton with an acceptable reference and for every , where a guarantee means posterior correctness one,
where the minimum is over sets containing the reference components. Moreover, if and only if .
The total effort required of the developer is the cost of writing the skeleton , and of specifying the required tests. What makes a good skeleton then? First, it should be short, stating only the decisions that are needed to control the agent. Each of its components should be simple to specify, with a narrow interface and a behavior that a few tests or a short contract can pin down. Individually correct components should automatically lead to globally correct programs. For example, complete Hoare-style pre- and post-conditions [24] achieve (no compatibility tests are needed), since if each component satisfies its contract then the implementation is globally correct. This can come at the cost of a longer specification . However, it might be still worth it: when , components are independent so independent agents can implement them in parallel with no risk of conflict. Moreover, each agent then faces a simpler task, which a smaller model may handle (Figure 5).
3 Closing the Loop: Checks and Refinement
Section 2 describes an open-loop control setting: the specifications are provided as initial conditions to the agent. Initial conditions can at most condition, but not control, the execution. However, in practice LLMs are not even conditioned in the classical probabilistic sense, as much as they are prompted [8]. We will elaborate on this subtle but important difference, whose consequence is that it forces developers to iterate on a slow loop: they check each proposal and answer its failures. Whether this loop works depends on whether the specification can be checked mechanically. In each case below, a skeleton turns a cost that multiplies across components into one that adds.
Let be a specification. So far, we have considered exact Bayesian conditioning on the specification which restricts the agent's distribution to the programs that satisfy it. Let be the distribution actually produced by prompting the agent with the task and the specification , so that . Generally, the Bayesian posterior and the prompted model distribution will differ:
This means that a sample from might still violate . Moreover, suppose the developer adds to an initial specification an additional specification to steer the agent toward the goal (such that ). The posterior entropy cannot increase in expectation over possible observations under the Bayesian predictive distribution, . Prompting with additional specifications, on the other hand, has no such guarantee. Indeed, in our experiments we show that overly detailed contracts can actually lower the pass rate (Figure 2).
Formal specifications. Nonetheless, when the specification can be checked formally, the developer can close the loop by rejection sampling, discarding proposals that fail the check. This ensures eventual convergence as more specifications are added, at the cost of additional compute to resample rejected programs. Local formal contracts can exponentially decrease the cost of rejection sampling as the following proposition shows. Let the skeleton have components , let be the implementations of component that satisfy its contract, and assume . Given the skeleton, each component can be generated independently , and we write . Let be the resulting distribution over programs.
Proposition 3.1 (Checking components separately). Resampling the whole program until every check passes takes proposals in expectation, whereas resampling each component until its own check passes takes component proposals. Both return programs distributed as .
Informal contracts. In our experiments we use informal contracts stated in the docstrings of the skeleton, checked by the agent itself or by a model used as a judge. Suppose the judge accepts every implementation consistent with its informal contract and let be the probability that it also accepts an implementation not in . This false-accept rate has two sources, : the fraction of violations that the informal contract, read literally, still allows, and the rate at which the judge accepts the others.
Proposition 3.2 (What an informal check guarantees). Under the assumptions of Theorem 3.1:
(i) the probability that a component accepted by the judge actually satisfies the contract is ;
(ii) resampling each component until its check accepts yields a program that satisfies every contract with probability at least ; the probability is at most for whole-program rejection sampling with false-accept probability .
In particular, a check makes an accepted component likely correct only when it errs much less often than the agent fails on that unit, . The term is a floor that no judge removes: a violation that the informal contract allows passes even a perfect judge. Making informal contracts more precise can drive to zero, leaving equal to the judge's own error ; when that error also vanishes, we recover Theorem 3.1.
4 Empirical Results
In this section, we empirically study how different kinds of specifications – both behavioral and structural – affect pass rate, code quality and implementation cost.
Types of specifications. We test different specifications that describe end-to-end behavior but not the structure of the code base: (a) Task Only: a vibe-coding style prompt describing the task; (b) Concrete Behaviors: natural language prescription of observable behavior in EARS format [25]; (c) Behavioral Tests: test suite on the public APIs. We then consider specifications describing the desired structure of the code base: (d) Design: a prose document describes the system architecture [26]; (e) Function Stubs: a code-like specification containing modules and function signatures with docstrings [27]; (f) Local Contracts: same as before, but adding local contracts, such as pre- and post-conditions to the docstring of each function [16]; (g) Global Invariants: same as before, adding properties about the composition of functions that should hold at the code-base level.
Models and Benchmarks. We first consider greenfield applications, where the implementation is generated from scratch, using programs drawn from SlopCodeBench (SCBench) [12], SD-DBench (Section B), and ProgramBench [13]. We evaluate GPT-5.6 Sol and GPT-5.6 Luna [14], Qwen3.8-27B [28], and GLM 5.2 [29]. In each experiment, we take a reference program from one of these datasets and generate different types of specifications from it. The implementation agent then receives the task description and one specification and produces a reconstructed program without access to the reference implementation. We run all agents in our experiments with the open-source AI Functions framework [30]¹.
Metrics. We measure agreement with evaluation tests and properties of the produced implementation. Test pass rate is the fraction of evaluation tests that the implementation passes. It measures agreement on the tested cases; passing a finite suite does not by itself establish membership in . Code erosion and verbosity characterize implementation quality separately from behavioral correctness. Code erosion [12] is the share of cyclomatic-complexity [31] mass held by functions with cyclomatic complexity greater than 10, where each function's mass is its cyclomatic complexity multiplied by the square root of its source-line count. It measures how much complexity is concentrated in difficult-to-maintain code. Verbosity is the fraction of source lines flagged as duplicated code or common code-slop patterns and measures unnecessary or repetitive implementation content. Implementation cost is the estimated monetary cost of the implementation model's input, output, and cache-read tokens, calculated using the corresponding per-token prices.
Generation of specifications. Each experiment starts from a ground-truth code base . From this, based on the experimental setting , we produce a specification . The ground-truth
¹https://github.com/strands-labs/ai-functions


Figure 6: (Left) More architecture detail does not match skeletons. Adding architecture sections to the markdown file slightly raises mean pass rate, but the resulting pass rate remains below that achieved with skeleton-based specifications. (Right) Accuracy improvement with additional behavioral observations. On ProgramBench, we show the average test pass rate increases as we increase the number of observations provided to the model (unlimited lets the agent decide), but in all cases end-to-end behavioral specifications perform worse than skeletons with just 20 queries.
code base is then kept hidden, and the implementation agent reconstructs the program from the task and specification alone, . In the structural conditions the specification is a skeleton; in the behavioral conditions it is a set of observations derived from the reference; the task-only baseline supplies no specification and samples from . Pass rate therefore reflects both the information each specification carries and the agent's ability to use that information.
4.1 Results
Behavioral testing alone does not identify valid programs First, in Figure 1 we evaluate on ProgramBench how many behavioral specifications are needed to identify a program in the goal set. ProgramBench provides an oracle binary implementation for each task, which is in principle a full behavioral specification. However, even with access to it models only pass 61.5% of the hidden tests. Still, this may be due to the agent not being able to make informative enough queries. To simulate a developer providing an informative set of observations, we provide the agent with an increasing number of the hidden tests. Surprisingly, while providing additional tests does help, on average no number of tests provided is enough to let the agent identify the correct program. This supports the theoretical observation that, with no structure specified, exponentially many tests might be required despite the strong prior of frontier coding agents.
Structural specifications outperform behavioral. Next, we compare the performance of different types of specifications from behavioral descriptions and tests with accuracy from architecture documents and code-like skeletons. In Figure 2 we see that, no matter the format, behavioral specifications underperform compared to structural specifications. Of the latter, code-like specifications consisting of function stubs perform better than architectural design files in natural language. Adding additional structural constraints, such as local and global invariants, further improves the final pass rate. Across SCBench [12] and SDDBench, structural specifications raise mean pass rate from 71.7% to 89.2% and from 29% to 74.2%, respectively, whereas behavioral specifications improve pass rate by at most 9.4 percentage points. Adding function stubs alone raises SDDBench mean pass rate from 53% to 66.4%. Together with Programbench, across 4 models the relative error rates reduces by 48.4% from 40.7% to 21.0% (see Figures 2 and 10) compared to the best

Figure 7: Structural specifications produce less eroded code than behavioral specifications: Across all benchmarks and models, structural specifications reduce code erosion by up to 24.7%, compared to the task-only prompt. Meanwhile, behavioral specifications increase it. Verbosity varies little across conditions.
end-to-end behavioral specifications.
Structure helps even with perfect behavioral specifications. One may wonder whether providing enough behavioral specifications can eventually match structural specification. Theoretically, this should be the case, but it does not happen in practice. In Figure 1 (Right), we show on ProgramBench that, even when the agent can query the oracle (a full behavioral specification), adding a skeleton with local contracts increases mean pass rate by 10.9% relative (from 64.0% to 70.9%) to the same setup without a skeleton. The best-performing structural condition, a skeleton with global invariants, reduces mean test error across the four models by 27.0% relative (from 36.0% to 26.3%) to that baseline (Figure 10). To remove the influence of the agent's choice in querying the oracle Figure 6 (Right), we provide the increasing number of curated observations up to 160. For any number of curated observations, the performance is strictly worse than that of a skeleton with just 20 observations.
Structural specifications improve smaller models. We compare pass rate and implementation cost across model sizes in Figure 5, and test whether structural specifications narrow the gap between smaller and larger models. With detailed global invariants, GPT-5.6 Luna [14] improves from 67% to 90% on SCBench [12] and from 21.1% to 79.5% on SDDBench. These results come within 5.0–8.2 percentage points of the best GPT-5.6 Sol [14] results at approximately 15× and 26× lower implementation cost, respectively.
More architectural specifications. Within structural specifications, we have seen in Figure 2 that code-like specifications outperform prose-like specifications such as markdown files describing the architecture. This motivates our choice to use code-like specifications for skeleton coding. We can ask if a more elaborate architecture file can bridge the gap with code-like signature specifications. This is not the case: in Figure 6 we show that adding progressively more architectural information does raise mean pass rate (61% → 71% on SCBench [12], 40.1% → 52.8% on SDDBench). However, while it expands the input by roughly 4–7×, every architecture specification still remains below the best code-like specification on the same repositories.
Model fatigue and non-Bayesian models. One may expect that adding more specifications

Figure 8: Skeletons reduce query effort and cost during iterative repair: For iterative repair tasks, using skeletons reduces the total cost of implementation, and also the number of user queries. We model user queries with the number of calls to the program binary. Additionally, final code has lower erosion and higher maintainability.
will always result in more faithful implementations. This is, however, not the case. In Figure 2, we take the best-performing skeleton specification, and we add additional local and global contracts that, while correct, are overly detailed. This reduces performance, especially on smaller models. While the Bayesian posterior on additional specifications should only improve pass-rate, prompting the model with specifications need not approximate the Bayesian posterior. This is increasingly the case when more specifications are provided, making actual Bayesian conditioning more complex.
Effect of skeletons on code quality An implementation can pass its tests while containing complex or repetitive code. We compare erosion and verbosity across specification types to test whether specifying function boundaries and contracts improves code quality alongside accuracy. In Figure 7, we show that signature specifications reduce code erosion from 0.66 to 0.56 on SCBench and from 0.41 to 0.24 on SDDBench relative to the task-only condition, while behavioral specifications increase erosion to as much as 0.73 and 0.43. Verbosity varies less across conditions, but is also lowest under structural specifications on SDDBench.
Skeletons reduce query effort during iterative repair. In Figure 8, we compare iterative fixing of a code-base both without using skeletons and asking the agents to maintain a skeleton. In both cases, we start with the task and reference-binary access; between rounds, we disclose new failing tests and carry the code and, where present, the skeleton into a fresh conversation. By round 8, the skeleton workflow reaches similar error rates with 32% fewer reference-binary calls (a proxy for behavioral clarification effort), lower mean erosion, and higher mean maintainability.
5 Related Work
Contracts and formal specifications. Skeletons inherit their basic vocabulary from program logics and design-by-contract methods, which make interfaces, preconditions, post-conditions, and invariants explicit rather than leaving them implicit in an implementation [24, 16]. Verification languages such as Dafny make these contracts machine-checkable and use them to generate proof obligations for an implementation [9]. The skeletons we evaluate range from typed stubs [27] to stubs with local contracts and global invariants written in EARS [25], and are not machine-checked. We draw on the contract tradition to separate interfaces, contracts local to one function [32], and invariants shared across components, and measure how much each helps a coding agent.
Intermediate artifacts for code generation. Several code-generation systems ask a model to construct an intermediate artifact before writing or modifying code [33, 34]. Self-planning first elicits a sequence of implementation steps and then conditions generation on that plan [35]; CodePlan combines a repository-wide edit plan with dependency and change-impact analysis [36]. RPG replaces free-form natural-language plans with a repository planning graph that encodes capabilities, file structure, data flows, and functions, from which ZeroRepo generates whole repositories [37]. SpecRover instead infers intended behavior while searching a repository and uses a reviewer to vet the resulting patch [38]. Tests can also serve as intermediate behavioral evidence [39, 40]: CodeT generates tests to rank candidate implementations [41]. These interventions use intermediate artifacts, but plans, specifications, and tests are usually evaluated as complete workflows. We instead hold the implementation task and model fixed while organizing skeletons by the contract content they expose, separating that content from artifact format and raw length.
Specification-driven development. Recent work treats specifications as artifacts that guide generation and persist across revisions. SMART regenerates an ML performance-modeling library from modular natural-language design documents with worked examples [42]. He et al. compare specification forms and input granularity, finding benefits from structured pseudocode and module-level inputs [43]. SpecFirst separates behavioral specification elicitation from implementation: one agent combines documentation with observations from querying an execute-only binary into a specification, which another agent uses for code synthesis [44]. We complement these approaches by varying the structural information supplied in skeletons and measuring reconstruction accuracy, code quality, and query effort.
Constrained and formally verified generation. A complementary line of work enforces stronger constraints during generation [45]. Program sketching is a direct precedent for skeletons: the programmer writes a partial program that fixes the structure of a solution, and a synthesizer fills in the missing details so that the result agrees with a reference implementation or passes supplied tests [46]. Synchronesh restricts decoding to programs admitted by a target language and its semantic constraints [47]. AlphaVerus [48] and AutoVerus [49] use verifier feedback, search, and specialized repair procedures to generate verified code and correctness proofs in Verus, a verifier for Rust [10], while the Vericoding benchmark [50] evaluates generation from formal specifications across Dafny [9], Verus, and Lean [11]. These systems primarily address the downstream problem of finding code and proof material for a supplied formal specification. Our central question is upstream: what information the implementation target should contain, who must author it, and how much implementation uncertainty it removes. The current experiments use executable acceptance checks rather than machine-checked proofs; evaluating the formal checks discussed in Section 3 remains a direction for future experiments.
Greenfield and repository-level evaluation. Function-level benchmarks such as HumanEval established test pass rate as a standard outcome for code generation from a short natural-language description [51]. SlopCodeBench (SCBench) extends evaluation to long-horizon, iterative greenfield development, where generated decisions accumulate as a project evolves [12]. We study greenfield and brownfield tasks to expose different burdens: greenfield generation must preserve a growing design, whereas brownfield modification must first recover relevant behavior from pre-existing code. Beyond aggregate pass rate, we report outcomes by specification type, skeleton coverage, model, query effort, and code quality.
References
[1] Edsger W. Dijkstra. On the Role of Scientific Thought. In Selected Writings on Computing: A Personal Perspective, pages 60–66. Springer, 1982.
[2] Amazon Web Services. Kiro: An Agentic IDE for Spec-Driven Development. https://kiro.dev, 2025.
[3] Stéfan van der Walt, S. Chris Colbert, and Gaël Varoquaux. The NumPy Array: A Structure for Efficient Numerical Computation. Computing in Science & Engineering, 13(2):22–30, 2011.
[4] Charles R. Harris, K. Jarrod Millman, Stéfan J. van der Walt, et al. Array Programming with NumPy. Nature, 585:357–362, 2020.
[5] Karl Johan Åström and Pieter Eykhoff. System Identification—A Survey. Automatica, 7(2):123–162, 1971.
[6] E. Mark Gold. Language Identification in the Limit. Information and Control, 10(5):447–474, 1967.
[7] Ji Liu and Xiaojin Zhu. The Teaching Dimension of Linear Learners. Journal of Machine Learning Research, 17(175):1–25, 2016. https://jmlr.org/papers/v17/15-630.html.
[8] Fabian Falck, Ziyu Wang, and Chris Holmes. Is In-Context Learning in Large Language Models Bayesian? A Martingale Perspective. In Proceedings of the 41st International Conference on Machine Learning, 2024.
[9] K. Rustan M. Leino. Dafny: An Automatic Program Verifier for Functional Correctness. In Logic for Programming, Artificial Intelligence, and Reasoning, volume 6355 of Lecture Notes in Computer Science, pages 348–370. Springer, 2010. https://doi.org/10.1007/978-3-642-17511-4_20.
[10] Andrea Lattuada, Travis Hance, Chanhee Cho, Matthias Brun, Isitha Subasinghe, Yi Zhou, Jon Howell, Bryan Parno, and Chris Hawblitzel. Verus: Verifying Rust Programs using Linear Ghost Types. Proceedings of the ACM on Programming Languages, 7(OOPSLA1):286–315, 2023. doi: 10.1145/3586037.
[11] Leonardo de Moura and Sebastian Ullrich. The Lean 4 Theorem Prover and Programming Language. In Automated Deduction – CADE 28, volume 12699 of Lecture Notes in Computer Science, pages 625–635. Springer, 2021. doi: 10.1007/978-3-030-79876-5_37.
[12] Gabriel Orlanski, Devjeet Roy, Alexander Yun, Changho Shin, Alex Gu, Albert Ge, Dyah Adila, Nicholas Roberts, Frederic Sala, and Aws Albarghouthi. SlopCodeBench: Benchmarking How Coding Agents Degrade Over Long-Horizon Iterative Tasks. arXiv preprint arXiv:2603.24755, 2026. https://arxiv.org/abs/2603.24755.
[13] John Yang, Kilian Lieret, Jeffrey Ma, Parth Thakkar, Dmitrii Pedchenko, Sten Sootla, Emily McMilin, Pengcheng Yin, Rui Hou, Gabriel Synnaeve, Diyi Yang, and Ofir Press. ProgramBench: Can Language Models Rebuild Programs From Scratch? arXiv preprint arXiv:2605.03546, 2026. https://arxiv.org/abs/2605.03546.
[14] OpenAI. GPT-5.6: Frontier Intelligence for Professional Work. https://openai.com/index/gpt-5-6/, 2026.
[15] Koen Claessen and John Hughes. QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs. In Proceedings of the Fifth ACM SIGPLAN International Conference on Functional Programming, pages 268–279, 2000.
[16] Bertrand Meyer. Applying “Design by Contract”. Computer, 25(10):40–51, 1992. https://doi.org/10.1109/2.161279.
[17] Sally A. Goldman and Michael J. Kearns. On the Complexity of Teaching. Journal of Computer and System Sciences, 50(1):20–31, 1995.
[18] Dana Angluin. Queries and Concept Learning. Machine Learning, 2(4):319–342, 1988.
[19] Rudolf E. Kalman. Mathematical Description of Linear Dynamical Systems. Journal of the Society for Industrial and Applied Mathematics, Series A: Control, 1(2):152–192, 1963.
[20] Jeffrey M. Voas. PIE: A Dynamic Failure-Based Technique. IEEE Transactions on Software Engineering, 18(8):717–727, 1992. https://doi.org/10.1109/32.153381.
[21] Roy S. Freedman. Testability of Software Components. IEEE Transactions on Software Engineering, 17(6):553–564, 1991. https://doi.org/10.1109/32.87281.
[22] David L. Parnas. On the Criteria To Be Used in Decomposing Systems into Modules. Communications of the ACM, 15(12):1053–1058, 1972. https://doi.org/10.1145/361598.361623.
[23] Albert Benveniste, Benoît Caillaud, Dejan Nickovic, Roberto Passerone, Jean-Baptiste Raclet, Philipp Reinkemeier, Alberto Sangiovanni-Vincentelli, Werner Damm, Thomas A. Henzinger, and Kim G. Larsen. Contracts for System Design. Foundations and Trends in Electronic Design Automation, 12(2-3):124–400, 2018.
[24] C. A. R. Hoare. An Axiomatic Basis for Computer Programming. Communications of the ACM, 12(10):576–580, 583, 1969. https://doi.org/10.1145/363235.363259.
[25] Alistair Mavin, Philip Wilkinson, Adrian Harwood, and Mark Novak. Easy Approach to Requirements Syntax (EARS). In 17th IEEE International Requirements Engineering Conference, pages 317–322, 2009. https://doi.org/10.1109/RE.2009.9.
[26] Paul Clements, Felix Bachmann, Len Bass, David Garlan, James Ivers, Reed Little, Paulo Merson, Robert Nord, and Judith Stafford. Documenting Software Architectures: Views and Beyond. Addison-Wesley, second edition, 2010.
[27] Guido van Rossum, Jukka Lehtosalo, and Lukasz Langa. PEP 484—Type Hints. https://peps.python.org/pep-0484/, 2014.
[28] Qwen Team. Qwen3.8-27B Model Card. https://huggingface.co/Qwen/Qwen3.8-27B, 2026.
[29] Z.AI. GLM-5.2: Overview. https://docs.z.ai/guides/1lm/glm-5.2, 2026.
[30] Strands Labs. Strands AI Functions. https://github.com/strands-labs/ai-functions. Python library.
[31] Thomas J. McCabe. A Complexity Measure. IEEE Transactions on Software Engineering, SE-2(4):308–320, 1976.
[32] Madeline Endres, Sarah Fakhoury, Saikat Chakraborty, and Shuvendu K. Lahiri. Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions? Proceedings of the ACM on Software Engineering, 1(FSE), 2024.
[33] Eric Zelikman, Qian Huang, Gabriel Poesia, Noah D. Goodman, and Nick Haber. Parsel: Algorithmic Reasoning with Language Models by Composing Decompositions. In Advances in Neural Information Processing Systems, 2023.
[34] Sirui Hong, Mingchen Zhuge, Jonathan Chen, Xiawu Zheng, Yuheng Cheng, Ceyao Zhang, Jinlin Wang, Zili Wang, Steven Ka Shing Yau, Zijuan Lin, Liyang Zhou, Chenyu Ran, Lingfeng Xiao, Chenglin Wu, and Jürgen Schmidhuber. MetaGPT: Meta Programming for a Multi-Agent Collaborative Framework. In International Conference on Learning Representations, 2024.
[35] Xue Jiang, Yihong Dong, Lecheng Wang, Zheng Fang, Qiwei Shang, Ge Li, Zhi Jin, and Wenpin Jiao. Self-Planning Code Generation with Large Language Models. ACM Transactions on Software Engineering and Methodology, 33(7):1–30, 2024. doi: 10.1145/3672456.
[36] Ramakrishna Bairi, Atharv Sonwane, Aditya Kanade, Vageesh D C, Arun Iyer, Suresh Parthasarathy, Sriram Rajamani, B. Ashok, and Shashank Shet. CodePlan: Repository-level Coding using LLMs and Planning. Proceedings of the ACM on Software Engineering, 1(FSE): 675–698, 2024. doi: 10.1145/3643757.
[37] Jane Luo, Xin Zhang, Steven Liu, Jie Wu, Jianfeng Liu, Yiming Huang, Yangyu Huang, Chengyu Yin, Ying Xin, Yuefeng Zhan, Hao Sun, Qi Chen, Scarlett Li, and Mao Yang. RPG: A Repository Planning Graph for Unified and Scalable Codebase Generation. arXiv preprint arXiv:2509.16198, 2025. https://arxiv.org/abs/2509.16198.
[38] Haifeng Ruan, Yuntong Zhang, and Abhik Roychoudhury. SpecRover: Code Intent Extraction via LLMs. In Proceedings of the 47th IEEE/ACM International Conference on Software Engineering (ICSE), pages 963–974, 2025. doi: 10.1109/ICSE55347.2025.00080.
[39] Shuvendu K. Lahiri, Sarah Fakhoury, Aaditya Naik, Georgios Sakkas, Saikat Chakraborty, Madanlal Musuvathi, Piali Choudhury, Curtis von Veh, Jeevana Priya Inala, Chenglong Wang, and Jianfeng Gao. Interactive Code Generation via Test-Driven User-Intent Formalization. arXiv preprint arXiv:2208.05950, 2022.
[40] Sarah Fakhoury, Aaditya Naik, Georgios Sakkas, Saikat Chakraborty, and Shuvendu K. Lahiri. LLM-Based Test-Driven Interactive Code Generation: User Study and Empirical Evaluation. IEEE Transactions on Software Engineering, 50(9):2254–2268, 2024.
[41] Bei Chen, Fengji Zhang, Anh Nguyen, Daoguang Zan, Zeqi Lin, Jian-Guang Lou, and Weizhu Chen. CodeT: Code Generation with Generated Tests. In International Conference on Learning Representations, 2023. https://openreview.net/forum?id=ktrw68Cmu9c.
[42] Samuel Kushnir, Kimia Noorbakhsh, Kavya Sreedhar, Liqun Cheng, Ming Liu, Parthasarathy Ranganathan, Mohammad Alizadeh, Fred Kjolstad, and Suvinay Subramanian. Design Docs Are All You Need: An AI-native Machine-Learning Performance Tool. arXiv preprint arXiv:2609.05364, 2026. https://arxiv.org/abs/2609.05364.
[43] Ruirui He, Hanqing Lu, Lezhi Ma, Kai Ye, Qiong Wu, Shangqing Liu, Lei Bu, and Xuan-dong Li. From Vibe to Spec: An Empirical Study to Demystify Specifications in Code
Generation. In Proceedings of the 41st IEEE/ACM International Conference on Automated Software Engineering, pages 2780–2792. Association for Computing Machinery, 2026. https://doi.org/10.1145/3832783.3837515.
[44] Yihao Chen, Shi Chang, Feng Lin, Khaled Chawa, Boyuan Chen, Shaowei Wang, and Ahmed E. Hassan. SpecFirst: Behavioral Specification Elicitation as a First-Class Step in Agent-Based Program Synthesis from Scratch. arXiv preprint arXiv:2607.27167, 2026. https://arxiv.org/abs/2607.27167.
[45] Chuyue Sun, Ying Sheng, Oded Padon, and Clark Barrett. Clover: Closed-Loop Verifiable Code Generation. In International Symposium on AI Verification, 2024.
[46] Armando Solar-Lezama. The Sketching Approach to Program Synthesis. In Programming Languages and Systems (APLAS 2009), volume 5904 of Lecture Notes in Computer Science, pages 4–13. Springer, 2009. doi: 10.1007/978-3-642-10672-9_3.
[47] Gabriel Poesia, Oleksandr Polozov, Vu Le, Ashish Tiwari, Gustavo Soares, Christopher Meek, and Sumit Gulwani. Synchronesh: Reliable Code Generation from Pre-trained Language Models. In International Conference on Learning Representations, 2022. https://openreview.net/forum?id=KmtVD97J43e.
[48] Pranjal Aggarwal, Bryan Parno, and Sean Welleck. AlphaVerus: Bootstrapping Formally Verified Code Generation through Self-Improving Translation and Treefinement. arXiv preprint arXiv:2412.06176, 2024. https://arxiv.org/abs/2412.06176.
[49] Chenyuan Yang, Xuheng Li, Md Rakib Hossain Misu, Jianan Yao, Weidong Cui, Yeyun Gong, Chris Hawblitzel, Shuvendu Lahiri, Jacob R. Lorch, Shuai Lu, Fan Yang, Ziqiao Zhou, and Shan Lu. AutoVerus: Automated Proof Generation for Rust Code. Proceedings of the ACM on Programming Languages, 9(OOPSLA2):3454–3482, 2025. doi: 10.1145/3763174.
[50] Sergiu Bursuc, Theodore Ehrenborg, Shaowei Lin, Lacramioara Astefanoaei, Ionel Emilian Chiosa, Jure Kukovec, Alok Singh, Oliver Butterley, Adem Bizid, Quinn Dougherty, Miranda Zhao, Max Tan, and Max Tegmark. A Benchmark for Vericoding: Formally Verified Program Synthesis. arXiv preprint arXiv:2509.22908, 2025. https://arxiv.org/abs/2509.22908.
[51] Mark Chen et al. Evaluating Large Language Models Trained on Code. arXiv preprint arXiv:2107.03374, 2021. https://arxiv.org/abs/2107.03374.
A Specification Types
All experiments include the natural-language task description and differ in the additional specification provided to the implementation agent. We consider the following specification types. (i) Task only: the implementation agent receives only the natural-language task description and no reference-derived artifact; (ii) Concrete Behaviors (EARS): individual end-to-end behavioral instances are written as event, condition, and response requirements; (iii) Generalized Behaviors (EARS): behavioral requirements are expressed as rules over classes of inputs rather than
EARS stands for Easy Approach to Requirements Syntax [25]; Python signature specifications use stub-style interfaces as described in PEP 484 [27]; local and global contract specifications build on Design by Contract [16]; and architecture specifications use established software-architecture documentation concepts [26].
individual examples; (iv) Behavioral Tests: generated executable tests encode end-to-end input-output behaviors; (v) Design (EARS): a prose design document describes the system architecture together with EARS behavioral requirements; (vi) Signature Specifications: the repository structure, modules, types, and callable signatures are preserved while behavioral contracts and implementation bodies are omitted; (vii) Local Contracts: signatures are augmented with behavioral contracts attached to individual functions and methods; (viii) Global Invariants: local contracts are augmented with agreements that must hold across multiple functions, methods, or modules; (ix) Architecture Specifications: a prose architecture document progressively adds components and boundaries, data models and state, collaborations, repository layout, and per-file sketches; and (x) Native Skeleton Specifications: for ProgramBench [13], the source-language file structure, declarations, types, callable signatures, and EARS contracts are preserved while implementation bodies are omitted.
A.1 Specification templates
To make the specification types concrete, this section shows a template for each artifact, instantiated on a small synthetic component written for illustration. The component is not drawn from any benchmark repository. It is a hypothetical library-lending module, booklend, with one class, Library, that tracks how many copies of each title are on the shelf and on loan. Every template concerns the same design decision: a successful loan reduces the number of available copies, whereas an availability query leaves it unchanged. Angle brackets mark the parts that differ between repositories.
(i) Task only. A natural-language description of the package, its features, and its public API, written as a user-facing README. It describes what the library does but not how it is organized.
# <package name>
## Problem and Purpose
<What the package is for and which problems it solves.>
## Features
- 'Library' records the number of copies of each title.
- 'lend(title, copies)' lends copies of a title to a reader.
- 'available(title)' reports how many copies can still be lent.
(ii) Concrete Behaviors (EARS). A numbered catalogue of end-to-end observations, each a single input and its expected output, written in EARS syntax (WHEN/IF ... THEN THE SYSTEM SHALL ...). Behavioral scaling experiments draw nested 25%, 50%, and 100% subsets of this catalogue.
# Behaviors: <package name>
<N> behaviors in <K> capability groups.
1. 'result' - WHEN Library holds 5 copies of "poems" and lend("poems", 2) is called THEN THE SYSTEM SHALL return True.
2. 'state' - WHEN Library holds 5 copies of "poems", lend("poems", 2) is called, and available("poems") is called THEN THE SYSTEM SHALL return 3.
3. 'state' - WHEN Library holds 5 copies of "poems" and available("poems") is called twice THEN THE SYSTEM SHALL return 5 both times.
(iii) Generalized Behaviors (EARS). The same catalogue size, but each entry quantifies over a class of inputs rather than naming one. Note the WHERE clause and the absence of concrete values.
state- WHERE a title has q available copies, WHEN lend is called with k <= q copies THEN THE SYSTEM SHALL reduce the available copies of that title to q - k.state- WHEN available is called for any title THEN THE SYSTEM SHALL leave the available copies of every title unchanged.
(iv) Behavioral Tests. Executable pytest functions against the public API only. Each test is the executable form of one concrete behavior.
def test_lend_reduces_available(): library = Library({"poems": 5}) assert library.lend("poems", 2) assert library.available("poems") == 3
def test_available_does_not_change Copies(): library = Library({"poems": 5}) assert library.available("poems") == 5 assert library.available("poems") == 5
(v) Design (EARS). A prose document in the requirements/design format: user stories with EARS acceptance criteria, followed by a design section describing components, behavioral rules, data models, and error handling in paragraphs.
Requirement <n>: <capability>
User Story: As a <role>, I want <capability>, so that <benefit>.
Acceptance Criteria
- WHEN a loan succeeds THEN THE SYSTEM SHALL reduce the available copies by the number lent.
- WHEN availability is queried THEN THE SYSTEM SHALL leave all copy counts unchanged.
Design
Components and Interfaces
- *<component>: * <responsibility, the state it owns, and the components it may call.>
(vi) Signature Specifications. The repository as a tree of .pyi stub files: modules, classes, attributes, and callable signatures with one-paragraph docstrings. Bodies are elided. This is the first level that fixes the internal representation.
class Library: ""Track available and lent copies per title."" _available: dict[str, int] _on_loan: dict[str, int]
def lend(self, title: str, copies: int) -> bool: ""Lend copies of a title if enough are available."" ...
def available(self, title: str) -> int: ""Return the number of copies of a title that can still be lent."" ...
(vii) Local Contracts. The same stubs, with each docstring extended by argument, return, and exception sections and an Ensures block of EARS post-conditions scoped to that callable.
def lend(self, title: str, copies: int) -> bool:
"""Lend copies of a title if enough are available.
Returns:
True if the loan succeeded, otherwise False.
Raises:
KeyError: If 'title' is unknown.
Ensures:
- WHEN the call returns True THEN THE CALLABLE SHALL reduce
'._available[title]' by 'copies'.
- WHEN the call returns False THEN THE CALLABLE SHALL leave all
copy counts unchanged.
""
...
(viii) Global Invariants. Local contracts plus a separate INVARIANTS.md file. Each invariant is an EARS statement that spans several callables, followed by the list of callables that must agree with it; the invariant is also cited from the docstrings of those callables.
# I<n> -- Lent and available copies stay consistent
WHEN any public method returns THEN THE SYSTEM SHALL keep, for every title,
the sum of its available and lent copies equal to the number of copies it owns.
Participants: Library.lend, Library.checkin, Library.available
(ix) Architecture Specifications. We illustrate the five architecture variants in Figure 6 using booklend. All variants accompany the task description. The first specifies component responsibilities and state ownership. Each subsequent variant retains the preceding sections and adds a different kind of information: the state representation and its invariants, the sequence of checks and updates, the repository layout, and finally the interfaces and requirements of individual files. Thus, the first variant includes only section 1 below, and the final variant includes all five sections.
## 1. Components and Boundaries
- Library manages an in-memory inventory and exposes lend and available.
- Library owns all mutable lending state. Callers use its public methods rather than modifying copy counts directly.
- Lending may change state; availability queries only read it.
## 2. Data Models and State
- _available maps each title to its number of available copies.
- _on_loan maps each title to its number of lent copies.
- Both mappings contain the same known titles and nonnegative counts.
- Initially, _available contains the supplied inventory and _on_loan contains zero for every title.
- For each title, available plus lent copies equals its initial inventory.
## 3. Collaborations
- A caller submits a title and copy count to Library.lend.
- lend validates the title and positive copy count before changing state.
- If stock is insufficient, lend returns False without changing state.
- Otherwise, lend decreases _available and increases _on_loan by the requested count, then returns True.
- available validates the title and reads _available; it changes no state.
## 4. Repository Layout
- booklend/_init_.py: exports the public Library class.
- booklend/library.py: defines Library, initializes its state, and implements lending and availability queries.
- The package entry point imports Library from library.py; library.py does not depend on the package entry point.
5. File Sketches
- booklend/init.py re-exports Library without creating an inventory.
- booklend/library.py defines Library(inventory), lend(title, copies), and available(title), with the two state mappings described above.
- WHEN lend returns True THEN THE CALLABLE SHALL reduce _available[title] and increase _on_loan[title] by copies before returning.
- WHEN lend returns False THEN THE CALLABLE SHALL leave all counts unchanged.
- WHEN available returns THEN THE CALLABLE SHALL return _available[title] and leave both mappings unchanged.
- IF a title is unknown THEN THE CALLABLE SHALL raise KeyError before changing either mapping.
(x) Native Skeleton Specifications (ProgramBench). For ProgramBench tasks, the skeleton is written in the source language of the task. It keeps the module tree, type declarations, trait or interface implementations, and function signatures with their documentation comments, and replaces every body with a placeholder. Module-level EARS contracts are placed in a specification file beside each directory. The template below is written in Rust.
/// <What the type represents and the invariants it maintains.> pub struct Library { available: HashMap<String, u32>, }
impl Library { /// <What the function does, its arguments, and its result.> pub fn lend(&mut self, title: &str, copies: u32) -> bool { unimplemented!("specification stub") } }
B SDDBench
SDDBench is a repository-level benchmark for evaluating specification-driven software development with coding agents. We derive its tasks from real Python libraries, with renamed packages and rephrased project descriptions to reduce direct recognition of the original projects. In our experiments, the agent reconstructs each library from a self-contained task description and the specification supplied by the experimental condition, without access to the reference implementation. Functional correctness is the fraction of tests passed in the corresponding project's evaluation suite, which is executed separately from the implementation. This setup isolates how the structure and behavioral detail of a specification affect reconstruction accuracy, implementation cost, and code quality. Since the underlying projects are public, anonymization reduces explicit identity cues but does not completely rule out training-data contamination.
| Real name | Anonymized name |
|---|---|
| Babel | LocaleFoundry |
| CacheControl | RequestsCachePro |
| cachetools | memokit |
| Click | CLIForge |
| icecream | debugwhisper |
| itsdangerous | cryptoseal |
| marshmallow | serializor |
| Mimesis | MirageMint |
| Parsel | DataHarvest |
| PySnooper | CodeTrail |
| statsmodels | StatWeaver |
| TinyDB | MicroVault |
| xarray | AxisAtlas |
C ProgramBench and SCBench
We evaluated 20 tasks from ProgramBench [13]: atlas, brotli, dropbear, dupl, fzf, go-mod-outdated, loop, luajit, ninja, nomino, revive, richgo, ripsecrets, rust-sloth, sd, solar, tty-clock, typst, xq, and xz. For our main SCBench [12] experiments, we evaluated reconstructions of each problem's final repository state.
D Experimental Details
Here we describe the details of the experiments in Section 4.1. We ran all experiments with the AI Functions framework (https://github.com/strands-labs/ai-functions). We used the models, specification formats, and metrics described in Sections A and 4. In Figure 1a, we evaluated four models on 20 ProgramBench tasks [13] (Section C). For each task, we held out approximately 25% of the eligible reference-passing tests for evaluation and used the remaining tests as the available pool. We gave each agent the task, reference-executable access, and nested 0/33.3/66.7/100% subsets of that pool, drawn with a fixed seed. We scored all conditions on the same held-out set. Thus, 100% on the x-axis means that all tests in the available pool were provided, while the evaluation tests remained withheld. In Figure 10, we used the same tasks and models to compare task-only input with prose in EARS format [25], original comments, signatures, local contracts, or global invariants. We retained reference-executable access in every condition and used reference source only for artifact generation. In Figure 2, we evaluated four models on 35 SCBench problems [12] and 13 SDDBench libraries (Section B). We supplied the task alone or one additional artifact, using full catalogues for behavioral conditions and withholding reference code and evaluation tests. In Figure 7, we measured erosion and verbosity on the same reconstructions using the SCBench metrics [12].
In Figure 6 (Right), we allowed the four models 20, 40, 80, or 160 reference-executable queries on ProgramBench, with or without a Global Invariants skeleton. We also supplied curated examples at matching counts or allowed uncapped querying. In Figure 6, we used five repositories from SCBench and four from SDDBench with four models. We reduced each architecture document to five nested versions covering components, state, collaborations, layout, and per-file sketches, and compared them with task-only input. We counted both task and architecture text in the input size.

Figure 9: Skeleton coverage vs. pass rates: (Left, Middle) We select a subset of the functions to add to the skeleton based on their complexity. Providing additional coverage increases pass-rate. (Right) Adding per-folder descriptions to a directory sketch improves the pass rates.
In Figure 9 (left, middle), we evaluated Sol and Luna on five repositories per benchmark. We ranked callables by complexity, retained nested 25/50/75% subsets of their local contracts, and compared these with task-only input and the full skeleton. We counted coverage by callable and scored reconstructions with benchmark tests. In Figure 5, we compared accuracy and implementation cost for the models and conditions in Figure 2. We priced input, output, cache-read, and cache-write tokens at fixed rates, excluding specification generation and evaluation compute. In Figure 8, we compared code-only and agent-maintained specification workflows on 20 ProgramBench task pairs, using Sol. We started both from the task and reference-executable access, disclosed new failing tests between rounds, and carried code and specifications into fresh conversations. We tracked error, model cost, and reference calls through round 8 and measured code quality at that point. For common maintainability, we combined source length, cyclomatic complexity, and Halstead volume.
E Proofs and remarks for Sections 2 and 3
Throughout, for a fixed skeleton , denotes the acceptable programs with skeleton , and the programs in that agree with the reference on every input tested in . Exact conditioning on gives
Also, the sum in eq. (3) is over canonical skeletons defined by a fixed map , with . These classes partition . A partial skeleton is treated as conditioning on the union of compatible canonical classes. Throughout, we condition only on events of positive probability, and omit zero-weight terms from the sum.

Figure 10: Value of different types of skeletons: Providing skeletons improves the pass-rates on ProgramBench despite query access to the oracle executable.
E.1 Proof of Theorem 2.1
Proof. Take inputs and the parity target . A program is acceptable exactly when it computes on every input. For , the two skeletons permit respectively
where the inner product is over . The first structure allows a joint exceptional branch; the second combines contributions by XOR. Each parameter setting has prior mass under each skeleton, the programs of each skeleton have distinct behaviors, and both skeletons implement the target exactly when .
In , each incorrect completion differs from the target only at , so all nonzero inputs must be tested to eliminate them. In , each test imposes . Inputs of rank leave candidates, so tests are necessary and the standard basis inputs suffice. Under either uniform prior, any suite leaving at least two candidates has posterior correctness at most , while a suite leaving only the target has posterior correctness one. Hence and .
For the second part, let consist of the tests at the standard basis vectors , which guarantee success under . Under , the test at eliminates only , so programs survive, one of them correct, and the success probability is . Now let put mass on each skeleton, uniformly within each. Under only survives, with prior mass ; under the survivors have total mass . Both surviving programs with are acceptable, so
The information supplied by the same labeled sample depends on the skeleton. Before any tests, fix a nonzero input and supply . Measuring information gain in bits by the posterior-to-prior KL divergence gives
(4)
Indeed, the posteriors are uniform on and survivors, respectively. Thus the same reference-labeled sample supplies only bits under , but one bit under . For comparison, under each skeleton let the unknown parameter be uniform and generate the response . The expected information gains are
where remains fixed and is binary entropy. The first response differs from with probability ; the second splits the prior equally between the two possible outputs. These mutual informations average over possible responses, whereas Equation (4) concerns the same observed response.
E.2 Proof of Theorem 2.2
Proof. For each , choose
This implements . The same architecture also implements , for example with every transition constant zero. Thus this small compositional class contains the singleton-indicator family [7].
Put prior mass 1/2 on the constant-zero implementation, which serves as the reference, and mass on the implementation above of each . Let , so that . Every test is labeled 0, so adaptive selection is no more informative than a fixed suite, and a test at input eliminates exactly the implementation of . For distinct tests,
Repeated inputs provide no additional constraint. Solving gives the lower bound on . For the bound equals , and testing every input suffices. Locally, four input pairs reveal the truth table of each transition under any prior, so 4n local tests identify every transition table.
Worst case without a prior. When all Boolean transition tables are allowed, the same construction shows that exact identification of requires end-to-end queries in the worst case, even with adaptive input selection: on a transcript consisting entirely of zero outputs, every unqueried input leaves indistinguishable from . Testing every input suffices for any composite behavior.
The system has only 4n unknown truth-table bits, but its endpoint can hide where a disagreement arose. In the construction, the state records whether every input bit seen so far matches a. After a mismatch, later stages keep the state at zero. An endpoint test then reveals neither which stage rejected the input nor what the other stages would do. A local test observes a component before subsequent transitions can erase its effect. Software testability theory describes this distinction through fault execution, infection of internal state, and propagation to an observable output [20]. Direct access to inputs and outputs improves a component's controllability and observability [21].
State merging permits this example; depth alone does not imply hardness. For comparison, if for both values of , every transition has the form . The composition is then affine over bits and is identified by the endpoint queries at and the standard basis vectors. The exponential result concerns exact behavioral identification and a specified prior: it does not establish a bound for every prior or for prediction at fixed nonzero error. Endpoint data need not identify the individual transition tables uniquely, even when they identify the composite behavior.
E.3 Proof of Theorem 2.4
Proof. Here is the minimum total number of local and end-to-end tests needed for posterior correctness one. All tests are answered by the fixed acceptable reference . Each minimum test count is when no finite suite suffices. For any classes containing the reference components and having finite costs, combine local suites excluding their complements with a joint suite excluding the unacceptable combinations that remain. All survivors belong to , and the reference survives with positive mass. This gives the upper bound.
Conversely, take any successful mixed suite, and let be the component implementations passing its local tests in slot . The number of those tests is at least . Its end-to-end part must exclude every unacceptable member of , since each such member has positive prior mass and passes all local tests. That part therefore costs at least . Minimizing proves equality, including the case in which no finite suite succeeds. The zero-cost characterization follows because, without joint tests, all of these combinations survive.
E.4 Proof of Proposition 2.3
Proof. The reference passes every test in , and we assume . Every member of also passes every test, so conditioning on leaves the relative weights within unchanged. Since , exact conditioning gives
If exceeds this ratio, no finite test suite attains the required posterior correctness, so .
E.5 Proof of Proposition 3.1
Proof. Each retry for component is an independent draw from the same distribution , with . Each check terminates and accepts exactly the implementations in . By independence, a whole program passes every check with probability , so the number of proposals is geometric with mean , and an accepted program is distributed as . Resampling component until it passes takes a geometric number of proposals with mean and returns a sample of . By independence, the accepted components are jointly distributed as .
E.6 Proof of Proposition 3.2
Proof. We retain the sampling assumptions of Proposition 3.1, with the checks specified in this proposition. All error rates are measured under the fixed proposal distributions; in particular, when , . The checker uses fresh randomness, independent across attempts and components. A violation of contract either is consistent with the docstring, with probability , and is then accepted, or is not and is accepted at rate ; this gives .
(i) Every implementation that satisfies the contract is accepted, so by Bayes' rule an accepted component satisfies its contract with probability . If or , this probability is one.
(ii) The accepted components are independent, so by (i) they all satisfy their contracts with probability , where . Since for and , the lower bound follows.
For the whole-program comparison in (ii), write . If , correctness is certain. Otherwise, let . As in (i), the accepted program satisfies every contract with probability
since . When , every accepted program satisfies all contracts.