Loading lessons...
Anatomy of a Great Prompt (Role, Task, Context, Constraints)
Asking an AI a vague question gets you a vague answer. Structuring your prompt with clear components dramatically improves output quality.
The 5 Pillars of a Great Prompt
- Role / Persona: Who the AI should act like (e.g., "Act as a Senior Backend Developer").
- Context: Background information the AI needs (e.g., "We are building an e-commerce API in Express.js").
- Task: The specific instruction (e.g., "Write a user registration route with bcrypt password hashing").
- Constraints: What the AI must NOT do or must adhere to (e.g., "Do not use third-party auth libraries. Keep code under 50 lines.").
- Output Format: How the response should look (e.g., "Provide code in a clean Markdown snippet with bulleted explanations.").
Bad Prompt vs Good Prompt
❌ Bad Prompt:
"Write a function for user signup."
js developer. js POST route for /api/register.
body, hash the password using bcryptjs with salt round 10, and return JSON { success: true }`. Use async/await and include try/catch error handling.