Docs First: Why AI Agents Need a Spec Before They Touch the Code


AI coding agents fill every gap in your docs with a guess. What a good spec includes, why it belongs in the repo, and how it changes code review.
Give an AI coding agent a task and a codebase, and it will finish the task. The question is what it does with everything nobody told it.
In our experience, the answer is always the same. Wherever the docs say nothing, the agent makes something up.
It does not do this carelessly. It fills the gap with the most likely answer, the pattern it has seen a thousand times in other projects. The trouble is that your product is not other projects. The most likely answer is often a reasonable one, and still wrong for you.
This post is our view on why a written spec matters more with agents than it ever did with people, what a good one includes, and how it changes code review.
Why AI Agents Make Things Up Where the Docs Are Silent
A new developer who hits a gap asks someone. An agent rarely does. It is built to keep going, so it decides.
Every unanswered question becomes a guess. Should a refund cancel the order or only the payment? Can a guest see an order without logging in? What happens when a background job fails halfway? If the answer is not written down or obvious from the code, the agent picks one. Sometimes it picks well.
Guesses look like decisions. The code that comes back is clean, tested and confident. Nothing in the diff says "I invented this rule". The guess is now a feature, and nobody chose it.
Guesses multiply. Run several agents on several tasks and each one fills the same gap differently. One treats a cancelled order as refundable, another does not. Both pass their tests, because each wrote tests for its own assumption.
The code cannot explain what it does not contain. Agents are good at reading code. But code only shows what the system does, not what it is supposed to do, what is deliberately left out, or why. Those are exactly the questions agents get wrong.
None of this is a model problem that the next release will fix. A smarter model makes better guesses. It still guesses.
A Spec Is Not a Prompt
There is an easy mistake here. "Agents need more context" can turn into longer prompts, bigger instruction files and growing lists of rules. We think that makes things worse. Long instructions compete with each other and with the code, and the agent ends up following the noise.
A spec is different. It does not tell the agent how to behave. It describes the product: what it is, how it works and what must stay true.
Instructions age badly, descriptions don't. "Always use the payment helper" is a rule someone has to remember to update. "A paid amount must match the order total, and a mismatch is reconciled, never ignored" is a fact about the product. Agents and people can both check code against it.
It serves people first. A good spec is the same document a new engineer, a product owner or a client would read. If it only makes sense to an agent, it is a prompt in disguise.
It is short on purpose. A spec that covers everything is too long to read and too long to keep true. Write down what an agent would otherwise guess. Skip what the code already makes obvious.
What a Good Spec Includes
Here is what we recommend putting in writing before agents start building, or as early as possible on an existing product.
Purpose and users. What the product does and for whom, in a few paragraphs. This is what lets an agent make sensible small decisions, like the tone of an error message or which edge case matters.
User journeys. The main paths through the product, step by step. Agents build screens one at a time. Journeys are what keep those screens adding up to one flow.
The data model and its states. The main entities, how they relate, and the lifecycle of anything with a status. Orders, payments and subscriptions are where invented states do the most damage, because they end up in the database.
Rules that must always hold. The handful of things that can never be wrong: how money is calculated, who can see what, what happens on a failed payment. These are the first thing to check in review and the first thing to test.
Boundaries and contracts. Where one part of the system ends and another begins, and what crosses the line. Which service owns which data, what an API promises, what a webhook carries. Agents working on two sides of a boundary need the same contract.
What is out of scope. The features you decided not to build, and why. Without this, an agent will helpfully add them.
How to verify. How you will know each part works. If you cannot say how you will check something, an agent cannot either.
This is not a hundred-page document. For most products it is a handful of short files, each covering one area, written in plain language.
Keep the Spec in the Repository
A spec in a slide deck or a shared drive is a spec agents never read, and one that goes out of date the week after it is written.
Put the docs next to the code. Agents read the repository. If the spec is there, it is part of what they see, without anyone pasting it into a prompt.
Change docs and code together. A change that alters how the product behaves should update the spec in the same pull request. If the doc and the code disagree, one of them is a bug.
Delete what is no longer true. A stale spec is worse than none, because agents believe it. Removing an outdated section is as valuable as writing a new one.
Link, don't repeat. Each fact should live in one place. When the same rule is written in three files, one of them will drift, and an agent will find that one.
How a Spec Changes Code Review
When agents write most of the code, review becomes the main job of the engineer. A spec changes what that job looks like.

Review against the spec, not against taste. Without a spec, a reviewer has to work out what the change was supposed to do and then whether it does it. With one, the first question is quick: does this match what we wrote down?
Guesses become visible. When a change introduces a rule the spec does not mention, that is the moment to stop and ask. Either the spec missed something, or the agent made it up. Both are worth knowing before merge.
Disagreements turn into edits. Arguments about how something should work end with a change to the spec, not a comment thread nobody finds again. The next agent and the next reviewer both benefit.
AI reviewers get better too. An AI reviewer pointed at the spec can check a change against written rules instead of general best practice. That turns vague suggestions into concrete findings.
Reviewing a spec is cheaper than reviewing code. A wrong assumption caught in a one-page doc costs minutes. The same assumption caught after agents built three features on top of it costs days.
We have written before about why AI projects fail, and unclear requirements were a big part of the story long before agents. Agents just make the cost show up faster.
The Spec Is Where the Thinking Goes
Agents have made writing code cheap. They have not made deciding what to build cheap, and they never will.
That decision has to live somewhere. If it lives in a spec, agents follow it, reviewers check against it and clients can read it. If it lives nowhere, agents invent it, one guess at a time.
Write the spec first. The code will follow faster than you expect. If you are planning a product and want help with both, see how we approach web and mobile apps.