Prompt engineering is the skill of crafting effective inputs for AI models to get the output you want. For developers, it's the difference between mediocre AI suggestions and production-ready code.
The CRAFT Framework
Use this framework for every coding prompt:
What's the project? What technology stack? What's already built?
What exactly do you need? Be specific about inputs, outputs, edge cases.
Any preferred patterns or constraints? What should it avoid?
How should the output be structured? Code only? With explanation?
How will you verify it works? Include test cases if relevant.
Essential Patterns
Pattern 1: The Role Pattern
You are a senior software engineer with 15 years of experience in TypeScript and React. You follow clean code principles and always consider edge cases. [Your actual question here]
Pattern 2: The Step-by-Step Pattern
Create a user authentication system. Think step by step: 1. First, design the database schema 2. Then, create the API endpoints 3. Finally, implement the frontend forms Show your reasoning before each step.
Pattern 3: The Example Pattern
Create a function similar to this: Example input: [1, 2, 3, 4, 5] Example output: [2, 4, 6, 8, 10] But instead of doubling, the function should [your requirement].
Pattern 4: The Constraints Pattern
Write a sorting algorithm with these constraints: - Must be O(n log n) time complexity - Must use no extra space (in-place) - Must be stable - Must handle null values
Pattern 5: The Refinement Pattern
Here's my current code: [paste code] Improve it by: 1. Adding error handling 2. Improving performance 3. Adding TypeScript types 4. Following React best practices Explain each change you make.
Advanced Techniques
Chain of Thought
I need to optimize this database query that's taking 30 seconds. Walk me through your analysis: 1. What could cause this slowness? 2. How would you diagnose it? 3. What solutions would you try? 4. Implement the most likely solution. [query here]
Few-Shot Learning
Convert these SQL queries to Prisma:
SQL: SELECT * FROM users WHERE active = true
Prisma: await prisma.user.findMany({ where: { active: true } })
SQL: SELECT * FROM posts WHERE author_id = 1
Prisma: await prisma.post.findMany({ where: { authorId: 1 } })
Now convert:
SQL: SELECT * FROM orders WHERE status = 'pending' AND total > 100
Negative Prompting
Create a React form component. DO: - Use controlled components - Include validation - Handle loading states DON'T: - Use class components - Use any external libraries except React - Include inline styles
Common Mistakes to Avoid
- Too vague: "Make it better" → Specify what "better" means
- No context: Always explain your environment and constraints
- Ignoring errors: If AI gives an error, provide the full message
- Not iterating: First response isn't always best; refine it
My Coding Team: Beyond Manual Prompting
While prompt engineering is valuable, it's time-consuming. At My Coding Team, we've built systems that handle prompting automatically—our squad of 8 AI specialists knows exactly how to prompt each other for optimal results.