Prompting Guide for Developers
Prompts for Writing Code
AI doesn''t replace the developer — it makes them faster and more efficient. A good code generation prompt can save you hours of development time, provided you know how to communicate precisely what you want.
Principles of an Effective Code Prompt
The golden rule: the more specific your prompt, the better the generated code. Always include:
- Language and framework: "in TypeScript with Next.js 14" — not just "in JavaScript"
- Project conventions: "using named exports, interfaces over types, and @/* import aliases"
- Technical context: dependency versions, existing architecture, patterns used
- Edge cases: error handling, null/undefined cases, input validation
- Performance constraints: "must handle 10K requests/second", "optimized for bundle size"
React Component Template Prompt
Create a React component in TypeScript for [functional description]. Stack: Next.js 14, Tailwind CSS 4, next-intl for i18n. The component should: 1) use Server Components by default (add ''use client'' only if necessary), 2) type all props with an exported interface, 3) handle loading and error states, 4) be accessible (ARIA labels, keyboard navigation), 5) be responsive (mobile-first). No default exports.
API Endpoint Template Prompt
Create a REST API endpoint in [language/framework] for [functionality]. The endpoint must: 1) validate inputs with [Zod/Joi/other], 2) handle authentication via [method], 3) return appropriate HTTP codes (200, 400, 401, 404, 500), 4) include exhaustive error handling with explicit messages, 5) log errors with debugging context, 6) be documented with JSDoc comments.
Debugging with AI
Debugging is perhaps the use case where AI shines most for developers. It can analyze stack traces, identify subtle bugs, and propose fixes in seconds.
Error Analysis Prompt
I have this error in my [language/framework] application:
[paste complete error with stack trace]
Context: [describe what the code should do, when the error occurs].
Relevant code: [paste code].
1) Explain the likely cause, 2) Propose a fix with modified code, 3) Explain why the fix resolves the issue, 4) Identify any similar problems in the shown code.
Intermittent Bug Prompt
I have an intermittent bug in [context]. It manifests as [symptoms] and occurs approximately [frequency]. Environment: [prod/staging/dev]. Here''s what I''ve already checked: [list]. Here are the relevant logs: [logs]. Propose an ordered list of hypotheses (most to least probable) with for each: 1) why this hypothesis, 2) how to verify it, 3) how to fix if confirmed.
Refactoring and Code Review
AI is an excellent refactoring partner. It can analyze legacy code, identify code smells, and propose improvements while preserving functional behavior.
Complete Refactoring Prompt
Here is a module/component/function I want to refactor:
[paste code]
Constraints: 1) functional behavior must remain identical, 2) improve readability and maintainability, 3) follow SOLID principles, 4) extract magic constants, 5) improve variable and function naming, 6) add missing TypeScript types. Provide: the complete refactored code, and a summary of changes with justifications.
Code Review Prompt
You are a senior developer doing a thorough but constructive code review. Review this code:
[paste code or diff]
Evaluate on: 1) Correctness, 2) Security (injection, XSS, etc.), 3) Performance, 4) Maintainability, 5) Test coverage. For each issue, indicate severity (critical/major/minor/suggestion) and propose a fix.
Automated Testing
Writing tests is often the least enjoyed part of development, but it''s also where AI can deliver considerable value.
Unit Testing Prompt
Write comprehensive unit tests for this function/module:
[paste code]
Test stack: [Vitest/Jest/Pytest/other]. Cover: 1) all nominal cases (happy path), 2) edge cases (empty inputs, null, undefined, very large numbers, special strings), 3) error cases (invalid inputs, network errors, timeouts), 4) concurrency cases if applicable. Use descriptive test names. Organize tests with describe/it logically. Mock external dependencies.
E2E Testing Prompt
Write an E2E test with [Playwright/Cypress] for the following user journey: [step-by-step description]. The test should: 1) use robust selectors (data-testid preferred), 2) explicitly wait for elements (no sleep), 3) verify each step, 4) take screenshots at key steps, 5) handle failure cases gracefully.
Architecture and Documentation
AI can help you make informed architectural decisions and produce quality technical documentation — two activities often neglected due to time constraints.
Architecture Design Prompt
I need to design the architecture for [feature/system]. Constraints: 1) Tech stack: [stack], 2) Expected load: [metrics], 3) Infra budget: [budget], 4) Team: [size and seniority], 5) Timeline: [timeline]. Propose 2-3 architectural approaches with pros, cons, implementation complexity, estimated cost, and scalability for each. Recommend your preferred choice with justification.
Developer + AI Best Practices
What AI Does Well
- Boilerplate and repetitive code: CRUD, migrations, configurations, types
- Language/framework translation: Python to TypeScript, REST to GraphQL
- Code comprehension and explanation: legacy code, complex algorithms
- Test generation: from existing code, it identifies cases to test
- Documentation: JSDoc, README, ADR, code comments
What AI Does Poorly (or Dangerously)
- Large-scale system architecture: it lacks holistic vision of your codebase
- Security-critical code: authentication, cryptography — always have an expert review
- Advanced performance optimization: subtle optimizations require real profiling
- Business decisions: which feature to build, which tech debt to pay — that''s your job
Security Rules to Follow
- Never paste secrets (API keys, tokens, passwords) into a prompt
- Always review generated code before merging
- Don''t trust suggested dependencies: verify they exist, are maintained, and have no known CVEs
- Watch for API hallucinations: AI can invent methods or parameters that don''t exist
Go further with our developer prompt library and practice with our technical prompting exercises. Also discover how AI agents can automate your development workflows.
Related Prompts
Design an Application Caching Strategy
Design a complete Redis caching strategy with appropriate patterns, TTL policy, invalidation, and stampede protection.
Refactor Legacy Code Step by Step
This prompt guides AI to analyze legacy code and produce a structured refactoring plan with diagnosis, prioritization, tests, and modernized code.
Write Comprehensive Unit Tests
Generate an exhaustive unit test suite covering nominal cases, edge cases, and errors with appropriate mocks.
Debug a Production Error
Quickly analyze a production error with a structured Root Cause Analysis approach and an immediate action plan.
Complete Code Review for Pull Requests
Get an exhaustive code review covering quality, performance, security, and maintainability for any language.
Document Code with JSDoc/TSDoc
Generate professional and complete JSDoc/TSDoc documentation for your functions and classes with concrete examples.
Practice Exercises
Providing Context
Master the art of giving the right context to AI for relevant results.
Role Prompting
Use role assignment to get expert-level responses.
Structured Output / JSON
Get structured JSON responses that can be processed by code.
System Prompt Design
Design a complete system prompt for a professional chatbot.
Chain-of-Thought Reasoning
Force the AI to reason step by step for complex decisions.
Code Generation
Generate production-ready code with structured prompts.
Continue your learning
You've finished this guide. Here's how to go further.
Practice what you learned
Interactive exercises to sharpen your prompting skills
Get new guides every week
Join our newsletter and never miss new content.