50 ChatGPT Prompts for Developers, With Example Output Shapes
50 copy-paste prompts for debugging, code review, documentation, refactoring and everyday dev tasks, with illustrative input and output examples for the five most useful ones and notes on verifying results.
This is a list of 50 copy-paste prompts for common development tasks. They are written for ChatGPT but work in most chat assistants and coding tools, since they rely on plain instructions rather than product-specific features. Replace the [PLACEHOLDERS] with your own details.
If you want the process behind good coding prompts (what context to give, how to constrain the output, how to verify it), read the companion coding prompts workflow guide. This page is the quick-reference list.
Before You Use These Prompts
- Verify every output. Run the code, run the tests, and read the diff. AI-generated code can compile and still be wrong, insecure or slower than what you had.
- Results vary. The same prompt can give different answers between runs, and models are updated regularly, so a prompt that worked well last month may behave differently today. Re-check prompts you rely on after a model change.
- Don't paste secrets. Strip API keys, credentials and customer data before pasting code or logs.
- The examples below are illustrative. For five of the most useful prompts we show an example input and the shape of a good answer. These were written for this article to show what to expect; they are not recorded outputs from a specific model.
Debugging Prompts (1-10)
1. Bug Diagnosis
I have a bug in my [LANGUAGE] code.
Expected behavior: [EXPECTED]
Actual behavior: [ACTUAL]
How to reproduce: [INPUT OR STEPS]
Environment: [RUNTIME/FRAMEWORK AND VERSION]
[CODE]
Please:
1. Identify the root cause and point to the line(s)
2. Explain why this happens
3. Provide a minimal fix (change only what is needed)
4. Give a test that fails before the fix and passes after it
Illustrative example (not a recorded model output).
Input:
// Expected: total of items, Actual: "0102030" for [10, 20, 30]
function cartTotal(items) {
return items.reduce((sum, item) => sum + item.price, "0");
}
// items come from JSON where price is a string, e.g. { "price": "10" }
Shape of a useful answer:
Root cause: line 3 — the initial value "0" is a string and item.price is a
string, so + concatenates instead of adding.
Fix: return items.reduce((sum, item) => sum + Number(item.price), 0);
Test: expect(cartTotal([{price:"10"},{price:"20"},{price:"30"}])).toBe(60)
Prevention: parse prices to numbers at the API boundary.
How to verify: run the test before and after the fix. If the model's "root cause" doesn't explain the reproduction you gave, push back before applying its patch. Matching template: Debug Helper; more in debugging prompts.
2. Error Message Decoder
I'm getting this error: [ERROR MESSAGE]
Context:
- Language/Framework: [LANGUAGE]
- What I was trying to do: [ACTION]
Explain what this error means in simple terms and provide 3 possible solutions.
3. Stack Trace Analysis
Analyze this stack trace and explain:
1. What went wrong
2. Which line is the actual cause (vs. just propagating the error)
3. How to fix it
[STACK TRACE]
4. Memory Leak Detection
This code may have a memory leak. Analyze it for:
- Memory leaks
- Resource leaks (file handles, connections)
- Objects that should be garbage collected but aren't
[CODE]
5. Race Condition Debug
I suspect a race condition in this concurrent code. Please:
1. Identify potential race conditions
2. Explain the scenarios where they'd occur
3. Suggest fixes (mutexes, channels, atomic ops)
[CODE]
6. Performance Issue Investigation
This function is slow. Profile the logic and identify:
- Time complexity issues
- Unnecessary operations
- Optimization opportunities
Current execution context: [HOW IT'S CALLED]
[CODE]
7. Null/Undefined Debug
I'm getting null/undefined errors somewhere in this flow:
[CODE]
Trace through the data flow and identify all places where null/undefined could occur.
8. API Integration Debug
My API call isn't working as expected.
Request: [REQUEST DETAILS]
Expected response: [EXPECTED]
Actual response: [ACTUAL]
API documentation says: [RELEVANT DOCS]
What am I doing wrong?
9. Database Query Debug
This query returns wrong results:
[QUERY]
Expected: [EXPECTED ROWS/DATA]
Actual: [ACTUAL ROWS/DATA]
Schema:
[RELEVANT TABLES]
Diagnose the issue and fix the query.
10. Regex Debug
This regex isn't matching correctly:
Pattern: [REGEX]
Should match: [EXAMPLES THAT SHOULD MATCH]
Shouldn't match: [EXAMPLES THAT SHOULDN'T]
Fix the pattern and explain each part.
Matching template: Regex Pattern Generator and Tester. Test the fixed pattern against every example you listed before using it.
Code Review Prompts (11-20)
11. Comprehensive Review
Review this [LANGUAGE] code. What it should do: [INTENT]
Check for:
- Bugs and edge cases
- Security vulnerabilities
- Performance issues that matter at [EXPECTED SCALE]
- Missing tests
[CODE]
For each finding give: line, problem, the input or code path that triggers
it, severity (high/medium/low), and a fix. Only report issues you can
support with evidence from the code. If something depends on code you
can't see, list it as a question instead.
Illustrative example (not a recorded model output).
Input:
# Intent: return a user's orders. Called from an authenticated API route.
def get_orders(db, user_id, status):
query = f"SELECT * FROM orders WHERE user_id = {user_id} AND status = '{status}'"
return db.execute(query).fetchall()
Shape of a useful answer:
1. Line 3 — high — SQL injection: status is interpolated into the query.
Trigger: status = "x' OR '1'='1" returns other users' orders.
Fix: parameterized query, e.g. db.execute("... user_id = ? AND status = ?",
(user_id, status)).
2. Line 3 — low — SELECT * returns every column; select only what the API needs.
Question: is status validated against an allowed list before this call?
Missing tests: injection attempt returns no rows; unknown status returns [].
How to verify: confirm each high-severity finding yourself (here, by writing the injection test). Dismiss findings whose "trigger" doesn't actually work. Matching templates: Code Review Expert and Code Review Assistant for Pull Requests. For a full review process, see the AI code review workflow guide.
12. Security Audit
Audit this code for security vulnerabilities including:
- Injection attacks (SQL, XSS, command)
- Authentication/authorization flaws
- Data exposure risks
- Insecure configurations
[CODE]
13. Performance Review
Review for performance issues:
- O(n²) or worse operations
- Unnecessary memory allocation
- Database N+1 queries
- Blocking operations
- Missing caching opportunities
[CODE]
14. Code Style Review
Review against [STYLE GUIDE - e.g., Google, Airbnb, PEP8]:
[CODE]
List all style violations with line numbers.
15. Accessibility Review
Review this frontend code for accessibility:
- ARIA labels
- Keyboard navigation
- Screen reader compatibility
- Color contrast issues
- Focus management
[CODE]
16. API Design Review
Review this API design:
[ENDPOINTS AND SCHEMAS]
Check for:
- REST best practices
- Consistent naming
- Appropriate HTTP methods
- Error response format
- Missing endpoints
17. Schema Review
Review this database schema:
[SCHEMA]
Check for:
- Normalization issues
- Missing indexes
- Poor naming conventions
- Relationship problems
- Scalability concerns
Matching template: Database Schema Designer.
18. Test Coverage Review
Here's my function and its tests.
Function:
[CODE]
Tests:
[TEST CODE]
Testing framework: [FRAMEWORK]
1. List behaviors of the function that no test covers (one line each)
2. For the three most important gaps, write the missing tests
3. Point out any existing test that would still pass if the function
were broken (weak assertions)
Illustrative example (not a recorded model output).
Input:
export function slugify(title: string): string {
return title.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-");
}
test("slugify", () => {
expect(slugify("Hello World")).toBe("hello-world");
});
Shape of a useful answer:
Uncovered behaviors:
- Leading/trailing punctuation produces leading/trailing hyphens ("Hi!" -> "hi-")
- Non-ASCII letters are replaced by hyphens ("Café" -> "caf-")
- Empty or whitespace-only input
Tests to add:
expect(slugify(" Hi! ")).toBe(...) // decide: "hi" or "hi-"?
expect(slugify("Café au lait")).toBe(...)
expect(slugify(" ")).toBe("")
Weak assertion: none, but the single test only covers the happy path.
How to verify: run the new tests. A useful answer often reveals a decision you haven't made yet (should "Hi!" become "hi" or "hi-"?). Decide the intended behavior yourself; don't let the generated test define it. Matching templates: Unit Test Generator and Jest Unit Test Generator.
19. PR Review Template
I'm reviewing this PR. Help me understand:
Changes:
[DIFF OR DESCRIPTION]
Context: [WHAT FEATURE/FIX THIS IS FOR]
Questions:
1. What could break?
2. What edge cases might be missed?
3. Any potential performance impact?
20. Architecture Review
Review this system design:
[ARCHITECTURE DESCRIPTION/DIAGRAM]
Evaluate for:
- Single points of failure
- Scalability bottlenecks
- Security concerns
- Operational complexity
- Cost efficiency
Browse more code review prompts, or read our AI code review workflow guide for a complete process.
Documentation Prompts (21-30)
21. Function Documentation
Generate documentation for this function:
[FUNCTION]
Format: [JSDoc / Python docstring / Javadoc / etc.]
Include:
- One-sentence description of what it does (not how)
- Parameters with types and allowed values
- Return value
- Errors or exceptions it can raise, and when
- One usage example
Only document behavior visible in the code. If something is unclear
(e.g., what happens on empty input), say so instead of guessing.
Illustrative example (not a recorded model output).
Input:
def retry(fn, attempts=3, delay=0.5):
for i in range(attempts):
try:
return fn()
except Exception:
if i == attempts - 1:
raise
time.sleep(delay * 2 ** i)
Shape of a useful answer:
"""Call fn, retrying on any exception with exponential backoff.
Args:
fn: Zero-argument callable to invoke.
attempts: Total number of calls to make, including the first. Default 3.
delay: Seconds to wait before the first retry; doubles each retry. Default 0.5.
Returns:
Whatever fn returns on its first successful call.
Raises:
Exception: re-raises the last exception if every attempt fails.
Note:
attempts <= 0 calls fn zero times and returns None (behavior visible in
the code; confirm this is intended).
Example:
data = retry(lambda: fetch_json(url), attempts=5)
"""
How to verify: check each documented claim against the code, especially defaults and error behavior. Good output flags surprising behavior (like attempts=0) rather than smoothing over it. Matching template: Documentation Generator; more in documentation prompts.
22. README Generator
Generate a README.md for my project:
Project name: [NAME]
What it does: [DESCRIPTION]
Tech stack: [TECHNOLOGIES]
Installation steps: [STEPS]
Key features: [FEATURES]
Include badges, quick start, and contributing section.
23. API Documentation
Document this API endpoint:
[ENDPOINT CODE OR SPECIFICATION]
Generate documentation including:
- Description
- URL and method
- Request parameters/body
- Response format with examples
- Error codes
- cURL example
Matching template: REST API Documentation Generator. Check every documented field and status code against the actual handler.
24. Architecture Documentation
Create documentation for this system architecture:
[DESCRIPTION OR DIAGRAM]
Include:
- System overview
- Component descriptions
- Data flow
- Dependencies
- Deployment considerations
25. Code Comments
Add appropriate comments to this complex code:
[CODE]
Comment on:
- Why (not what) for non-obvious logic
- Algorithm explanations
- Magic numbers
- Edge case handling
- Potential gotchas
26. Changelog Entry
Write a changelog entry for this change:
[DESCRIPTION OF CHANGE]
Version: [VERSION]
Type: [Feature / Fix / Breaking / etc.]
Format as Keep a Changelog style.
27. Migration Guide
Write a migration guide for upgrading from v[OLD] to v[NEW]:
Breaking changes:
- [CHANGE 1]
- [CHANGE 2]
Include before/after code examples for each change.
28. Troubleshooting Guide
Create a troubleshooting guide for common issues with [SYSTEM/LIBRARY]:
For each issue include:
- Symptom
- Common causes
- Diagnostic steps
- Solutions
29. Quick Start Guide
Write a 5-minute quick start guide for [PROJECT]:
Target: [Beginner developer / experienced X developer]
Goal: Get [BASIC THING] working
Focus on the absolute minimum to see results.
30. Runbook
Create an operational runbook for [SERVICE]:
Include:
- Health check procedures
- Common incident responses
- Restart procedures
- Rollback steps
- Escalation paths
Refactoring Prompts (31-40)
31. General Refactor
Refactor this code to improve readability:
[CODE]
Preserve functionality but improve:
- Naming
- Structure
- Complexity
- DRY violations
Matching template: Refactoring Assistant. Run your test suite before and after; a refactor that changes behavior is a bug.
32. Extract Function
Identify code that should be extracted into separate functions:
[CODE]
For each extraction, provide:
- Function name
- Parameters
- The extracted code
- Why this should be separate
33. Design Pattern Application
Refactor this to use [PATTERN NAME] pattern:
[CODE]
Show the refactored code and explain how the pattern applies.
34. Type Safety Refactor
Add TypeScript types to this JavaScript:
[CODE]
Create appropriate interfaces/types.
Make the most strict type definitions that still work.
Matching template: TypeScript Type Generator. Run the type checker on the result.
35. Async Refactor
Refactor from callbacks to async/await:
[CALLBACK CODE]
Handle errors properly and maintain the same behavior.
36. Reduce Complexity
This function has high cyclomatic complexity. Simplify it:
[CODE]
Target: Under 10 cyclomatic complexity while maintaining functionality.
37. Remove Duplication
Find and remove duplication in this code:
[CODE]
Create reusable functions/components for repeated patterns.
38. Modernize Syntax
Update this [LANGUAGE] code to modern syntax ([VERSION]):
[CODE]
Use latest features where they improve the code.
39. Error Handling Improvement
Improve error handling in this code:
[CODE]
Current issues: [KNOWN ISSUES OR "review and identify"]
Implement proper error handling, recovery, and user feedback.
40. Testable Refactor
Refactor this code to be more testable:
[CODE]
Add dependency injection, reduce coupling, make I/O operations injectable.
Utility Prompts (41-50)
41. Regex Generator
Create a regex that matches:
- [WHAT TO MATCH]
And doesn't match:
- [WHAT TO EXCLUDE]
Explain each part of the pattern.
42. Bash Command
Write a bash one-liner that [TASK].
Requirements:
- [ANY CONSTRAINTS]
Explain what each part does.
43. SQL Query
Write a [POSTGRESQL/MYSQL/ETC.] query to [GOAL].
Schema:
[CREATE TABLE STATEMENTS OR COLUMNS AND KEYS]
Requirements:
- [PERFORMANCE NEEDS, e.g. tables have ~N million rows]
- [ANY CONSTRAINTS]
Also give:
1. A one-line explanation of each join and filter
2. How it handles NULLs, ties and empty groups
3. Indexes that would help, if any
4. A tiny sample dataset and the expected result, so I can test it
Illustrative example (not a recorded model output).
Input (PostgreSQL): "Top 3 customers by total paid order value in the last 30 days" with tables customers(id, name) and orders(id, customer_id, total_cents, status, created_at).
Shape of a useful answer:
SELECT c.id, c.name, SUM(o.total_cents) AS paid_cents
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.status = 'paid'
AND o.created_at >= now() - interval '30 days'
GROUP BY c.id, c.name
ORDER BY paid_cents DESC, c.id
LIMIT 3;
-- Ties: broken by c.id so results are stable.
-- Index: orders (status, created_at) or (created_at) depending on selectivity.
-- Test data: 4 customers, 6 orders incl. one 'refunded' and one 40 days old;
-- expected result lists the 3 customers with the highest paid totals.
How to verify: run the query on the sample data and compare with the expected result, then check the plan with EXPLAIN on realistic data before trusting the index advice. Matching template: SQL Query Optimizer and Explainer.
44. Git Command
What git commands do I need to [GOAL]?
Current state: [WHERE I AM]
Desired state: [WHERE I WANT TO BE]
Include safety warnings if applicable.
45. Cron Expression
Create a cron expression that runs [WHEN].
Format for: [cron / AWS / Kubernetes / etc.]
Explain each field.
46. Data Structure Selection
I need to store [DATA] and perform these operations frequently:
- [OP 1]
- [OP 2]
In [LANGUAGE], what data structure should I use and why?
47. Algorithm Selection
I need to solve: [PROBLEM]
Constraints:
- Data size: [SIZE]
- Time constraint: [REQUIREMENT]
- Memory constraint: [REQUIREMENT]
What algorithm should I use? Provide implementation.
48. Boilerplate Generator
Generate boilerplate for [TYPE] in [FRAMEWORK]:
Include:
- Standard folder structure
- Config files
- Essential dependencies
- Basic setup code
49. Test Data Generator
Generate test data for [SCHEMA]:
[DATA MODEL]
Generate:
- [N] records
- Realistic values
- Edge cases included
- Format: [JSON / SQL / CSV]
50. Code Translation
Translate this code from [SOURCE LANGUAGE] to [TARGET LANGUAGE]:
[CODE]
Maintain:
- Same functionality
- Idiomatic patterns for target language
- Equivalent error handling
Bookmark This Page
Keep these prompts handy and adapt the placeholders to your situation. Two habits make any of them more useful: give the model the context it can't guess (versions, intent, constraints), and ask for something you can check (a test, a sample dataset, a reproduction). For the full process, read the coding prompts workflow guide; to sharpen general technique, read how to write better AI prompts.
For more prompts organized by category and use case, browse the prompt library:
- Coding prompts
- Debugging prompts
- Code review prompts
- Documentation prompts
- Data prompts for SQL, analytics and visualization
Related Articles
Coding Prompts That Work: A Workflow from Context to Verified Code
A practical workflow for AI-assisted coding: give the right context, set constraints, generate in small steps, verify with tests, review and security checks, and iterate. Links to individual coding templates for each step.
AI Code Review Workflow: Prompts, Triage Rubric and a Worked Diff Example
A repeatable AI code review workflow: what context to give the model, a review prompt that demands evidence, a triage rubric for false positives, human checks, and how to package it as a reusable review skill.
How to Build a Custom GPT Workflow and Test It (and Plan the Move to Plugins)
Plan a Custom GPT's instructions, reference files, actions and evaluation cases, with OpenAI's current status: custom GPTs are being retired in favor of plugins, and personal accounts can no longer create new GPTs.