Prompting 101: How to Talk to AI

The quality of AI-generated code depends entirely on how well you communicate. Learn the fundamentals of prompt engineering to get dramatically better results from AI coding tools.

Why Prompting Matters

AI coding tools are incredibly powerful, but they're not mind readers. The same AI that generates buggy, incomplete code for one person can produce production-ready solutions for another. The difference? How they ask.

Think of prompting like giving directions. "Go somewhere nice" will get you lost. "Take Highway 101 North for 3 miles, exit at Main Street, turn right" will get you exactly where you want to go.

The 80/20 Rule of AI Coding: 80% of your results come from 20% of your effort—and that 20% is crafting good prompts. Master prompting, and you'll dramatically outperform those who don't.

Anatomy of a Good Prompt

Every effective prompt has four key components:

1. Context

Tell the AI what it's working with. What's the project? What technologies are involved? What already exists?

❌ No Context
"Add a login form"
✓ With Context
"I'm building a React app with Tailwind CSS. Add a login form to my existing AuthPage component."

2. Intent

Be explicit about what you want to achieve. Don't assume the AI knows your goal.

❌ Vague Intent
"Make the API faster"
✓ Clear Intent
"Add caching to the /users endpoint to reduce database queries. Cache should expire after 5 minutes."

3. Constraints

Specify boundaries, requirements, and preferences. What should the AI NOT do? What patterns should it follow?

❌ No Constraints
"Create a database schema"
✓ With Constraints
"Create a PostgreSQL schema for users. Use UUID for IDs, include created_at/updated_at timestamps, and add an index on email."

4. Examples (Optional but Powerful)

Show the AI what you want. Examples are worth a thousand words of instruction.

Example: Showing the AI Your Preferred Style
Create API endpoints for the Product model following this pattern: // Example from my User controller: export const getUsers = async (req, res) => { try { const users = await User.findAll(); res.json({ success: true, data: users }); } catch (error) { res.status(500).json({ success: false, error: error.message }); } }; Apply the same pattern for: getProducts, getProductById, createProduct, updateProduct, deleteProduct

Essential Prompting Patterns

The Step-by-Step Pattern

For complex tasks, break them down into steps. This helps the AI follow a logical process.

Step-by-Step Prompt
Help me implement user authentication: 1. First, create the User model with email and hashed password 2. Then, create a registration endpoint that validates input and hashes the password 3. Next, create a login endpoint that verifies credentials and returns a JWT 4. Finally, create middleware to protect routes Let's start with step 1.

The Role Pattern

Tell the AI to act as a specific type of expert. This shapes its responses.

Role Pattern Prompt
Act as a senior backend engineer who specializes in Node.js and PostgreSQL. Review this database query and suggest optimizations for handling 100k+ rows: [your query here]

The Refinement Pattern

Start broad, then iterate. Don't try to get everything perfect in one prompt.

Refinement Flow
Prompt 1: "Create a basic React component for a todo list" Prompt 2: "Add the ability to mark items as complete" Prompt 3: "Add local storage persistence" Prompt 4: "Add animations when items are added or removed"

Common Prompting Mistakes

Being Too Vague

Vague prompts get vague results. "Make it better" tells the AI nothing. "Improve error handling by adding try-catch blocks and user-friendly error messages" tells it exactly what you want.

Asking for Too Much at Once

Don't ask for an entire application in one prompt. Break it into manageable pieces. Build incrementally.

Warning: The more you ask for in a single prompt, the more likely the AI is to hallucinate, make assumptions, or produce inconsistent code. Keep requests focused.

Not Providing Feedback

AI tools learn from your feedback within a session. If something isn't right, don't just regenerate—explain what's wrong and what you want instead.

❌ No Feedback
"That's wrong, try again"
✓ Specific Feedback
"The function works but returns an array when I need an object. Change the return type to { items: [...], count: number }"

Advanced Techniques

Ask the AI to Think Out Loud

For complex problems, ask the AI to explain its reasoning before coding. This catches logical errors early.

Think-Out-Loud Prompt
Before writing any code, explain your approach to implementing a rate limiter that: - Allows 100 requests per minute per user - Uses Redis for distributed state - Gracefully handles Redis connection failures Once I approve your approach, implement it.

Negative Prompting

Tell the AI what NOT to do. This prevents common AI habits you don't want.

Negative Prompting
Create a data fetching hook for React. Do NOT: - Use class components - Add console.log statements - Include comments explaining basic JavaScript - Use any deprecated React patterns DO: - Use TypeScript - Handle loading, error, and success states - Support abort on unmount

Few-Shot Learning

Give multiple examples to establish a pattern. The AI will extrapolate.

Few-Shot Example
Convert these API responses to TypeScript interfaces: Example 1: Input: { "id": 1, "name": "John", "active": true } Output: interface User { id: number; name: string; active: boolean; } Example 2: Input: { "orderId": "abc", "items": [], "total": 99.99 } Output: interface Order { orderId: string; items: unknown[]; total: number; } Now convert this: Input: { "productId": 123, "title": "Widget", "price": 29.99, "inStock": true, "tags": ["sale", "new"] }

Tool-Specific Tips

Claude Code / CLI Tools

  • Provide file paths when referencing existing code
  • Use the tool's ability to read your codebase—ask it to "look at" files
  • Be explicit about which files to modify vs. create

Cursor / IDE Integrations

  • Highlight the specific code you want changed before prompting
  • Use inline comments as prompts for context-aware suggestions
  • Reference other files in your project by name

v0.dev / Component Generators

  • Describe visual layout in detail (grid, flexbox, spacing)
  • Specify responsive behavior explicitly
  • Reference design systems or component libraries you want to match

Practice Exercises

Try these exercises to build your prompting skills:

  1. Refactor this prompt: "Make a website" → Write a detailed prompt that would actually produce a useful result.
  2. Add constraints: Take any simple prompt and add 3 meaningful constraints that would improve the output.
  3. Create examples: Write a prompt that teaches the AI your coding style using 2-3 examples.

Key Takeaway: Great prompts are investments. Spending 2 minutes crafting a clear prompt saves 20 minutes of fixing AI mistakes. The best AI coders aren't the ones who type fastest—they're the ones who communicate clearest.