
Get an AI agent to follow a detailed spec by turning the document into a traceable contract. Give each requirement an ID, map it to implementation and verification, and require explicit approval before the agent changes the interpretation or scope.
Ask for a traceability table before coding:
| Requirement | Planned change | Verification | Status |
|---|---|---|---|
| `REQ-01` | Files or components affected | Test or observable behavior | Pending |
The table forces hidden gaps into view. A requirement without a planned change may have been overlooked. A change without a requirement may be scope creep. A requirement without verification is not ready to implement.
Define precedence when the spec conflicts with the repository. For example, security rules and public contracts may outrank an outdated implementation detail, but the agent should report the conflict rather than choose silently. Include non-goals and forbidden changes so the specification does not expand through convenient assumptions.
During implementation, require the agent to reference requirement IDs in its progress notes and final summary. Tests should cover behavior, boundary cases, and stated failure conditions, not merely confirm that code runs. At the end, compare the completed diff with the traceability table and list any deviation.
A detailed spec works when it controls decisions throughout the task. Repeating “follow the spec” in a prompt is weaker than making every change accountable to a requirement and every requirement accountable to evidence.
Related reading: What makes a good AI coding-agent prompt? and What is Plan Mode in an AI coding agent?.
