You paste code into ChatGPT. You ask it to "improve this." It responds with the exact same code plus comments explaining what each line does. Congratulations, you've wasted 30 seconds.

The difference between developers who swear by AI tools and those who think they're useless isn't the AI — it's the prompt. A bad prompt produces generic advice. A good prompt produces structured, actionable output with specific findings, severity ratings, and working fixes.

Here are the prompting patterns that actually work, with real examples.

The Problem: Generic Prompts Get Generic Output

Bad prompt:

> Review this code and suggest improvements.

What you get: "Consider adding error handling. The variable names could be more descriptive. You might want to add type hints."

This is the AI equivalent of a code review that says "looks good to me." It's technically not wrong, but it's not useful.

Pattern 1: Structured Output Format

The single most impactful change you can make to any prompt is specifying the output format.

Good prompt:

Review this Python function for bugs. For each bug found: 1. Line number and the buggy code 2. What's wrong (be specific) 3. What will happen if this reaches production 4. The fixed version of the code 5. Severity: Critical / High / Medium / Low Code: [your code here]

What you get: A numbered list of specific findings with exact line references, severity ratings you can sort by, and copy-paste fixes. This is a real code review, not a suggestion box.

Pattern 2: Role Assignment

AI models perform dramatically better when given a specific expertise role.

Without role:

> What's wrong with this SQL query?

With role:

You are a database performance engineer with 15 years of experience optimizing PostgreSQL at scale. Analyze this SQL query for performance issues, focusing on: - Missing or incorrect index usage - N+1 query patterns - Unnecessary joins or subqueries - Opportunities for query rewriting For each issue, show the EXPLAIN ANALYZE output you'd expect and provide the optimized version.

The role isn't just flavor text. It tells the model which domain knowledge to prioritize and what level of depth to operate at.

Pattern 3: Constraint Setting

Unconstrained prompts produce unconstrained output. Set boundaries.

Generate a Python function that validates email addresses. Constraints: - Use only the standard library (no third-party packages) - Must handle edge cases: empty strings, missing @, multiple @, dots in local part - Include docstring with examples - Include 5 unit tests using pytest - Function must be < 20 lines - Return a NamedTuple with (is_valid: bool, reason: str)

Every constraint eliminates a category of bad output. Without them, you'll get a function that pip install email-validator or one that's 200 lines of regex.

Pattern 4: Chain of Thought for Architecture

When asking AI to help with architecture decisions, force step-by-step reasoning.

I need to decide between PostgreSQL and MongoDB for a new e-commerce platform. Think through this step by step: 1. List the data models we'll need (users, products, orders, etc.) 2. For each model, identify the relationships and query patterns 3. Evaluate which patterns favor relational vs document storage 4. Consider operational complexity (backups, scaling, team expertise) 5. Make a recommendation with specific reasoning Context: - Team of 3 backend developers, all experienced with SQL - Expected load: 10K orders/day, 1M products, 50K users - Need full-text search on products - Must support complex reporting (revenue by category, cohort analysis)

This prevents the AI from jumping straight to "use PostgreSQL because it's popular." The step-by-step reasoning often surfaces considerations you haven't thought of.

Pattern 5: Example-Driven Prompts

Show the AI what good output looks like before asking for more.

I need to write error messages for API validation errors. Here's the pattern: Input: { "email": "" } Error: { "field": "email", "code": "required", "message": "Email address is required" } Input: { "email": "not-an-email" } Error: { "field": "email", "code": "invalid_format", "message": "Email must be a valid email address (e.g., user@example.com)" } Now generate error messages for these validation rules: - password: minimum 8 characters, must contain uppercase, lowercase, number - age: must be between 13 and 120 - username: 3-30 characters, alphanumeric and underscores only

The examples establish the tone, structure, and level of detail. Without them, you get inconsistent output that doesn't match your codebase's existing patterns.

Pattern 6: Debugging with Context

When debugging, the more context you provide, the better the analysis.

This Python function raises a KeyError intermittently in production. Function: [paste code] Stack trace: [paste traceback] What I've already tried: - Added logging: the key exists in 95% of requests - The error correlates with high-traffic periods - The dictionary is populated from a Redis cache Environment: - Python 3.11, Django 4.2 - 4 Gunicorn workers - Redis 7.0 Analyze the root cause considering: 1. Race conditions between workers 2. Redis cache eviction under load 3. Data serialization issues 4. Any other possible causes I haven't considered

The "what I've already tried" section prevents the AI from suggesting things you've already done. The environment details enable specific, actionable debugging steps.

Stop Writing Prompts From Scratch

These patterns work, but writing structured prompts from scratch every time is tedious. That's why I built prompt libraries for the most common developer tasks.

— Download 10 battle-tested prompts for security review, performance analysis, and code quality. Completely free.

Want the full set? The AI Prompts for Developers pack includes 120+ prompts covering code review, debugging, architecture, refactoring, testing, documentation, and more. Every prompt uses the structured patterns above to produce actionable, copy-paste-ready output.


What's your most effective AI prompting technique? Share your patterns in the comments.