Spec-driven development
Write down what done looks like before the agent starts. The spec is what you review, and the tests are how you check it.
Words on this page (1)
- agent
- : A model run in a loop that chooses its own tools and steps until the task is done.
What it is
You describe the behavior, constraints and acceptance checks in a short document. The turns it into a plan, then code. When it goes wrong, you fix the spec or the checks, not the generated code by hand. Google's framing is the same: define success with tests and automated checks first, then let the agent work, then verify.
Why it works
Most agent failures are underspecified tasks. A spec forces the missing decisions to surface while they are cheap. It also gives a stable document to hand to a fresh agent after a context reset. Keep specs small and testable. A spec nobody can verify is a wish.
A worked example: a tiny spec
Feature: password reset by email. Behavior: user enters email, receives a link valid for 30 minutes, link works once. Edge cases: unknown email shows the same message as a known one, so attackers cannot discover accounts. Checks: a test for expired links, a test for reuse, a test for unknown email. The agent now knows what done means.
How a spec guides the agent
The agent works from the text it is given. A vague request leaves gaps, and the model fills each gap with the most likely choice, which may not be yours. A spec closes the gaps in advance. The usual flow is a short chain.
- Write the behavior and the checks.
- Ask the agent for a plan from the spec and read it.
- Let it implement in steps, running the checks.
- When something is wrong, edit the spec, not the code.
Step 4 keeps the spec as the source of truth. If you patch the code by hand, the next agent run will undo your change or contradict it.
A second example: when a spec is too much
You want a button to change colour. Writing a spec with edge cases would take longer than the change itself. Skip it. A spec pays off when the feature has rules that are easy to get wrong, such as money, permissions or time limits, or when several people or agents will touch it. Equally, a spec cannot capture everything: for a visual design, you may only know it is right when you see it. In that case iterate with the agent and look at the result.
What goes wrong
Vague words are the main failure. "Fast", "secure" and "user-friendly" cannot be tested. Replace them with something measurable, such as "the page responds in under one second on the test data". Another failure is a spec that contradicts itself, which shows up as the agent asking questions or making an arbitrary choice. A third is checks that pass without testing anything, such as a test that always succeeds. To confirm a test has value, break the code on purpose and see whether it fails.
Try it yourself
Choose a small feature, such as a function that checks whether a password is strong enough.
- Write five lines of rules, each testable.
- Ask the agent to write tests from the rules before any code.
- Break one rule in the code and watch a test fail.
Expect to find at least one rule that was ambiguous when you tried to write its test.
Common mistake
Specs nobody can check. If you cannot say how you would test a line, rewrite the line.
A builder starts a house with a sketch on a napkin and discovers on day 30 that the staircase has nowhere to go. Another starts with a floor plan that shows where every wall, door and stair lives. Writing the spec first is the floor plan. The agent builds faster and you spot the staircase problem in minutes, not weeks.
Check yourself
The agent built the wrong thing. What do you fix first?
Not quite. If the spec was ambiguous, a better spec fixes the cause instead of the symptom.
What makes a spec useful?
Not quite. A spec you cannot verify cannot tell you when the agent is done.
A spec says "make the reset flow secure". What is wrong with it?
Not quite. Say what to test, such as "a reset link works once and expires after 30 minutes".
You got 0 of 3 right.
Go deeper
- Repo
GitHub · Toolkit for spec, plan and task workflows with coding agents.
- Course
DeepLearning.AI and JetBrains · Short course on constitutions, specs and plan, implement, verify.
- Article
Google Research · Verifiable specifications as the first stage.
Spotted a mistake or something unclear? Report it on GitHub.