Prompt.Lab

Coding / Practical templates

AI coding prompts that help you debug, build, and learn.

Twelve adaptable templates that give an AI coding assistant the evidence, constraints, and acceptance criteria it needs—without treating its output as automatically correct.

Prompt.Lab Editorial12 min readOfficial sources reviewed

“Fix my code” asks an AI to guess. A strong coding prompt gives it a system to investigate: the environment, expected behavior, actual behavior, relevant code, constraints, and a way to verify the result.

More detail is not automatically better. A full repository dump can hide the same clue that a one-line request omits. The goal is relevant evidence: enough context to understand the problem, without unrelated files, secrets, or private data.

The safe default

Ask for diagnosis, a focused change, and verification.

Code that looks convincing can still fail. Make the assistant show its assumptions and give you a testable path.

The six fields that make coding prompts useful

01

Environment

Language, framework, versions, operating system, and relevant dependencies.

02

Goal

The behavior you need—not merely the file you want changed.

03

Evidence

Minimal code, full error output, logs, schema, or official API contract.

04

Constraints

Compatibility, security, performance, architecture, and dependencies.

05

Acceptance

Specific conditions that prove the work is complete.

06

Verification

Tests, commands, measurements, and manual checks to run.

12 AI coding prompt templates

Replace the bracketed fields and remove any line that does not matter to your task. Never paste production secrets, access tokens, customer data, or proprietary code you are not allowed to share.

01

Debug a runtime error

Find the cause before proposing a patch.

Act as a senior [language/framework] developer. Diagnose the runtime error below. First explain the most likely cause using only the supplied code and error output. Then propose the smallest safe fix as a diff. Do not invent missing files or APIs; list any information you still need. Finally provide exact steps to verify the fix.

Environment: [versions and operating system]
Expected behavior: [what should happen]
Actual behavior: [what happens]
Error: [paste full error]
Relevant code: [paste minimal code]
02

Reduce a bug to a minimal example

Useful when a large project hides the real failure.

Help me create a minimal reproducible example for this [language/framework] bug. Identify which parts of the supplied code are relevant, remove unrelated dependencies one at a time, and preserve the failure. Return: (1) a minimal code sample, (2) setup steps, (3) expected versus actual behavior, and (4) the next diagnostic test. Do not claim a root cause until the reduced example supports it.

Project context: [context]
Code and error: [paste]
03

Explain unfamiliar code

Learn what the code does without receiving a vague summary.

Explain the code below to a developer who understands [known concepts] but is new to [topic]. Start with the overall purpose, then trace the data flow in execution order. Explain important syntax, assumptions, side effects, and failure cases. End with three questions I should be able to answer to confirm understanding. Do not rewrite the code unless a correctness issue requires attention.

Code: [paste code]
04

Review a pull request

Focus the review on risk rather than personal style.

Review this change as a careful maintainer. Context: [feature and users affected]. Prioritize correctness, security, data loss, concurrency, accessibility, and backward compatibility. Ignore harmless style preferences. For every issue, cite the exact code, explain the failure scenario, assign severity, and suggest a focused fix. If you cannot verify an assumption from the diff, state what evidence is missing.

Diff: [paste diff]
Relevant requirements: [paste]
05

Implement a small feature

Turn a request into code with explicit acceptance criteria.

Implement [feature] in the existing [stack] project. Respect the current architecture and dependencies shown below. Acceptance criteria: [criteria]. Constraints: [browser/runtime support, libraries, performance, accessibility]. First summarize the files you expect to change. Then provide the implementation as focused diffs and the tests needed. Do not replace unrelated code or introduce a dependency without explaining why.

Relevant files: [paste]
06

Refactor without changing behavior

Make improvement measurable and protect existing behavior.

Refactor the code below to improve [readability/performance/maintainability] without changing observable behavior. Identify the invariants that must remain true. Provide a small staged diff, explain each change, and add or update tests that prove behavior is preserved. Avoid speculative abstractions and keep public APIs compatible.

Code: [paste]
Existing tests: [paste]
Known constraints: [list]
07

Write meaningful tests

Cover behavior and failure paths instead of chasing a percentage.

Design tests for the [function/component/API] below. Derive cases from its contract and risks: normal behavior, boundaries, invalid input, failure paths, and one regression scenario. Use [test framework]. For each test, state what bug it would catch, then provide runnable code. Mock only external boundaries and do not test implementation details.

Contract: [paste]
Code: [paste]
08

Build a safe SQL query

Make schema, parameters, and scale visible.

Write a parameterized [database] query that [goal]. Use only the schema below. Requirements: [filters, sorting, pagination, transaction rules]. Return the query, parameter list, and a short explanation of indexes or performance risks. Never interpolate untrusted input. If the schema cannot support the request safely, explain the missing relation or constraint instead of guessing.

Schema: [paste schema]
09

Integrate an API

Account for authentication, failures, and secret handling.

Show how to integrate [API] into this [server/runtime]. Use the official API contract supplied below. Keep secrets in server-side environment variables, validate inputs, set a timeout, handle non-2xx responses, and avoid logging credentials or sensitive payloads. Provide the smallest working example plus retry and rate-limit guidance. Mark any endpoint or field you cannot verify.

API contract: [paste excerpt or link]
Existing code: [paste]
10

Create an accessible frontend component

Describe behavior across screen sizes and input methods.

Build a responsive [component] in [framework]. It must support keyboard navigation, visible focus, semantic labels, loading, empty, error, and success states. Match these design tokens: [tokens]. Preserve the project’s existing component patterns. Return complete component code, minimal styles, and interaction tests. Explain any accessibility decision that is not obvious.

Existing patterns: [paste]
11

Investigate a performance problem

Measure first and optimize the actual bottleneck.

Help diagnose this performance problem in [system]. Symptom: [symptom]. Baseline measurement: [metric]. Workload: [data size and traffic]. Analyze the evidence below, rank possible bottlenecks, and propose one measurement that would confirm or reject each. Recommend an optimization only after connecting it to evidence, and include a rollback or comparison plan.

Profiling data/logs: [paste]
12

Learn a programming concept

Use explanation, prediction, and practice—not just an answer.

Teach me [concept] using [language]. My current level: [level]. Begin with a plain-language mental model, then show one small example and trace it line by line. Ask me to predict the output of a second example before revealing the explanation. Finish with a short exercise and a checklist for evaluating my solution. Do not solve the final exercise unless I ask.

How to review AI-generated code

Read the diff before running it. Check whether the assistant changed more than requested, invented APIs, weakened validation, exposed a secret, or ignored an error path. Then run the smallest relevant test, the wider test suite, static checks, and a manual flow where appropriate.

The explanation matches the actual code and error.

The change is limited to the requested behavior.

Inputs, permissions, secrets, and failure paths remain safe.

New dependencies and breaking changes are justified.

Tests cover the expected behavior and the original failure.

A human reviewer owns the final decision.

The coding lesson

Give AI evidence and a definition of done. Then verify the code as carefully as code written by any other collaborator.

Turn theory into a better result

Your idea is good.
Give it better instructions.

Paste a rough request into Prompt.Lab and get a structured prompt for ChatGPT, Claude, or Gemini.

Try Prompt.Lab free →

Continue exploring

View all →