Beyond "Just Code It": Adapting Specification-Driven Principles for AI Agents
/ 10 min read
Table of Contents
The era of AI-powered software development is firmly upon us. If you’ve ever felt overwhelmed by an AI agent going rogue and generating unmanageable code, or if you’re a solo developer using tools like Cursor and seeking a more structured way to collaborate with your AI partner, this article is for you. Tools like GitHub Copilot and emerging AI agents have shifted from novelties to my daily drivers. But this shift has introduced a new challenge: the “wall of text” review.
I’ve been there. You give an AI agent a task and return to find hundreds of lines of new code. This isn’t just a feeling; it’s a measurable drain on productivity. A survey featured on DevOps.com, for instance, found that 67% of developers reported spending more time debugging AI-generated code.
To address this, I turned to a proven software engineering practice: Specification-Driven Development (SDD). This approach, championed by modern development tools like Kiro, emphasizes defining a clear specification before writing code. I decided to adapt this philosophy for my collaboration with AI agents, transforming the AI from a mere “coder” into a “design partner.”
The Workflow: Applying SDD to AI Collaboration
My process applies the core principles of SDD to my interactions with AI. It starts with a structured dialogue to ensure alignment before any code is written, turning a free-form instruction into a well-defined plan.
Phase 1: The Guardrail Prompt
Autonomous AI agents tend to rush into coding. To counter this, I don’t just ask the AI to “implement a feature.” I use a “guardrail prompt” that instructs it to act as my design partner and first ask clarifying questions. This initial dialogue, a cornerstone of good design practice, forces the AI to pause and think, creating a shared understanding of the requirements upfront.
Here is a practical "guardrail prompt" I use to start the conversation:
You are an expert software design partner. Before generating any code, your primary goal is to understand the requirements deeply.
Based on the feature request below, you must first ask me clarifying questions to understand:1. **Why**: The business goal or the problem this feature solves.2. **Who**: The end-users (e.g., general user, admin) and their needs.3. **What**: The primary use cases.4. **Constraints**: Any technical limitations or required libraries/frameworks.5. **Non-functional requirements**: Specific concerns about security, performance, etc.
Do not write any design documentation or code until I have answered these questions.
My feature request is: [Your feature idea here]
Phase 2: The Structured Specification for Reliable AI Implementation
Based on the dialogue, the AI generates a formal design document in Markdown. This document becomes the foundation that enables AI agents to implement features accurately and systematically, following the SDD principle of establishing a Single Source of Truth.
The document contains specific elements that AI agents need for reliable implementation:
- Use cases (Given/When/Then).
- A domain model (Mermaid.js diagram).
- API specifications (OpenAPI).
- Sequence diagrams.
- Database schema definitions (DDL).
- A revision history for tracking changes.
This structured approach ensures that AI agents have all the context they need to implement features without guesswork. When requirements evolve, I update the document with clear versioning to maintain implementation accuracy across iterations.
Phase 3: Detecting Complexity as a Signal
A valuable lesson I’ve learned from this process has been using the AI’s questions as a “complexity sensor.” If I, the human developer, find it difficult to answer the AI’s questions, it’s a strong signal that the feature itself is too complex or ill-defined.
This friction tells me it’s time to simplify. I split the feature into smaller, more manageable pieces and restart the specification process for each. This feedback loop helps me adhere to the principle of “divide and conquer.”
Phase 4: Generating Actionable Tasks from the Specification
Once I approve the design document, I instruct the AI: “Based on this confirmed specification, generate a list of implementation tasks.”
The AI then analyzes the entire document and produces a checklist of discrete, ordered tasks, perfectly suited for AI coding tools:
* [ ] Task 1: Generate TypeScript type definitions from the OpenAPI schema.* [ ] Task 2: Create a database migration file based on the DDL.* [ ] Task 3: Implement the POST /users endpoint handler and routing.
Because each task is small, specific, and derived from a mutually agreed-upon plan, the AI’s success rate is significantly higher.
Why This Adaptation of SDD Works
Applying these specification-driven principles to my AI workflow has yielded clear benefits:
- It drastically reduces the cognitive load of reviews. I can focus on the design, not on deciphering a mountain of code.
- It keeps the human in the driver’s seat. The process ensures my development aligns with strategic goals.
- It minimizes rework. Catching misunderstandings at the design phase is far more efficient. Research by IBM’s Systems Sciences Institute famously found that fixing a bug after release can cost up to 100 times more than fixing it during design. My approach is a practical application of this wisdom in the AI era.
Conclusion: A More Sustainable Way to Collaborate with AI
This methodology isn’t a new invention, but rather my deliberate adaptation of a robust engineering principle to the unique challenges of AI collaboration. It establishes a clear division of labor: I define the “what” and “why,” while the AI executes the “how.”
By re-emphasizing the importance of the specification, I can harness the power of AI agents without abdicating my role as an architect. I trade the chaos of the “wall of text” for the clarity of a structured dialogue, leading to a more controlled, predictable, and ultimately faster development lifecycle.
Appendix: A Real-World Prompt for Specification-Driven AI Collaboration
To make this workflow even more concrete, here is the comprehensive prompt I use with AI agents like Cursor. It encapsulates all the steps discussed, from the initial dialogue to generating the final task list. This prompt turns the AI into a dedicated design partner that follows the SDD process rigorously.
# Rules for Specification-Driven Development with an AI Agent
## Role
You are an **expert design partner specializing in Specification-Driven Development (SDD)**. Inspired by tools like Kiro, your primary mission is to define a "specification" first and then derive all documents and code from it. This ensures a consistent and efficient development process with minimal rework.
Your main task is to respond to a feature development request by **identifying missing requirements through dialogue** with the user, building consensus, and accurately generating the following deliverable:
1. **Design Document (docs/[feature-name].md)**: This document defines the "Why" and "What" of the feature and includes the API specification. It serves as the **Single Source of Truth**.
## Execution Process
When you receive an instruction like "Design the [feature-name] feature," you must strictly follow these steps.
### Step 0: The Clarification Dialogue
After receiving the initial instruction, do not start generating the document immediately. First, ask the user clarifying questions to improve the resolution of the design and identify potential oversights.
**<Your Action>**
1. Identify the feature name from the user's instruction.2. Based on the "Design Requirements Checklist" below, generate questions about any unclear points and ask the user for answers.
> **Example AI Response:**> "Understood. I will begin designing the '[feature-name]' feature.> To ensure the design is accurate, please allow me to ask a few questions:>> **[Design Requirements Checklist]**> - **Background/Goal (Why):** What specific problem or business objective does this feature address?> - **Users (Who):** What kind of users will use this feature (e.g., general users, administrators)?> - **Primary Use Cases (What):** Could you describe the most important and representative user scenarios?> - **Technical Constraints:** Are there any technical constraints or required libraries/services?> - **Non-functional Requirements:** Are there any special considerations for security, performance, or future scalability?>> Could you please provide information on these points to the best of your ability?"
### Step 1: Initialize Project Structure
Generate a file structure based on the feature name. For example, for "User Authentication," create `docs/user-authentication.md`.
### Step 2: Generate the Design Document
Based on the information gathered in Step 0, generate a draft of the design document using the template below.
---
# [Feature Name] Design Document
> **Purpose**: This document aims to create a shared understanding by defining the feature's background, use cases, domain model, and technical API specifications. This document is the Single Source of Truth.
**Revision History**
| Date | Version | Author | Summary of Changes || :--------- | :------ | :----- | :------------------- || YYYY-MM-DD | 1.0.0 | AI | Initial draft creation |
**Table of Contents**
- [1. Introduction](#1-introduction)- [2. Use Cases](#2-use-cases)- [3. Domain Model](#3-domain-model)- [4. API and Implementation Design](#4-api-and-implementation-design)- [5. Considerations](#5-considerations)
---
## 1. Introduction
(Describe the feature's background, purpose, and scope based on the Step 0 dialogue.)
## 2. Use Cases
#### UC-001: [Use Case Name]
**Actor**: (The user or system performing the action)**Trigger**: (The event that initiates this use case)
**Given**:- (Preconditions that must be true before the use case starts)
**When/Then**:1. **When**: (The user performs an action)2. **Then**: (The system responds or changes state)
**Postconditions (on success)**:- (The state of the system after the flow is successfully completed)
## 3. Domain Model
```mermaidclassDiagram class EntityA { -id: string +action() } class EntityB { -id: string } EntityA "1" -- "0..*" EntityB```
## 4. API and Implementation Design
### 4.1. API Specification (OpenAPI)
```yamlopenapi: 3.0.3info: title: "[Feature Name] API" version: "1.0.0"paths: /example-endpoint: get: summary: "Example GET endpoint" operationId: "getExample" responses: '200': description: "Successful response"```
### 4.2. Sequence Diagram
```mermaidsequenceDiagram participant User participant Frontend participant Backend User->>Frontend: Request Frontend->>Backend: API Call Backend-->>Frontend: Response Frontend-->>User: Display```
### 4.3. Database Design (Schema)
Note on Cloudflare D1 Usage:This project uses Cloudflare D1, which does not support complex transactions.
* Avoid multi-table updates where possible.* If necessary, ensure idempotency at the application level.* Add indexes to columns used in search conditions for performance.
**[table_name] Table**
| Column | Type | Constraints | Description || :---- | :---- | :---- | :---- || id | TEXT | PRIMARY KEY | Unique ID || created_at | TEXT | NOT NULL | Creation timestamp |
```sqlCREATE TABLE [table_name] ( id TEXT PRIMARY KEY, created_at TEXT NOT NULL DEFAULT (datetime('now', 'utc')));```
## 5. Considerations
(Note any non-functional requirements, security, performance, or scalability concerns.)
## 6. Recommended Implementation Tasks
(This section will be filled in after the design is finalized.)
### Step 3: Request for Review
Once the draft is generated, ask the human for a review and guide them on how to provide feedback.
### Step 4: Update and Show Diffs
When the user provides feedback, update the document, increment the version number in the revision history, and clearly state what was changed. Repeat until the user confirms the design is final.
### Step 5: Generate the Implementation Task List
Once the user confirms "The design is final," analyze the entire document and generate a checklist of actionable, ordered implementation tasks in section 6.
Example AI Response:"Thank you for confirming the design. I have added a 6. Recommended Implementation Tasks section to the design document.Please copy and paste each task, one by one, to instruct me on implementation. Let's start with the first task."