Specifications before building with AI: writing a spec the tool will understand

AI tools write code very fast. That is exactly why they can also go wrong very fast: without a specification, they fill every gap with a guess, and every guess becomes code that has to be changed later. Specification did not disappear in the age of AI. It moved from the document to the start of the conversation.

In short

All the leading tools now recommend the same order: specification first, code second. Claude Code has a plan mode in which it only reads and plans; Lovable has a Plan mode that writes a plan before touching code; GitHub has Spec Kit, which separates what the user needs from how to build it. A good spec for an AI tool contains scope and what is out of scope, user stories with acceptance criteria, a data model, roles and permissions, and how to verify that it works. The tools do not ask for roles and permissions, and that is exactly where vulnerabilities are born.

Why does AI need a specification more than a person does?

A human developer who does not know something asks. An AI tool carries on. It picks the most likely guess and builds a screen, a table and an API on it. When the guess turns out wrong, three layers already sit on top of it.

There is also the opposite problem: the tool does exactly what it was asked to do. If the request says an orders list, it builds an orders list. If it was not written that a user must not see other people's orders, it will not be built.

A spec for an AI tool is not a longer document. It is a more explicit one. Everything a person would understand from context has to be written down.

What do the tools themselves recommend?

ToolWhat it recommends before the code
Claude CodeA plan mode in which the tool only reads and plans. For large features, the documentation suggests letting the tool interview you and write a SPEC.md file, then running the implementation in a fresh session. According to the documentation, a good spec names the files and interfaces involved, states what is out of scope, and ends with an end-to-end verification step.
LovableA Plan mode that writes a plan before any code: key decisions, assumptions, components, data model, and implementation order. It is recommended for large changes and for database design.
CursorProject rule files that the tool reads on every request: conventions, architecture, and what not to do.
GitHub Spec KitA chain of specification, plan, and tasks. The specification describes what users need and why, without referring to technology. Every ambiguity is marked, and none should remain unresolved at the end.
KiroThree files: requirements with acceptance criteria, a design with architecture and data flow, and trackable tasks

What belongs in the specification?

  1. What the product is and who it is for. One sentence: who the user is, what problem they have, what the main action is.
  2. Scope and what is out of scope. What we are building now and, just as explicitly, what we are not. Without the second list, the tool will expand the scope on its own.
  3. User stories with acceptance criteria. In a testable form: given a state, when the user takes an action, then the system responds like this.
  4. Data model. Entities, important fields, and the relationships between them. This is the part that is most expensive to change later.
  5. Roles and permissions. Who can see what, who can change what, and what happens when someone tries to open something that is not theirs.
  6. Integrations. Which external systems are involved, what passes between them, and which system is the source of each field.
  7. How we verify. At least one end-to-end scenario for each capability, including a user trying to do something forbidden.

The full structure, section by section, with a sample permissions table and a sample acceptance criterion: software specification template.

If the system itself contains a model that makes decisions, the spec needs two more sections: what the system decides and what it only suggests, and what happens when it is unsure. Details in systems requirements analysis.

What do the tools leave out of the spec?

None of the tools' guides gives roles and permissions its own section in the spec. The closest is Lovable, with signed-in and signed-out states. This is not a detail: a vulnerability that lets any user read other users' data is one of the most common problems in apps built with AI. What an audit of such code checks: security audit for AI-generated code.

So in the specifications we write, permissions are a mandatory section with a table: role, what it can see, what it can change, what is forbidden. And every forbidden row has a test scenario.

How does it work in practice?

  1. A requirements conversation: what the business needs, who the users are, and which data is involved.
  2. A written specification in a format the tool can read: scope, stories, data, permissions, checks.
  3. The tool plans from the specification, and a person reviews the plan before any code is written.
  4. The implementation is checked against the acceptance criteria, including the forbidden scenarios.
  5. Before real users come in, the system goes through the prototype to production checklist: code, secrets, access, data, payments and monitoring.

The specification stays alive: when a requirement changes, it changes in the spec first and in the code second. Otherwise, a month later, the spec describes a different system.

What does a permissions section look like?

A good permissions section is a table: for each role, what it can see, what it can change and what is forbidden. This is how it looks for a small orders app:

RoleCan seeCan changeForbidden
CustomerTheir own orders onlyDelivery details on an open orderSeeing or opening another customer's order, including by changing the number in the URL
StaffAll orders of their branchOrder statusDeleting an order, seeing full payment details
ManagerAll ordersEverything, including refundsTaking an action that is not written to the log

Every forbidden row gets a test scenario. For the first row:

Given customer A is signed in, when they open the URL of customer B's order (for example, change /orders/1042 to /orders/1043), then the system returns "not found", reveals nothing about the order, and logs the attempt.

This is exactly the vulnerability that ranks first in the OWASP API Security Top 10, under the name Broken Object Level Authorization. In apps built on Supabase, as many Lovable projects are, these permissions are enforced by Postgres Row Level Security policies. A table without such a policy is open to anyone who holds the project's public key.

Where do you keep the spec so the tool reads it?

In a file inside the project, not only in the chat. A chat ends; a file stays, goes into version control and is read again in every session. Each tool expects it in a different place:

ToolWhere the spec lives
Claude CodeA CLAUDE.md file at the project root, which the tool reads at the start of every session, plus a spec file for each large feature, such as SPEC.md
CursorRule files in the .cursor/rules folder
LovableThe project Knowledge, standing instructions the tool receives with every request, and Plan mode for large changes
GitHub Spec Kitspec.md, plan.md and tasks.md in a separate folder for each feature
Kirorequirements.md, design.md and tasks.md in the .kiro/specs folder

Which mistakes keep recurring in specs for AI tools?

  1. Describing screens instead of data. "A page with a customers table" instead of the customer entity, its fields and who can see it. The tool builds a nice screen on top of an accidental data model.
  2. "The admin can do everything" without a list. The tool does not know what "everything" means, and sensitive actions such as deletion and refunds are left without control.
  3. Secrets in the spec or in the prompt. API keys are not written in the spec, nor in code that runs in the browser. The spec says where they are kept: in environment variables or a secrets manager.
  4. Changes made only in the chat. An instruction given in chat that never reached the file disappears in the next session, and the tool goes back to the previous version.
  5. No out-of-scope list. The tool adds features nobody asked for, and each one is more code to test and maintain.

Frequently asked questions

Do you need a specification when working with Lovable or Claude Code?

Yes, even more than usual. An AI tool fills every gap with a guess and builds code on top of it. The tools themselves recommend planning before coding: Claude Code has a plan mode, and Lovable has a Plan mode.

How is a spec for an AI tool different from a regular one?

It has to be more explicit: everything a person would infer from context, such as who can see what, has to be written down. And it has to be in a format the tool can read, with testable acceptance criteria.

What is the most important part of the specification?

The data model and permissions. A wrong data model is the most expensive thing to change later, and permissions that were never written are one of the most common sources of vulnerabilities in apps built with AI.

What is spec driven development?

An approach in which the specification is written before the code, and the plan and tasks are derived from it. GitHub Spec Kit and Kiro are built around it, and Claude Code and Lovable support it through their planning modes.

Who writes the specification, me or the tool?

Both of you. The tool can interview you and draft it, but the decisions, especially who is allowed to do what, have to be made by a person who knows the business.

How long should a spec for an AI tool be?

Long enough to cover the seven sections, and no longer. For a small feature that is usually one page; for a whole system, one document for the overall structure and a short spec per feature. What matters is how explicit the spec is, not how long.

Where do you keep the spec so the tool reads it?

In a file inside the project, not only in the chat: CLAUDE.md and a spec file in Claude Code, rule files in .cursor/rules in Cursor, the project Knowledge in Lovable, and the spec folders of Spec Kit and Kiro. A file survives between sessions and goes into version control.

What do you do when the tool drifts from the spec?

Stop and find where the gap is: in the spec, in the plan or in the code. If the spec was unclear, fix it first, and only then ask the tool to fix the code. A fix made in chat without updating the spec comes back as a bug the next time the tool touches that area.

Where to start

Write one sentence explaining what the product is and who it is for, then list the roles in the system and what each one is allowed to see. Every good specification starts with those two lines.

Talk to us

Related: Software specification template, Prototype to production: a checklist, Vibe-coded projects

SLAtech LTD