Prompt Patterns

Reference intermediate

Master Prompt Pattern Library

Category 1: Generation Patterns

The Complete Specification

Create [THING] that:

Inputs: [DESCRIBE INPUTS WITH TYPES]
Outputs: [DESCRIBE OUTPUTS WITH TYPES]
Behavior: [STEP-BY-STEP LOGIC]
Edge cases: [LIST EDGE CASES]
Errors: [HOW TO HANDLE EACH ERROR TYPE]

Example:
  [INPUT EXAMPLE] => [OUTPUT EXAMPLE]

Constraints:
  - [CONSTRAINT 1]
  - [CONSTRAINT 2]

The Pattern Match

Create [NEW THING] following the exact same pattern as [EXISTING THING]:

[PASTE EXISTING CODE]

But for [NEW DOMAIN/ENTITY], with these differences:
- [DIFFERENCE 1]
- [DIFFERENCE 2]

The Interface-First

Implement this interface:

[PASTE INTERFACE/TYPE DEFINITION]

Requirements:
- [REQ 1]
- [REQ 2]

The implementation should [KEY BEHAVIORAL REQUIREMENT].

Category 2: Transformation Patterns

The Upgrade

Upgrade this code from [OLD] to [NEW]:

[PASTE CODE]

Migration rules:
- [OLD PATTERN] becomes [NEW PATTERN]
- [OLD API] becomes [NEW API]
- [DEPRECATED] should be replaced with [CURRENT]

Preserve all existing behavior.

The Decompose

This function is too long/complex. Split it into smaller functions:

[PASTE LONG FUNCTION]

Each extracted function should:
- Have a single responsibility
- Be independently testable
- Have a descriptive name
- Accept parameters instead of accessing closure variables

The Generalize

This code works for [SPECIFIC CASE]:

[PASTE SPECIFIC CODE]

Generalize it to work for [BROADER CASES] by:
- Extracting [HARDCODED VALUES] as parameters
- Supporting [ADDITIONAL TYPES/FORMATS]
- Making [SPECIFIC LOGIC] configurable

Category 3: Analysis Patterns

The Audit

Audit this code for [CONCERN]:

[PASTE CODE]

For each issue found, report:
1. Location (line/section)
2. Problem description
3. Severity (critical/warning/suggestion)
4. Fix recommendation

Concerns to check:
- [CONCERN 1]
- [CONCERN 2]
- [CONCERN 3]

The Comparison

Compare these two approaches:

Approach A:
[PASTE CODE A]

Approach B:
[PASTE CODE B]

Compare on: performance, readability, maintainability, 
extensibility, and correctness.

Recommend which to use for [MY CONTEXT].

The Trace

Trace the execution of this code with input: [SPECIFIC INPUT]

[PASTE CODE]

Show me:
- The value of each variable at each step
- Which branches are taken
- What the final return value is
- Where it would fail with [EDGE CASE INPUT]

Category 4: Testing Patterns

The Coverage Generator

Write tests for [FUNCTION/MODULE]:

[PASTE CODE]

Required coverage:
- Happy path: [DESCRIBE NORMAL INPUTS]
- Boundary values: [LIST BOUNDARIES]
- Error conditions: [LIST ERROR TRIGGERS]
- Null/undefined: [WHICH PARAMS CAN BE NULL]
- Type edge cases: [EMPTY STRINGS, EMPTY ARRAYS, etc.]

Framework: [jest/vitest/pytest/etc.]
Style: [describe/it blocks, AAA pattern, etc.]

The Fixture Builder

Generate test fixtures for [TYPE]:

[PASTE TYPE DEFINITION]

Create:
- 3 valid examples (typical cases)
- 2 valid edge cases (minimum/maximum values)
- 3 invalid examples (explain why each is invalid)

Output as a TypeScript const with the fixtures array.