Skip to content
mentoor

Write a spec an agent cannot misread

For engineers

Scenario lesson and practice set combining Spec-driven development, Anatomy of a good prompt and PRDs and specs. Completing it counts as evidence for every listed skill.

A spec is written for a reader who cannot ask questions, never gets tired and fills every gap with a confident guess. Write for that reader and the work gets simple.

This case follows one small feature at Ledgerly, an invoicing app for small businesses. Support has a request: accountants want an invoice export. One line, from the support lead: "Add a CSV export of recent paid invoices. It should be fast and work for big accounts. Keep it simple."

Why this request goes wrong

A person would ask four questions before starting: what does "recent" mean, what is "fast", what counts as big, and what columns does the accountant's tool need? A coding agent usually does not ask. It picks an answer, builds it and reports success. In the first attempt the agent exported the last 30 days, in its own column order, with dates written 03/12/2026 and totals written with commas. Every choice was reasonable, and none was what the team meant.

The fix is not a smarter agent. It is a better input, built in three layers that each use one skill.

Layer one: the problem and the boundary (PRD)

Before any feature idea, write who has the problem, what it costs and how you will know it is solved. Here: accountants rebuild each client's paid invoices by hand every month, and support gets 38 tickets a week asking for data pulls (a figure from the team's own tracker). The primary metric is that ticket count. A guardrail is the export error rate.

Then draw the scope line, and spend more care on the non-goals than on the goals. "Not in this release: emailed or scheduled exports, Excel or PDF, draft and void invoices" is what stops an eager agent from adding a scheduler. Settle open questions that change scope, such as whether credit notes belong in the file, before work starts. An assistant can help draft the PRD, but it also invents plausible numbers and tidy-sounding exclusions, so every figure needs a source and every rewrite is compared with the original.

Layer two: the spec (one slice of the PRD)

The spec turns one slice into rules the agent can build and a test can check. It states behaviour, not design. It uses fixed words (MUST, MUST NOT) where it means a rule, names fields exactly and gives examples. Acceptance criteria are checkable:

1. The file has one row per invoice with status paid and paid_at in the last 12 months.
2. Rows are sorted by paid_at, oldest first.
3. 10,000 invoices export in under 5 seconds on the staging data.
4. An account with no match gets a file with only the header row.
5. Users with the viewer role get a 403 response.

"Fast and big" has become a number and a place to measure it. "Recent" has become a field and a range. The spec lives in the repository, such as docs/specs/invoice-export.md, and changes in the same pull request as the code.

Layer three: the prompt

The prompt carries the spec to the agent and says how to work. Its parts are the task, the context, the constraints, the format and an example. Here: one task sentence, the spec in a labelled block, a path limit ("edit only src/export/ and tests/export/, and stop and ask if another file needs a change"), the exact columns and one example row such as INV-1042,Ola Textiles,2026-12-03,EUR,1250.00.

Check the work against the spec

Ask the agent for a plan first. Compare it with the criteria line by line: is each criterion covered, and has the agent invented a step? Then read the diff against the spec's wording. A filter on issued_at where the spec says paid_at passes a quick look and fails an accountant. AI output reads as confident whether or not it is right, so the spec is what you check against.

What goes wrong

  • Invented numbers. A drafted PRD says "cuts tickets by 63%" with no source. Replace it with your baseline and a target you own.
  • Contradictions. Scope says paid only; a criterion says paid, sent and overdue. The agent follows one of them without telling you.
  • A rewrite that deletes a boundary. "Tighten the wording" removes the line that excluded draft invoices.
  • Praise instead of detail. "Be thorough and production-ready" replaces columns and examples with attitude.

The exercise below uses this case. Each question names the skill it tests.

Steps

  1. Write the problem and the scope line

    Skill: delivery-prd

    Start from the support request, not from the solution. Write who has the problem, what it costs today and the evidence. Pick one primary metric and one guardrail. Then list non-goals: emailed and scheduled exports, Excel and PDF, draft and void invoices. Close any open question that changes scope, such as credit notes, before work starts.

    Support request, Ledgerly, 12 November 2026

    From support: Accountants keep asking for an invoice export. Please add a CSV export of recent paid invoices. It should be fast and work for big accounts. Keep it simple.

  2. Check the AI-drafted PRD for invented detail

    Skill: delivery-prd

    If an assistant drafted the success section, mark every number and ask where it came from. Replace invented figures with your baseline. After any rewrite, compare the exclusions line by line with the version before it.

  3. Turn one slice of the PRD into a spec

    Skill: sdlc-spec-first

    Write behaviour, not design. Name the fields (paid_at, not "date"), use MUST and MUST NOT for rules, and give each criterion a check a test can run. Turn "fast and big" into 10,000 invoices in under 5 seconds on the staging data. Save it as docs/specs/invoice-export.md.

    Spec, acceptance criteria

    1. One row per invoice with status paid and paid_at in the last 12 months.
    2. Rows sorted by paid_at, oldest first.
    3. 10,000 invoices export in under 5 seconds on the staging data.
    4. No matching invoices: a file with only the header row.
    5. Viewer role: 403.

  4. Hunt the lines an agent could read two ways

    Skill: sdlc-spec-first

    Read the spec as the agent would. Look for undefined words ("recent"), conflicts between scope and criteria, rules with no check and lines that dictate code. Rewrite each so one reading is left.

  5. Put the spec in a prompt that sets its own limits

    Skill: prompt-anatomy

    One task sentence. The spec in a labelled block. Constraints with real edges: allowed paths, no migrations, no new dependencies, and what to do at the edge (stop and say). The exact columns and one example row. Ask for a plan before code.

    Second prompt to the coding agent
    1. user

      Task: implement the invoice export described in <spec>.

      <spec>
      (contents of docs/specs/invoice-export.md)
      </spec>

      Constraints: edit only src/export/ and tests/export/. No migrations, no new dependencies. If another file needs a change, stop and tell me which and why.

      Format: CSV with the header invoice_number,customer_name,paid_on,currency,total. Example row: INV-1042,Ola Textiles,2026-12-03,EUR,1250.00.

      First give me a plan that maps to each acceptance criterion. Do not write code yet.

  6. Review the plan and the diff against the spec

    Skill: sdlc-spec-first

    Match the plan to the criteria: every one covered, no extra steps. Then read each changed line against the spec's wording, including the field names. Send back anything that departs, and update the spec in the same pull request if behaviour was meant to change.

Skills this scenario uses

Where to study