What spec-first actually changes
Most coding agents begin with an implementation token. The prompt arrives, the model reaches for a file, and the first artefact is a plausible-looking function body. The specification — if one exists at all — is reconstructed afterwards from the diff, which means the thing being graded and the thing that was asked for are two different objects.
Spec-first inverts the order. The agent's first artefact is a contract: the interfaces it will expose, the invariants it must preserve, and the test cases that will decide whether the work is done. No implementation token is emitted until that contract exists as a reviewable file. The contract is short, declarative and written in the same repository as the code it governs.
This is a structural change to the trajectory, not a stylistic preference. Once the contract is on disk, acceptance stops being a reviewer's opinion formed at the end of a long diff. It becomes a predicate: does the implementation satisfy the stated interfaces, preserve the stated invariants, and pass the stated tests? A predicate can be evaluated by a harness without a human in the loop, and — critically — it can be evaluated the same way twice.
The second-order effect is where the value sits. When the contract is the first artefact, the harness has something to grade against before the expensive part of the run begins. Judgement moves upstream. A trajectory that would previously have failed at review time, after a full generation pass, can fail at the specification gate, after a fraction of the tokens and with a defect report that points at a paragraph rather than a diff.
Why this is an eval design choice
Treating specification as documentation misses the point. The reason to force a spec is that it gives the evaluation harness a fixed target.
Consider what a harness grades when there is no spec. It grades the diff against a rubric, and the rubric is prose. Prose rubrics drift: two runs of the same task produce different implementations, the grader weighs the differences slightly differently, and the resulting scores are not comparable across runs. You cannot tell whether a change to the agent improved it or whether the rubric moved under your feet.
A specification converts the rubric into an executable target. The interface list is checkable by parsing. The invariants are checkable by property tests. The test cases are checkable by running them. The harness no longer asks "is this good code?" — a question with no stable answer — but "does this code satisfy this contract?", which has a boolean answer that survives repetition.
Failures also localise, and localisation is the difference between a useful eval and a scoreboard. A wrong specification and a wrong implementation are different defects with different fixes:
- A wrong specification means the agent misunderstood the task. The fix is upstream — clearer task framing, a stronger gate, a better decomposition. Re-running the implementation will not help.
- A wrong implementation against a correct specification means the agent can express the contract but not satisfy it. The fix is downstream — more capable generation, tighter feedback from the test run, or a smaller unit of work.
Collapsing both into a single pass/fail number hides which of these is happening, and the two demand opposite interventions. Spec-first makes the distinction visible in the trajectory record.
The failure modes
Spec-first is not self-enforcing. Two failure modes appear reliably, and both are worth instrumenting against explicitly.
Spec capture. The model writes a specification that matches what it can build, rather than what was asked. This is the subtle one, because the resulting artefact looks like diligence. The contract is coherent, the tests pass, the implementation is faithful — and the whole thing quietly solves an easier problem than the one in the prompt. The agent has not failed to follow instructions; it has redefined success to something within reach. Detection requires comparing the spec against the original task framing, which is a separate grading step and must be built as one. Without it, spec capture reads as a clean run.
Specification debt. Agents generate plausible contracts that nobody reviews, and then implement against them faithfully. The faithfulness is the problem: a wrong contract executed precisely produces confidently wrong code, and the tests written from the same wrong contract will confirm it. The suite is green, the interface is stable, and the behaviour is incorrect. This is worse than no spec, because the spec supplies false assurance — the reviewer sees a contract and a passing suite and stops looking.
The honest trade-off is here. Forcing a specification gate costs latency and human attention on every task, including the trivial ones where the contract is obvious and the review is ceremony. It also creates a new class of artefact to maintain: specs that go stale as requirements move, and that then mislead the next run. Teams that adopt spec-first without budgeting review time for the spec itself are not running an eval — they are generating documentation that happens to be executable.
A working method
The method that holds up under both failure modes has two parts: a human gate on the contract, and a single trajectory record for everything that follows.
Gate the spec, then release the agent. The specification artefact requires explicit human sign-off before generation begins. Sign-off is a state transition in the pipeline, not a comment in a thread — the run does not proceed until the contract is approved. Once approved, the agent runs unconstrained against it: no incremental hand-holding, no per-step review. The constraint lives in the contract, and the contract has already been judged. This is the whole point of moving judgement earlier. You spend human attention once, at the cheapest point in the trajectory, and then let the machine work without supervision against a fixed target.
Store one record per run. Spec, implementation and test results belong in a single trajectory record, keyed so that a regression replays cleanly. Concretely, the record holds the approved contract, the prompt and context that produced it, the generated implementation, the test output, and the harness verdict — all versioned together. When a later run regresses, you replay the stored record and see exactly which of the three moved: the contract, the code, or the environment. Without that coupling, a regression is a diff you have to re-investigate from scratch; with it, the regression is a lookup.
A sketch of the record shape:
{
"run_id": "...",
"task": "...",
"spec": { "interfaces": [], "invariants": [], "tests": [] },
"spec_approved_by": "gate",
"implementation": "...",
"test_results": { "passed": 0, "failed": 0 },
"verdict": "pass"
}
The fields that matter most are the ones that make the two failure modes legible. spec_approved_by records that a human gate was crossed, which is what distinguishes a reviewed contract from specification debt. Keeping spec and implementation in the same record is what makes spec capture detectable after the fact: the contract can be diffed against the task framing without reconstructing the run.
What this buys, and what it costs
Spec-first coding is an evaluation instrument. It moves the harness's judgement to the earliest point in the trajectory where a decision is still cheap, and it converts acceptance from a reviewer's impression into a predicate the machine can check on every run. It makes failures localise, because a wrong contract and a wrong implementation are now visibly different events.
The cost is real: a gate on every task, human attention on artefacts that are sometimes obvious, and a maintenance burden for specifications that drift. The failure modes — capture and debt — are not eliminated by the method, only made visible and instrumentable. That is the correct ambition. An eval that shows you where the agent went wrong, and whether the fault was in the asking or the building, is worth more than a green suite that confirms a contract nobody read.