Journal / Process

Why we write specs before code, even in the age of AI agents.

The fastest way to fail with AI engineering is asking a model to write code from an informal chat prompt. High-velocity engineering teams use written specs as precise context anchors.

RL
RBB LAB
Studio
Published 15 Sep 2026 7 min read
spec:md RBB/LAB PROCESS RBB LAB · JOURNAL 7 MIN READ

When AI coding agents arrived, popular narrative promised that natural language would replace software specifications altogether. Just describe what you want in plain English, and the model will deliver a fully functional feature.

In practice, skipping the specification step creates severe context drift. Without an explicit, written blueprint that defines domain models, API boundaries, and invariants, AI agents hallucinate dependencies and make dangerous architecture assumptions.

10x
Reduction in Debug Iterations
1
Source of Truth File
0
Ambiguous API Schemas

The Cost of Unstructured Prompts

When engineers prompt AI agents without a spec, the agent acts as a loose interpreter rather than an executor. It picks variable names at random, invents database columns, and selects libraries that conflict with existing project standards.

A spec is not bureaucracy; it is context compression. Giving an AI agent a clean specification cuts context window noise and guarantees deterministic code output.

Our Markdown Spec Anatomy

Every feature branch at RBB LAB starts with a spec file saved in docs/specs/YYYY-MM-DD-feature-name.md. The spec contains five mandatory sections:

Section Content Description Why the Agent Needs It
Overview & Goals High-level purpose and user story summary Prevents scope creep during implementation
Data Model Types, schemas, and database migrations Ensures type safety across generated endpoints
API Contracts Request payload parameters and response status codes Eliminates mismatched client-server interfaces
Invariants & Rules Non-negotiable security and validation logic Prevents AI from omitting business checks
Verification Plan Commands and unit test expectations Gives the agent a self-testing target loop

Sample Spec Contract

Here is how a concise API contract section looks inside an implementation specification:

docs/specs/2026-07-28-payment-webhook.md# Spec: Payment Webhook Handler

## Contract
POST /api/webhooks/stripe
Headers: Stripe-Signature: string

## Validation Rules
1. Verify payload signature using process.env.STRIPE_WEBHOOK_SECRET.
2. If invalid: Return HTTP 400 immediately.
3. Idempotency: Check `processed_events` table for `event.id`.
4. If already processed: Return HTTP 200 with { received: true, duplicate: true }.
5. On success: Update account tier inside transaction block.

The Spec-Driven Agent Loop

Once the spec is reviewed by a human engineer, implementation takes minutes. The AI agent reads the markdown file, generates necessary files, runs verification tests, and fixes syntax errors autonomously.

For more insights into how engineering discipline scales when using AI, read our post on from copilots to delegation and why we stopped fighting vibe coding.