Getting generic, unusable code from your AI? The problem isn't the AI; it's how we ask.
Many of us treat AI like a vague search engine. I was getting bad responses until I stopped 'chatting' and started 'directing'. I developed a 5-step framework that completely changed the quality of my results. If you follow this, you'll see the difference immediately.
The Golden Rule: Always Set the Role First
Before you write a single command, tell the AI 'who it is'. This sets the context for its entire response.
Example:You are a senior full-stack engineer assigned to build a modern web application from scratch.
Now, 5-Step Prompt Framework
I structure my prompts using these five sections. This forces the AI to be specific and build exactly what I need.
1. Objective
State the "big picture" goal in one or two sentences.
- Create a secure REST API for a blog platform. It will handle user authentication and CRUD operations for posts.
2. Structure
Define your tech stack and architecture. Don't let the AI guess.
- Tech Stack: Use the MERN stack (MongoDB, Express.js, React
- Authentication: Use JSON Web Tokens (JWT).
- Backend: Follow a controller-service pattern.
3. Tasks
This is the most critical part. Break the objective down into small, clear, actionable chunks.
- Create 'User' and 'Post' MongoDB models.
- Implement user registration (with password hashing) and login (issuing a JWT).
- Create a middleware to verify the JWT for protected routes.
- Implement full CRUD operations for the 'Post' controller.
4. Output Requirements
Tell the AI *exactly* how you want the answer delivered.
- Provide complete code for each file (models, controllers, middleware).
- Use ES6 module syntax (import/export).
- Add brief inline comments for complex logic.
5. Notes
Add any final rules, constraints, or specifics.
- All async functions must use try/catch blocks for error handling.
- Do not return the user's password in any API response.
Top comments (0)