Skip to content

Prompt Templates

You are about to implement a new API endpoint. You open Cursor and type: “Add a POST endpoint for creating orders.” Agent generates something, but it misses validation, uses the wrong error format, and does not follow your existing patterns. So you spend the next five messages correcting it: “add Zod validation,” “use our error format,” “follow the pattern in users.ts.” By message six, you have typed more corrective instructions than it would have taken to write the endpoint yourself.

The fix is not better prompting intuition. It is prompt templates — pre-built, tested prompts that you paste and customize in seconds. They front-load the instructions the AI needs so the first output is usable.

  • A library of copy-paste prompts for the most common development tasks
  • A framework for building your own project-specific prompt templates
  • Techniques for storing prompts as Cursor rules and custom commands
  • Understanding of what makes a prompt effective versus wasteful

An effective Cursor prompt has four elements:

  1. The task — What you want the AI to do
  2. The constraints — What patterns, files, or conventions to follow
  3. The boundaries — What NOT to do (prevents scope creep)
  4. The verification — How to confirm the output is correct

Save frequently used prompts as custom commands in .cursor/commands/:

---
description: Generate a comprehensive test suite for a service
---
Write a comprehensive test suite for the file I mention.
- Use Vitest
- Mock external dependencies
- Cover happy path, error cases, and edge cases
- Use factory functions for test data
- Run tests after writing them

Invoke with /generate-tests @src/services/payment-service.ts in chat.

For patterns that should always apply to certain file types:

---
globs: "src/routes/**/*.ts"
---
When creating or modifying API routes:
- Always validate request bodies with Zod
- Always use withAuth middleware unless the route is explicitly public
- Always return errors using AppError from @src/lib/errors.ts
- Always log the request and response using the logger

Templates produce output that does not match your project. The template references patterns from a generic project. Update the @file references to point to your actual canonical examples.

Agent ignores parts of the template. Very long prompts (over 500 words) cause the agent to lose focus on later instructions. Move recurring constraints into rules so the prompt only contains task-specific information.

Templates feel rigid. They are starting points, not scripts. Delete the parts that do not apply and add context specific to the current task.