>_ Analyst Engineering

Spec-Driven Development for Analysts: From API Contract to a Spec an AI Agent Can Build From

Written by Ahmed at Analyst Engineering, a Senior Technical Business Analyst with 10+ years in banking and payments delivery.

Cover for a guide to spec-driven development for analysts: from an API contract, to open questions, to traced acceptance criteria, to the spec an AI coding agent builds from.

Key takeaways

  • Spec-driven development makes a written specification, not the chat prompt, the source of truth for an AI coding agent: the agent plans, breaks down tasks, and writes code from the spec, and the spec is versioned with the code.
  • In spec-driven development the agent fills every gap in the spec with a plausible guess, so the analyst's job is to find and decide the gaps before the agent does.
  • A spec an agent can build from has four parts: decided rules with a source, what is out of scope, what the agent must never invent, and open questions marked as needing clarification with an owner.
  • Every acceptance criterion in a spec-driven workflow should trace to a field or a response code in the contract, so a reviewer can reject any agent output that has no source.
  • The five inventions to reject in agent output are new status values, silent defaults, rounding instead of rejecting, idempotency rules nobody decided, and retry or timeout numbers nobody agreed.

Spec-driven development is a way of building software with AI coding agents where a written specification, not the chat prompt, is the source of truth: the agent reads the spec, plans, breaks the work into tasks, and writes the code, and the spec is versioned next to that code. For an analyst this changes one thing that matters. The agent fills every gap in the spec with a plausible guess, so whoever decides the gaps decides what gets built. This guide shows how to do that on a real artifact: a payment API contract turned into open questions, traced acceptance criteria, and the spec an agent builds from without inventing.

The method underneath is the same one I use for any vague requirement: decode it, decompose it, define each rule, validate it with the owner. The full five-phase version, with the 16-field spec template and a banking example, is in From Vague Business Requirement to Functional Requirements.

What is spec-driven development?

Spec-driven development (SDD) inverts the usual relationship between the document and the code. In a chat-driven workflow the prompt is thrown away and the code is the only record of what was decided. In SDD the spec is kept, reviewed, and changed first; the code is regenerated or updated from it.

Two public toolchains show the shape:

  • GitHub Spec Kit, an open-source toolkit that works with several coding agents. It walks through specify (what and why), plan (the technical approach), tasks (a reviewable task list), and implement. Its templates mark anything ambiguous as needing clarification instead of letting the agent pick.
  • AWS Kiro, an IDE that keeps three files per feature: requirements.md, design.md, and tasks.md. Requirements are written in the EARS pattern: WHEN a condition, THE SYSTEM SHALL a response.

Neither tool decides what the system should do. They make the decision visible, which is why SDD puts the analyst back at the front of the pipeline.

What does the analyst own in a spec-driven workflow?

StepWhat the agent doesWhat the analyst owns
SpecifyDrafts a spec from a feature descriptionEvery rule, its source, and every open question
ClarifyAsks about the ambiguities it detectsAnswers, with the owner who decided each one
PlanProposes architecture and data modelChecks the plan covers every rule and adds no behaviour
TasksBreaks the plan into stepsChecks each acceptance criterion maps to a task
ImplementWrites the code and testsReviews the output against the spec, rejects inventions

The agent is fast at every column on the left. It cannot know which answers in the right-hand column are true for your bank, your customers, and your regulators.

How is this different from requirements as code or a user story?

Requirements as code is about storing requirements as validated records with stable IDs. User story versus specification is about when a story stops being enough. SDD uses both: the spec is the specification, stored in the repository, and what is new is the reader. The first reader is now an agent that will act on every sentence immediately and treat every silence as permission. That changes how you write: more explicit prohibitions, more explicit open questions, and a source on every rule.

Worked example: a payment contract to a spec an agent can build from

The input is a slice of an OpenAPI contract for creating a payment. It is realistic and, like most contracts, incomplete.

paths:
  /payments:
    post:
      summary: Create a payment
      parameters:
        - name: Idempotency-Key
          in: header
          required: true
          schema: { type: string, maxLength: 64 }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [amount, currency, debtorAccount, creditorAccount]
              properties:
                amount: { type: string, pattern: '^\d{1,15}\.\d{2}$' }
                currency: { type: string, enum: [CAD, USD] }
                debtorAccount: { type: string }
                creditorAccount: { type: string }
                remittanceInfo: { type: string, maxLength: 140 }
      responses:
        '201': { description: Payment received, status RECEIVED }
        '409': { description: Idempotency-Key reused with a different body }
        '422': { description: Validation failed }

Step 1: What does the contract not say?

Read for silence before reading for content. Each silence becomes a question with an owner, because a question with no owner is the one the agent answers for you. How to read a contract this way is in reading an API contract.

#The contract does not sayWhy it mattersOwner
Q1What a replay with the same key and the same body returnsClients retry after timeouts; a second payment is a real lossArchitecture
Q2How long an idempotency key is keptStripe documents that keys can be removed after at least 24 hours; yours needs a numberArchitecture
Q3Whether insufficient funds is a 422 now or an asynchronous rejection laterChanges the customer message and the status lifecyclePayments operations
Q4Whether the caller must own debtorAccount, and which code applies if notA missing 403 is a security gap, not a detailSecurity
Q5What happens after RECEIVEDThe agent will invent statuses if none are listedProduct
Q6Whether remittanceInfo passes through unchanged downstream140 characters matches unstructured remittance in ISO 20022; any system in between with a shorter field truncates itPayments operations

Q6 is the kind of gap that reaches production quietly. The pattern is covered in ISO 20022 data truncation.

Step 2: Which stories and acceptance criteria does the contract support?

Write criteria only for what the contract or a decided answer supports, and tag each one with its source. The tag is what lets a reviewer reject agent output later.

@source:POST-payments-201 @source:Q1
Scenario: A retried request with the same key does not create a second payment
  Given a payment was created with Idempotency-Key "k-123" and amount "250.00"
  When the same request is sent again with Idempotency-Key "k-123"
  Then the response is 201
  And the response body has the same payment id as the first response
  And only one payment exists for Idempotency-Key "k-123"

@source:POST-payments-409
Scenario: A reused key with a different body is rejected
  Given a payment was created with Idempotency-Key "k-123" and amount "250.00"
  When a request is sent with Idempotency-Key "k-123" and amount "300.00"
  Then the response is 409
  And no new payment is created

@source:POST-payments-422 @source:schema-amount-pattern
Scenario: An amount with three decimals is rejected, not rounded
  When a payment is created with amount "250.005"
  Then the response is 422
  And the error names the field "amount"

Stripe’s public API follows the same idea: it documents 409 for a request that conflicts with another one using the same idempotency key. The full test set for retries is in idempotency testing, and the wider criteria discipline for AI features is in acceptance criteria for AI systems.

Doing this by hand for a 60-page contract is a week of copying. The free Contract to User Stories + Acceptance Criteria engine generates the first draft of stories, Gherkin criteria, and a traceability matrix from an OpenAPI file, with every rule tied to a field or response code, so your time goes into the questions in Step 1 rather than the typing.

Step 3: What does the spec the agent receives look like?

The spec has four parts. The third is the one most analysts leave out, and it is the one that does the most work with an agent.

# Spec: Create payment (POST /payments)

## Decided rules
- R1  amount is a string with exactly two decimals; anything else is 422. (schema)
- R2  currency is CAD or USD; anything else is 422. (schema)
- R3  same Idempotency-Key and same body returns the original 201 and payment id. (Q1, Architecture, 2026-11-10)
- R4  same Idempotency-Key and different body returns 409; nothing is created. (contract)
- R5  a new payment has status RECEIVED. (contract)

## Out of scope
- Scheduled and recurring payments.
- Currency conversion.

## Must not invent
- Any status other than RECEIVED. Later statuses are an open question (Q5).
- Any error code not listed in the contract.
- Default values for missing required fields.
- Retry counts, timeouts, or key retention periods.
- Truncation or trimming of remittanceInfo.

## Open questions
- [NEEDS CLARIFICATION] Q2 key retention period. Owner: Architecture.
- [NEEDS CLARIFICATION] Q3 insufficient funds: sync 422 or async rejection. Owner: Payments operations.
- [NEEDS CLARIFICATION] Q4 debtorAccount ownership check and status code. Owner: Security.

## Acceptance criteria
features/create-payment.feature (every scenario tagged with its source)

The “Must not invent” list reads as obvious to a human and is not obvious to an agent. An agent asked to build a payment endpoint knows that payment systems usually have more statuses, retry policies, and defaults, so it adds them. Each addition is reasonable, and none was decided. How to make the agent read this file on every run (CLAUDE.md, AGENTS.md, plan mode) is in agentic coding for analysts.

Step 4: What should you reject in the agent’s output?

Review the plan before the code, then the code against the spec. These five inventions appear on almost every first pass:

  1. A new status value. A PENDING_REVIEW or PROCESSING status nobody listed. It looks helpful and creates a lifecycle no one has tested. See state machines for payments for what a decided lifecycle looks like.
  2. A silent default. Currency defaulted to CAD when missing, instead of a 422.
  3. Rounding instead of rejecting. 250.005 stored as 250.01. In payments this is a reconciliation break waiting to happen.
  4. An idempotency rule nobody decided. Keys scoped per user when the spec says per client, or a replay with a different body treated as success.
  5. Invented operational numbers. Three retries, a 30 second timeout, 7 days of key retention. Plausible, undecided, and now in production.

The check is mechanical: every behaviour in the diff must point to a rule ID or a scenario tag. Anything without a source is either a missing rule (add it to the spec, with an owner) or an invention (remove it).

Step 5: How do you prove coverage with a traceability matrix?

Contract elementRuleAcceptance criterionTestStatus
amount patternR1three decimals rejectedcreate-payment.feature:21Passing
currency enumR2unsupported currency rejectedcreate-payment.feature:28Passing
201 on replayR3same key, same bodycreate-payment.feature:2Passing
409R4same key, different bodycreate-payment.feature:11Passing
status RECEIVEDR5new payment statuscreate-payment.feature:35Passing
insufficient fundsQ3none yetnoneBlocked on Payments operations

The last row is the useful one. It tells the team, in the same artifact the tests run from, what cannot ship yet and who it is waiting for.

How do you keep the spec and the code in sync?

Keep the spec in the repository, next to the code, and change it first. A pull request that changes behaviour without changing the spec is incomplete by definition. Two checks make this cheap:

  • A schema check on the spec, so every rule has an ID and a source, as in requirements as code.
  • An agent review step that compares a diff with the spec and reports each criterion as met, not met, or not covered, citing file and line. The skill for that is shown in agentic coding for analysts.

If you want this as a working setup rather than a pattern, The Analyst Engineering Agent Kit packages it: one agent that keeps a house-style memory, three skills (contract to stories and Gherkin criteria with a traceability matrix, Postman and Bruno collections from the contract, and Xray test execution updates), hooks, a Jira and Confluence MCP configuration, and adapters for Claude Code and for VS Code with GitHub Copilot.

What goes wrong when analysts skip this?

The agent ships exactly what the spec says, plus everything it was not told. The failures look the same on every team:

  • Green tests, wrong system. The agent writes tests for its own inventions, so the suite passes and proves nothing about the decisions that matter.
  • Decisions made in code review. A reviewer finds an invented status, and the business rule gets decided in a PR comment by whoever is online.
  • No trace back. Six months later nobody can say why the endpoint returns 202 for one case, because the reason was a guess.

The same pattern on an AI feature, where exact-match criteria failed, is written up in why acceptance criteria failed on an AI project.

The takeaway

Spec-driven development makes the specification the thing the agent builds from, which makes the analyst’s gaps the agent’s guesses. Read the contract for silence and give every gap an owner. Write criteria only from a source, and tag them. Give the agent a spec with decided rules, scope, a “must not invent” list, and marked open questions. Then review its output for the five inventions, and keep a traceability matrix that shows what is blocked and on whom.

For the full method behind Step 1 to Step 3, with the 16-field spec template and a worked banking example, start with From Vague Business Requirement to Functional Requirements. The prompts that draft specs, data mappings, and acceptance criteria for you to review are in The Technical Business Analyst Prompt Toolkit, and The Complete Tech BA Bundle includes both with the Technical Skills Guide and the Interview Guide: four guides for CAD 49.99 instead of 109.96. To review your own spec before an agent touches it, book a 1:1 Tech BA Coaching Call. Grab the free downloads, or browse everything at The Tech BA Toolkit. More on analysts who code lives in the Developer Analyst hub.

Ahmed is a Senior Technical Business Analyst with 10+ years in banking and payments. He builds practical guides and tools for analysts at The Tech BA Toolkit.

About the author

Analyst Engineering is written by Ahmed, a Senior Technical Business Analyst with 10+ years of banking and payments delivery experience: ISO 20022 and SWIFT messaging, payments API integration, Kafka event validation, and production support. Every article comes from real delivery work, and each one is reviewed and updated as tools and standards change.

Go deeper on this

Not ready to buy? The free starter kit is a no-cost place to start, and every article here stays free.

Free account

Practice on the Labs, keep your progress

A free account, no password: an email link signs you in. It saves your steps and self-assessments on the Labs, shows your missions on a dashboard, unlocks the solutions, and, if you tick the box, sends you new missions and articles when they ship.

Your email is used to sign you in. Nothing else, unless you ask. Privacy.