Coding AI prompt templates

Free AI coding prompt templates for code review, debugging, refactoring, and unit tests. Each includes clear constraints, variables, and a worked example.

Choose a prompt by the job it needs to do.

Good coding prompts make the expected evidence explicit: quote the risky line, explain the failure, propose a concrete patch, and name the test that proves it.

Include the smallest runnable snippet plus its real context. Language and framework matter, but the intended behaviour and failure mode usually matter more.

  • Review a diff by severity
  • Explain an error from first principles
  • Refactor without changing behaviour
  • Generate focused unit tests

4 free templates

Every page includes the full prompt, variable guidance, and a filled-in example.

Build a lightweight prompt-rating habit
  • Code review checklist

    Run a focused, prioritised code review of a diff or snippet, covering correctness, edge cases, readability, and security without nitpicking style.

    3 fill-in variables · Worked example

    {{language}}{{context}}{{code}}

    Review the following {{language}} code as a senior engineer.
    
    Context: {{context}}
    
    ```{{language}}
    {{code}}
    ```
    
    Work through this checklist and report findings, not just observations:
    1. Correctness - logic errors, off-by-one mistakes, wrong assumptions.
    2. Edge cases - empty inputs, nulls, concurrency, large or malformed data.
    3. Error handling - what happens when a call fails or input is invalid.
    4. Security - injection, unsafe deserialisation, leaked secrets, missing
       authorisation checks.
  • Explain this error

    Decode a stack trace or error message into a plain-language root cause, the most likely fixes, and a quick way to confirm which one is right.

    3 fill-in variables · Worked example

    {{language}}{{context}}{{error}}

    I hit this error and need help understanding it.
    
    Language / runtime: {{language}}
    What I was doing when it happened: {{context}}
    
    Error output:
    ```
    {{error}}
    ```
    
    Please:
    1. Translate the error into plain language - what does it actually mean?
    2. Identify the single most likely root cause based on the message and context,
       and list any other plausible causes ranked by likelihood.
  • Refactor for readability

    Refactor a piece of code to be clearer and easier to maintain while preserving its exact behaviour, with a short explanation of every change.

    3 fill-in variables · Worked example

    {{language}}{{context}}{{code}}

    Refactor this {{language}} code for readability and maintainability without
    changing its observable behaviour.
    
    What the code does: {{context}}
    
    ```{{language}}
    {{code}}
    ```
    
    Constraints:
    - Keep the public interface (function names, signatures, return values) the same
      unless I explicitly approve a change.
    - Prefer clear names, smaller functions, early returns, and removing duplication
      over clever one-liners.
  • Write unit tests for a function

    Generate a thorough unit test suite for a single function, covering the happy path, edge cases, and failure modes using your chosen test framework.

    3 fill-in variables · Worked example

    {{language}}{{framework}}{{code}}

    Write unit tests for the following {{language}} function using {{framework}}.
    
    Function:
    ```{{language}}
    {{code}}
    ```
    
    Requirements:
    - Cover the happy path with representative inputs.
    - Cover edge cases: empty, zero, negative, boundary, and very large values where
      they apply.
    - Cover failure modes: invalid input, thrown errors, and unexpected types.
    - Use clear, behaviour-describing test names (e.g. "returns 0 for an empty list").
    - Arrange each test with minimal setup and assert one behaviour per test.

Make the useful version yours.

Copy a template into the free local-first prompt manager, then refine it after each run.