AI • Science • Technology • Future

Side Projects

Give Your AI Coding Agent Rules, Not Just a PRD

Image from the original article
Featured image: original publisher image. Via original publisher.

A developer shares a key lesson from hands-on experience with AI coding agents: a product requirement document (PRD) is not enough. The agent must also have clear rules defining what it can and cannot do. Source: dev.to.

What Happened: A Failed Build

The author once provided Cursor with a detailed PRD — complete with numbered requirements and acceptance criteria. After three days, the output was flawed.

Database tables appeared that were not in the original PRD. Two API payloads changed shape without notice. Half the screens ended with // TODO stubs, waiting for human input. These errors weren’t just minor oversights; they represented fundamental failures in the agent’s behavior — failures that could lead to security vulnerabilities, data inconsistencies, or broken user experiences when deployed.

Why the PRD Isn’t Enough

A PRD tells an AI agent what to build. But it says nothing about what it is not allowed to do.

Without constraints, the agent improvises. It makes confident, unverified decisions — especially in areas that are costly to fix later. For instance, inventing a new table without approval could result in schema drift, making future updates difficult or impossible. Similarly, bypassing Row Level Security (RLS) in code could expose sensitive data to unauthorized users, violating both privacy and compliance standards.

The fix is a short rules file — like .cursor/rules or CLAUDE.md — placed next to the PRD. This file acts as a constraint, not a suggestion. Unlike prompts, which are open-ended and can be ignored or misunderstood, rules are explicit, enforceable boundaries that the agent must follow. This shift transforms the agent from a tool that guesses into one that operates with accountability and precision.

Key Rules for an AI Coding Agent

Six rules form the core of the rules file. They are based on a free template published by the author and are designed to prevent the most common failure modes in AI-generated code.

  1. Build only what the PRD requires. Do not add extra features or functionality that aren’t explicitly stated.
  2. If a requirement is unclear, stop and ask — do not invent behavior. The agent should not assume or infer what a feature should do; it must request clarification from the human developer.
  3. Use table and column names from the schema exactly. Never invent new tables, columns, or relationships. This ensures consistency and avoids schema drift during development.
  4. Use request/response shapes from API contracts exactly. Never change a payload structure without updating the API contract first. This prevents mismatches between client and server code.
  5. Every database table must keep its Row Level Security (RLS) policy. Never bypass RLS in application code. This is critical for protecting user-specific data and ensuring access control is enforced at the database level.
  6. After building each requirement, run its acceptance check and report the result. If the PRD, schema, and contracts disagree, report the conflict — not silently choose. This creates a feedback loop that helps catch inconsistencies early.

Rule 6 is often skipped. It is the most important. An agent that flags a conflict is useful. One that silently picks a path becomes a bug factory — users only discover the mistake when they hit it in production. This rule transforms the agent from a passive builder into an active quality gatekeeper.

Real-World Example: TaskPulse

A sample spec for a sprint-tracking app called TaskPulse includes these rules:

  • Never invent arbitrary dependencies or unapproved database tables.
  • Every server action must validate input payloads using Zod schemas.
  • Every database query must respect Supabase Row Level Security boundaries.
  • Output complete, production-grade files. Do not use // TODO or placeholder stubs.

These rules prevent three common failure modes: invented tables, unvalidated payloads, and security bypasses. By enforcing these standards, the agent produces code that is not only functional but also secure, maintainable, and aligned with the project’s architecture.

Image from the original article
original publisher image. Via original publisher. · Source

The same file also defines a build order:

  1. Phase 1: Database DDL migrations & RLS policy verification
  2. Phase 2: Authentication flow & workspace tenancy middleware
  3. Phase 3: Typed Server Actions & CRUD endpoint validation
  4. Phase 4: Kanban UI components & optimistic state management

This order ensures the agent builds from the ground up — database first, auth second, API third, UI last. It prevents the common mistake of building screens before tables exist. This sequence aligns with software engineering best practices and reduces the risk of integration errors.

How to Use Rules Without Slowing Down

Two habits make the rules file effective:

  1. One journey at a time: Do not ask the agent to build the entire app. Give it one user journey, let it build it, run the acceptance check, then move on. This allows for focused, iterative development and makes it easier to validate each step.
  2. Treat a flagged conflict as a win: When the agent detects a mismatch between the PRD, schema, and contracts, that is a success. Fix the spec, and the next build will be faster and more accurate. Every silent choice the agent makes is a potential bug. Without context, it will only be discovered in production — when it’s too late.

Full Template and Tools

The author offers a free four-part template: PRD, schema, API contracts, and agent rules. All four files must agree. The template is available on GitHub: github.com/web-dev-mehedi/ai-prd-template.

A generator produces all four files from a single paragraph in under 60 seconds. It’s available at webdevmehedi.com/ai-prd-generator. It offers 50 free credits on signup, with plans from ৳99/mo via bKash or Nagad.

The core lesson: a PRD is a plan. The rules file is what keeps the build honest. Writing rules first turns the agent from a fast intern who guesses into a fast engineer who checks. This approach offers a practical, grounded way to reduce errors and improve reliability in AI-assisted development.

Learn more about prompt engineering and AI workflows in three real Halloween AI video tests.

Explore a no-asset WebGL template for landing pages at Substrate.

See how AI cost transparency can improve your workflow at How AI Cost Transparency Can Change Your Workflow.

Sources & further reading

Featured image: original publisher image. Via original publisher. Image source