Coding & Development prompts
Generate, debug, refactor, and explain code across languages.
Generate a function from a plain-English description
beginnerGenerates a production-ready function from a plain-English description; useful when you know what you need but don't want to write boilerplate from scratch.
You are an expert [LANGUAGE] developer. Write a clean, well-commented function that does the following: [DESCRIBE WHAT THE FUNCTION SHOULD DO]. Include: (1) the function signature with typed parameters where the language supports it, (2) inline comments explaining non-obvious logic, (3) a brief docstring or header comment, and (4) two example calls showing expected input and output. Use idiomatic [LANGUAGE] style.
How to use: Replace [LANGUAGE] with e.g. Python, TypeScript, or Go, and fill [DESCRIBE WHAT THE FUNCTION SHOULD DO] with a clear one-paragraph spec.
Debug a broken code snippet
beginnerSystematically finds and fixes bugs in a broken snippet; ideal when you have an error message or unexpected output and need a thorough diagnosis.
You are a senior [LANGUAGE] engineer and expert debugger. I have the following code that is supposed to [WHAT THE CODE SHOULD DO], but instead it [DESCRIBE THE ACTUAL WRONG BEHAVIOR OR ERROR MESSAGE]. Code: [PASTE YOUR CODE HERE] Please: (1) identify every bug, (2) explain why each bug causes the problem, (3) provide the corrected code in full, and (4) suggest one preventive practice to avoid each bug in the future.
How to use: Paste the exact error message or describe the wrong behavior precisely — vague descriptions yield vague fixes.
Explain code to a non-programmer
beginnerTranslates code into plain English for non-technical stakeholders; useful for documentation, onboarding, or code reviews with mixed audiences.
Explain the following [LANGUAGE] code to someone who has never programmed before. Use plain English, real-world analogies, and avoid jargon. After the explanation, list what the code ultimately produces or does in one sentence. Code: [PASTE YOUR CODE HERE]
How to use: If the audience has some technical knowledge, replace 'never programmed before' with their actual skill level for a better-calibrated explanation.
Convert code from one language to another
beginnerConverts a code snippet between programming languages while preserving logic; useful during technology migrations or polyglot projects.
Translate the following code from [SOURCE LANGUAGE] to [TARGET LANGUAGE]. Preserve all logic exactly. Use idiomatic [TARGET LANGUAGE] conventions (naming, error handling, standard library calls). If a direct equivalent does not exist for a feature, explain the closest alternative in a comment. Source code: [PASTE YOUR CODE HERE] Return only the translated code plus any necessary import/dependency statements.
How to use: Specify exact language versions or dialects if compatibility matters (e.g., 'ES2020 JavaScript' instead of just 'JavaScript').
Write unit tests for a function
intermediateGenerates a thorough unit test suite for a given function; ideal before shipping or when adding tests to legacy code.
You are a test-driven development expert. Write a complete unit test suite in [TEST FRAMEWORK] for the following [LANGUAGE] function. Cover: (1) the happy path with typical inputs, (2) edge cases (empty input, zero, null/None, maximum values), (3) expected exceptions or error states, and (4) any boundary conditions specific to this function's logic. Name each test descriptively. Function to test: [PASTE YOUR FUNCTION HERE]
How to use: Replace [TEST FRAMEWORK] with e.g. pytest, Jest, JUnit, or Go's testing package to get framework-specific syntax.
Refactor code for readability and maintainability
intermediateCleans up messy or legacy code while preserving behavior; useful during code reviews or technical debt sprints.
You are a senior software engineer focused on clean code. Refactor the following [LANGUAGE] code to improve readability and maintainability without changing its external behavior. Apply these principles: (1) single responsibility, (2) meaningful naming, (3) removal of duplication, (4) simplification of complex conditionals, and (5) consistent formatting. Original code: [PASTE YOUR CODE HERE] For each significant change you make, add a short inline comment starting with '# REFACTOR:' explaining why.
How to use: If you want to enforce a specific style guide (e.g., PEP 8, Google Style), mention it explicitly in the prompt.
Optimize code for performance
advancedIdentifies performance bottlenecks and produces a faster implementation; best used when profiling has shown a specific hotspot.
You are a performance-focused [LANGUAGE] engineer. Analyze the following code for performance bottlenecks and rewrite it to be as efficient as reasonably possible without sacrificing correctness. Context: This code runs [DESCRIBE FREQUENCY/SCALE, e.g., 'thousands of times per second on large datasets']. Original code: [PASTE YOUR CODE HERE] Provide: (1) a list of identified bottlenecks with brief explanations, (2) the optimized code, and (3) the time or space complexity of the original vs. the optimized version in Big-O notation.
How to use: Describe the actual scale and frequency of execution so the AI prioritizes the right optimizations (CPU vs. memory vs. I/O).
Add comprehensive error handling to existing code
intermediateRetrofits production-quality error handling onto unguarded code; essential before deploying scripts or services to production.
Review the following [LANGUAGE] code and add robust error handling throughout. For each place where something could go wrong (network calls, file I/O, type mismatches, external API failures, etc.), add appropriate error handling using [LANGUAGE]'s idiomatic approach (e.g., try/except, Result types, error returns). Also add meaningful error messages that include context about what was being attempted. Original code: [PASTE YOUR CODE HERE] Return the updated code and a brief summary of every error scenario you handled.
How to use: Specify whether you want errors to be logged, re-raised, or returned as values, so the style matches your architecture.
Design a REST API endpoint
intermediateDesigns a complete, standards-compliant REST endpoint including schema, responses, and a code stub; useful at the start of feature development.
You are a backend API architect. Design a RESTful API endpoint for the following feature: [DESCRIBE THE FEATURE, e.g., 'allowing users to upload a profile photo']. Provide: (1) the HTTP method and URL path following REST conventions, (2) the request body schema (JSON) with field names, types, and validation rules, (3) all possible response schemas with HTTP status codes and example payloads, (4) authentication/authorization requirements, and (5) a stub implementation in [LANGUAGE/FRAMEWORK].
How to use: Replace [LANGUAGE/FRAMEWORK] with e.g. 'Python/FastAPI' or 'Node.js/Express' for framework-specific code.
Explain a complex algorithm step by step
intermediateWalks through an algorithm with a concrete trace, complexity analysis, and real-world context; great for learning or code-review prep.
Explain the following algorithm to a developer who understands [THEIR SKILL LEVEL, e.g., 'basic data structures but not advanced algorithms']. Walk through it step by step using the concrete example input provided. After the walkthrough, state the algorithm's time and space complexity and one real-world use case. Algorithm code: [PASTE ALGORITHM CODE HERE] Example input to trace through: [PROVIDE A SAMPLE INPUT]
How to use: Provide a small but non-trivial input so the trace is illustrative without being exhaustingly long.
Generate a SQL query from plain English
beginnerTurns a plain-English data request into a well-structured, commented SQL query; ideal for analysts or developers working with unfamiliar schemas.
You are a SQL expert. Write a [SQL DIALECT, e.g., PostgreSQL / MySQL / SQLite] query that does the following: [DESCRIBE WHAT DATA YOU WANT TO RETRIEVE OR MODIFY]. Here is the relevant schema: [PASTE TABLE DEFINITIONS OR DESCRIBE TABLES AND COLUMNS HERE] Requirements: (1) use explicit JOIN syntax (not implicit), (2) alias all tables, (3) add a comment above each major clause explaining its purpose, and (4) note any indexes that would significantly improve performance.
How to use: Include actual column names and data types in the schema section for a more accurate query.
Identify and fix security vulnerabilities
advancedPerforms a security audit of a code snippet and produces fixed versions; critical before releasing user-facing or data-handling code.
You are an application security expert specializing in [LANGUAGE]. Audit the following code for security vulnerabilities. For each vulnerability found: (1) name the vulnerability type (e.g., SQL injection, XSS, insecure deserialization), (2) explain exactly how an attacker could exploit it, (3) rate its severity (critical / high / medium / low), and (4) provide the fixed code. Code to audit: [PASTE YOUR CODE HERE] Finish with a one-paragraph summary of the overall security posture.
How to use: Provide as much surrounding context as possible (framework, input sources, auth model) so the audit is accurate.
Create a regex pattern with explanation
intermediateProduces a correct regex with a full breakdown; useful when regex logic is complex or needs to be explained to teammates.
Write a regular expression that matches [DESCRIBE EXACTLY WHAT THE PATTERN SHOULD MATCH, including examples of strings that should and should not match]. Use [REGEX FLAVOR, e.g., PCRE / JavaScript / Python re]. Then provide: (1) the regex pattern, (2) a character-by-character breakdown explaining every part, (3) three example strings that match and three that do not, and (4) any known edge cases or limitations.
How to use: List concrete match/no-match examples upfront — the more specific your examples, the more accurate the pattern.
Scaffold a project file structure
intermediateProduces an opinionated, well-commented project scaffold; ideal at project kickoff to enforce consistency from day one.
You are an experienced [LANGUAGE/FRAMEWORK] architect. Generate a recommended file and folder structure for a [TYPE OF PROJECT, e.g., 'REST API with authentication and a PostgreSQL database']. For each file and folder, provide a one-line comment explaining its purpose. Then give starter boilerplate code for the three most important files. Follow current community best practices for [LANGUAGE/FRAMEWORK].
How to use: Describe the project's main features so the scaffold includes the right directories (e.g., tests, migrations, middleware).
Implement a design pattern
advancedProduces a domain-specific, runnable implementation of a classic design pattern; useful when you know the pattern name but need a contextual example.
Implement the [DESIGN PATTERN NAME, e.g., Observer / Strategy / Factory] design pattern in [LANGUAGE] for the following scenario: [DESCRIBE THE PROBLEM CONTEXT]. Provide: (1) a brief explanation of why this pattern fits the problem, (2) a complete, runnable implementation with classes/interfaces named after the domain (not generic 'ConcreteA' names), (3) a usage example showing the pattern in action, and (4) one trade-off or limitation to be aware of.
How to use: Describe a realistic domain scenario (e.g., 'an event notification system for an e-commerce order') for more practical code.
Write a database migration script
intermediateGenerates a safe, reversible database migration with rollback logic; critical when altering production schemas.
You are a database engineer. Write a database migration script for [ORM/MIGRATION TOOL, e.g., Alembic, Flyway, raw SQL] that performs the following schema change: [DESCRIBE THE CHANGE, e.g., 'add a non-nullable email_verified boolean column to the users table with a default of false']. Include: (1) the upgrade/forward migration, (2) the rollback/downgrade migration, (3) any necessary data backfill logic, and (4) a comment warning about any potential locking or downtime risk on large tables.
How to use: Mention table sizes or whether the DB is live so the AI can flag potential locking issues.
Implement pagination for an API
advancedAdds production-grade cursor-based pagination to an existing endpoint; useful when offset pagination causes performance or consistency problems.
Implement cursor-based pagination for the following [LANGUAGE/FRAMEWORK] API endpoint that currently returns all results at once. The endpoint fetches [DESCRIBE WHAT DATA IT RETURNS] from [DATABASE TYPE]. Existing endpoint code: [PASTE YOUR EXISTING ENDPOINT CODE HERE] Requirements: (1) accept 'limit' and 'cursor' query parameters, (2) return a 'next_cursor' in the response when more results exist, (3) ensure the cursor is opaque to the client, and (4) maintain consistent ordering even if new records are inserted.
How to use: Specify the primary sort key (e.g., created_at + id) so the cursor encoding is correct for your data model.
Generate data validation logic
intermediateCreates thorough input validation with structured error reporting; essential for any code that processes untrusted external data.
Write input validation logic in [LANGUAGE] for the following data object that comes from [DATA SOURCE, e.g., 'a public REST API request body']. Use [VALIDATION APPROACH, e.g., 'a schema validation library', 'manual checks', 'class-based validators'] if available in [LANGUAGE]. Data object fields and their rules: [LIST EACH FIELD, ITS TYPE, AND ITS VALIDATION RULES, e.g., 'email: string, required, valid email format'] Return a validation function that returns either a validated/typed object on success or a structured list of field-level error messages on failure.
How to use: Be explicit about required vs. optional fields and any cross-field rules (e.g., 'end_date must be after start_date').
Refactor callback-based code to async/await
intermediateModernizes legacy callback or Promise chain code to async/await; useful when updating older codebases for readability.
Refactor the following [LANGUAGE] code from a callback-based pattern to modern async/await syntax. Preserve all error handling and ensure that concurrent operations that were previously parallel remain parallel (use Promise.all or equivalent where appropriate). Original callback-based code: [PASTE YOUR CODE HERE] Annotate any place where you changed concurrency behavior with a comment explaining the decision.
How to use: Works best with JavaScript/TypeScript or Python asyncio; mention the runtime version if compatibility with older environments matters.
Write a CI/CD pipeline configuration
advancedGenerates a complete CI/CD pipeline config with caching, testing, and conditional deployment; great for setting up automation from scratch.
You are a DevOps engineer. Write a [CI/CD PLATFORM, e.g., GitHub Actions / GitLab CI / CircleCI] pipeline configuration file for a [LANGUAGE/FRAMEWORK] project that: (1) runs linting, (2) runs the full test suite, (3) builds a production artifact, and (4) deploys to [TARGET ENVIRONMENT, e.g., 'a staging server via SSH' or 'AWS Lambda'] only when merging to the main branch. Include caching of dependencies to speed up builds and add inline comments explaining each major step.
How to use: List any secrets or environment variables the pipeline will need so the AI includes the correct variable references.
Explain and simplify a complex regular expression
intermediateDemystifies a dense regex and produces a self-documenting version; ideal for code review or maintaining inherited patterns.
Explain the following regular expression in plain English, then rewrite it in a more readable way (using verbose/comment mode or named groups if the regex flavor supports it) without changing what it matches. Regex flavor: [REGEX FLAVOR, e.g., Python re / PCRE / JavaScript] Regex: [PASTE YOUR REGEX HERE] Also list three example strings it matches and three it does not.
How to use: Specify the language/flavor so the verbose syntax used in the rewrite is correct.
Implement a caching layer
advancedAdds a configurable caching layer to an expensive function call; useful when profiling shows repeated redundant work.
You are a backend engineer. Add a caching layer to the following [LANGUAGE] function that currently makes an expensive [TYPE OF CALL, e.g., 'database query' or 'external HTTP request'] on every invocation. Original function: [PASTE YOUR FUNCTION HERE] Requirements: (1) cache results using [CACHE STRATEGY, e.g., 'an in-memory LRU cache' or 'Redis'], (2) set a TTL of [TTL, e.g., '5 minutes'], (3) use the function's inputs as the cache key, (4) handle cache invalidation on [INVALIDATION EVENT, e.g., 'record update'], and (5) ensure the solution is thread-safe.
How to use: Specify whether you need distributed caching (Redis) or local caching based on your deployment model.
Generate a CLI tool with argument parsing
intermediateProduces a fully functional CLI tool with argument parsing, validation, and help text; ideal for automating developer workflows.
Write a command-line tool in [LANGUAGE] that does the following: [DESCRIBE THE TOOL'S PURPOSE AND BEHAVIOR]. Use the standard or most popular argument-parsing library for [LANGUAGE]. The tool must accept these arguments: [LIST ARGUMENTS, e.g., '--input FILE (required)', '--output DIR (optional, defaults to current directory)', '--verbose flag'] Include: (1) helpful --help text for every argument, (2) input validation with user-friendly error messages, (3) a non-zero exit code on failure, and (4) a usage example in a comment at the top of the file.
How to use: List all arguments with their types, whether they're required, and default values for the most accurate output.
Perform a code review with actionable feedback
intermediateDelivers structured, actionable code-review feedback across multiple quality dimensions; useful for self-review before submitting a PR.
You are a senior [LANGUAGE] engineer conducting a thorough code review. Review the following code as if it were a pull request submitted by a mid-level developer. Evaluate it across these dimensions: correctness, readability, performance, security, testability, and adherence to [LANGUAGE] best practices. Code: [PASTE YOUR CODE HERE] Format your feedback as a numbered list. For each issue: state the line or section, classify the severity (blocking / suggestion / nit), explain the problem, and provide the corrected or improved code snippet.
How to use: Add your team's specific style guide or constraints to the prompt so the review reflects your actual standards.
Architect a system for scale
advancedProduces a reasoned, scalable system architecture with failure analysis and a rollout plan; ideal at the start of a greenfield project.
You are a principal software architect. Design the high-level technical architecture for the following system: [DESCRIBE THE SYSTEM AND ITS CORE REQUIREMENTS, e.g., 'a real-time collaborative document editing service expected to handle 100,000 concurrent users']. Provide: (1) a component diagram described in text or ASCII art, (2) the technology choices for each layer (frontend, backend, data storage, messaging, caching) with justification, (3) how the design handles the top three failure scenarios, (4) the main scalability bottleneck and how you would address it, and (5) a phased rollout plan from MVP to full scale.
How to use: Include non-functional requirements (latency targets, data volume, team size) for a more tailored architectural recommendation.