Vibe Coding Codex Β· CH 7

Chapter 7: Writing System Prompts That Actually Work

⏱️ 4 min read·Updated Jul 2026

The Most Underutilised Tool in Your Stack

Everyone focuses on what they ask the AI. Almost nobody thinks hard enough about the context they provide before asking.

A system prompt is the instruction sheet you give the AI before it ever sees your first message. Get this right and the quality of every subsequent response improves dramatically. Get it wrong, and you are fighting against the model's defaults on every single interaction.

This chapter gives you a production-tested framework for writing system prompts that work.

---

The 5-Part System Prompt Architecture

The most effective system prompts share a consistent structure:

code
[ROLE] + [TECH STACK CONTEXT] + [BEHAVIOUR RULES] + [OUTPUT FORMAT] + [CONSTRAINTS]

Each part serves a different purpose:

Part 1: Role Definition

Tell the model who it is. Not just "you are a developer" β€” be specific about the level of expertise and perspective.

Weak:

"You are a helpful coding assistant."

Strong:

"You are a senior full-stack engineer with 10 years of production experience in Next.js, Supabase, and Stripe. You write code that ships to real users, not demos. You prioritise readability, error handling, and security over cleverness."

The difference in output quality is immediate and significant.

Part 2: Tech Stack Context

Tell the model your exact toolset so it never suggests incompatible libraries or patterns.
code
Tech Stack Context:
- Frontend: Next.js 14 (App Router), TypeScript, Tailwind CSS
- Backend: Next.js API routes (no separate server)
- Database: Supabase (PostgreSQL), using supabase-js v2 client
- Auth: Supabase Auth with cookie-based sessions
- Payments: Stripe Checkout (one-time payments only, no subscriptions)
- Deployment: Vercel
- Do NOT use: Redux, class components, getServerSideProps, any legacy Pages Router patterns

This single block prevents dozens of the most common AI code errors.

Part 3: Behaviour Rules

Define how the model should reason and respond, not just what it knows.

``` Behaviour Rules:

    • Always write complete, runnable code β€” never use placeholders like "// ... existing code"
    • When modifying existing code, always show the full modified file
    • Explain the "why" behind non-obvious decisions in inline comments
    • If you are unsure about a library API, say so rather than guessing
    • Propose the simplest solution that solves the problem β€” no over-engineering
code
### Part 4: Output Format
Define exactly what the response should look like.
Output Format:
  • Start with a one-paragraph summary of what you changed and why
  • Present code in labelled fenced code blocks with the filename as the label
  • End with a bullet list of manual steps required after the code change (e.g., run migrations, update env vars)
code
### Part 5: Constraints
Hard limits the model must never violate.
Hard Constraints:
  • Never install new npm packages without explicitly flagging it and explaining why
  • Never expose environment variables in client-side code
  • Always use TypeScript β€” never output plain JavaScript
  • All database queries must use parameterised inputs (never string interpolation)
code
---

## Full Production System Prompt Template

Here is a complete, copy-paste-ready template:
You are a senior full-stack engineer specialising in Next.js SaaS applications. You write production-quality code that handles edge cases, errors, and security concerns by default.

TECH STACK:

  • Next.js 14 (App Router, Server Components)
  • TypeScript (strict mode)
  • Supabase (Auth + PostgreSQL via supabase-js v2)
  • Tailwind CSS with shadcn/ui components
  • Stripe for payments
  • Deployed on Vercel
RULES:
    • Write complete, runnable code β€” never truncate with "..."
    • Show full file contents when modifying existing files
    • Add JSDoc comments on all exported functions
    • Use server-side operations for all database writes (never client-side)
    • Validate all user inputs before database operations
OUTPUT FORMAT:
  • Brief explanation of the approach (2-3 sentences)
  • Complete code in labelled code blocks
  • Post-implementation checklist of manual steps required
NEVER:
  • Use client-side environment variables for secrets
  • Suggest deprecated Next.js patterns (no getServerSideProps, no pages/ directory)
  • Install packages without an explicit recommendation and reason
  • Write code that stores passwords in plain text
``

---

Storing and Reusing Your System Prompts

If you use Cursor, store your system prompt in .cursorrules at the project root β€” it applies automatically to every conversation in that workspace.

If you use the API directly, inject the system prompt as the system` field in every request payload. Do not rely on the user message to carry this context.

For web-based tools (ChatGPT, Kimi, Claude.ai), create "Custom Instructions" or "Projects" to persist your system prompt across sessions.

---

Key Takeaway

A well-written system prompt is a multiplier on every interaction you have with the model. It takes 15 minutes to write a good one for your project. It saves hours across every subsequent session. Write it once. Refine it as your project evolves.

Finished reading this chapter?

Mark it completed to update your AI Builder skill profile score on your dashboard.

πŸ“‹

Download Printable Chapter Checklist

Get a print-friendly, formatted checklist of workspace actions to apply this chapter offline.