Applied AISpec-driven developmentProductivityQualityProgramming

Spec-driven development with AI: write the spec, let the AI implement

Pablo Alcalde García

Anyone who programs with AI assistants soon discovers a pattern: the quality of the result depends almost entirely on the clarity of what you ask for. If you describe the task in one vague sentence, you get plausible but unreliable code. If you describe precisely what it must do, what it must not, and how it will be checked, the result improves dramatically.

Spec-driven development turns that observation into a method: first write the specification, then implement (with AI help) and verify against it. It is, in essence, what good teams have always done, but now with a huge incentive to do it well.

Why it works especially well with AI

  1. It reduces ambiguity. A model fills gaps with assumptions; a spec closes the gaps.
  2. It makes review easier. You review “does it meet the spec?” instead of “do I like this code?”.
  3. It is verifiable. The acceptance criteria become tests.
  4. It outlives the code. The spec documents intent, which is what gets lost over time.
  5. It lets you iterate cheaply. Changing a paragraph of the spec is cheaper than rewriting code.

What a good specification must contain

You don’t need a 30-page document. One well-thought-out page is enough.

  1. Context and goal: what problem it solves and for whom.
  2. Scope: what is in and, above all, what is NOT in.
  3. Expected behaviour: use cases and main flows.
  4. Edge cases and errors: what happens with empty data, duplicates, network failures.
  5. Technical constraints: stack, conventions, performance, security.
  6. Acceptance criteria: a checkable list of “this is done when…”.

A template ready to copy

# Spec: <feature name>

## Context
<Why this exists, who uses it, what problem it solves>

## Scope
- Includes: ...
- Does not include: ...

## Behaviour
1. When the user ..., the system ...
2. If ..., then ...

## Edge cases
- Empty input: ...
- User without permissions: ...
- External service failure: ...

## Constraints
- Stack: ...
- Project conventions: ...
- Security: don't log personal data, validate inputs, ...

## Acceptance criteria
- [ ] ...
- [ ] ...
- [ ] Tests cover the edge cases

The workflow

1. Write the spec (you, with help if you want)

You can ask the AI to ask you questions to fill gaps before writing it:

I'm going to implement [feature]. Before writing code, ask me the questions
needed to complete a specification: edge cases, errors, permissions,
performance. Don't propose code yet.

2. Review the spec

It is the cheapest and most profitable review. A design mistake here costs minutes; in code, hours.

3. Ask for the tests first

With this specification, write the tests that would verify each acceptance
criterion. Don't implement yet.

Check that the tests make sense and that they fail (there is no implementation yet).

4. Implement in small steps

Ask for the implementation in parts, running the tests after each. If something fails, fix the spec or the code, but don’t let them diverge.

5. Verify against the spec

Before calling anything done, go through the acceptance criteria one by one.

A short example

Spec (excerpt): “A user can request a call. They must provide a valid name and phone number. If the email already exists in the last 24 h, a duplicate request is not created and a notice is shown.”

Derived test (Vitest):

import { describe, it, expect } from 'vitest'
import { requestCall } from './requestCall'

describe('requestCall', () => {
  it('rejects invalid phone numbers', async () => {
    const r = await requestCall({ name: 'Ana', phone: 'abc' })
    expect(r.ok).toBe(false)
  })

  it('does not duplicate requests within 24 h', async () => {
    await requestCall({ name: 'Ana', phone: '600000000', email: 'a@x.com' })
    const r = await requestCall({ name: 'Ana', phone: '600000000', email: 'a@x.com' })
    expect(r.duplicate).toBe(true)
  })
})

The spec produced the test cases almost on its own; the AI completes the implementation.

How it fits in your repository

Keep the specs in the repository (for example, docs/specs/) and reference them in pull requests. A project instructions file with conventions and commands helps the AI respect them; I explain it in documenting projects with AI.

When you DON’T need a spec

  • Trivial changes (renaming, tweaking styles).
  • Exploration and quick prototyping, where you don’t yet know what you want (vibe coding).

The rule: the more expensive a mistake is, the more precise the spec must be.

Conclusion

AI doesn’t remove the need to think about what to build; it makes it more important, because now implementing is cheap and specifying badly is what is expensive. Writing a good spec, verifying it with tests and reviewing against it is the most reliable way to get the most out of code assistants.

More practices in integrating AI into your workflow. If you want to adopt this method in your team, let’s talk.

Call me now