How to Write Effective AI Prompts: A 6-Part Framework
Most people write prompts the way they would ask a colleague a question, then feel let down by the answer. The difference is that a colleague shares your context and an AI model does not. An effective prompt supplies six things: role, task, context, format, constraints and examples. Get those right and output quality stops being random.
This guide gives you that framework, a diagnostic method for fixing weak prompts, and the specific habits that separate people who get consistent results from people who get occasional ones.
Why most prompts fail
Three failure modes account for almost every bad output.
The prompt is ambiguous. "Summarise this" does not say for whom, how long, or what to emphasise. The model picks defaults, and the defaults are average.
The prompt assumes shared context. You know the audience, the history and the constraints. The model knows only what is in front of it.
The prompt describes instead of demonstrating. Three sentences describing the tone you want are less effective than one example of it.
The 6-part framework
1. Role
Tell the model what perspective to adopt. This shifts vocabulary, assumed knowledge and depth.
Weak: "Explain database indexing." Better: "You are a senior backend engineer explaining database indexing to a junior developer in a code review."
Use a role when domain framing matters. Skip it for simple factual lookups.
2. Task
State exactly what you want done, in the imperative, with one primary verb. Ambiguity here causes more bad output than anything else.
Weak: "Can you help me with my resume?" Better: "Review my resume against this job description and list what is missing, what is weak and what to cut."
If your task contains multiple verbs, consider splitting it into separate prompts.
3. Context
Supply what the model cannot infer: audience, purpose, constraints, what you have already tried, and what has already failed.
Weak: "Suggest project ideas." Better: "Suggest project ideas for a final year computer science student who knows Python and SQL but has never deployed anything, and wants a portfolio piece for data analyst roles."
Context is where most of the quality gain lives. When in doubt, add more.
4. Format
Specify the shape of the output: length, structure, medium.
Weak: "Compare these options." Better: "Compare these three options in a table with columns for cost, learning curve, and best use case. Then give a one sentence recommendation."
Unspecified format is why output arrives as an unusable wall of text.
5. Constraints
Define the boundaries: tone, what to avoid, length limits, and crucially, what to do when uncertain.
Useful constraints include "no jargon", "under 200 words", "do not invent statistics", and "if the source does not contain the answer, say so explicitly". That last one is the single most effective guard against fabricated content.
6. Examples
Show one or two samples of the output you want. This is the highest leverage component and the most skipped.
If you have corrected the same issue twice, stop describing the fix and paste an example instead. One good example locks in format and style faster than a paragraph of instruction.
The framework as a checklist
A diagnostic method for fixing bad prompts
Do not rewrite from scratch. Diagnose the specific defect and apply the matching fix.
This diagnostic habit is what turns prompting from trial and error into a skill.
Advanced habits that compound
Iterate rather than restart. Tell the model what to change: "Keep the structure, make section two more concrete, cut the introduction by half."
Decompose long tasks. Outline first, then sections, then a critique pass. Complex output produced in one shot is almost always shallow.
Ask for reasoning on hard problems. Requesting step by step working improves accuracy on logic and analysis, and makes errors visible.
Ask the model to interrogate you. For decisions and planning, "ask me the five questions that would most clarify this" often produces more value than any answer would.
Build a prompt library. Save prompts that worked. This compounds faster than any other habit, and it is the basis of how prompts get reused inside real systems and AI agents.
Where prompt writing stops being enough
Prompting handles a single interaction well. Once you need consistency across thousands of runs, factual grounding in your own data, or multi step autonomy, you move into system design: retrieval pipelines, evaluation, and orchestration. The boundary between those approaches is covered in prompt engineering vs RAG vs fine tuning.
That transition is also where the earning potential sits. Understanding how models behave underneath the prompt, which is what applied AI and machine learning programmes teach, is what lets you debug a prompt instead of guessing at it.
Frequently asked questions
What is the best structure for an AI prompt? Role, task, context, format, constraints and examples. You will not need all six every time, but checking against them diagnoses almost any weak prompt.
How long should a prompt be? Long enough to remove ambiguity. Extra context and examples usually help, while extra adjectives usually do not.
Why does my AI output keep ignoring part of my instruction? Usually because the prompt contains too many separate tasks. Split it into sequential prompts.
How do I stop an AI from making things up? Provide the source material in the prompt and add an explicit instruction to say so when the answer is not present in that source.
Do I need examples in every prompt? No. Add them when format or style keeps drifting, or when the task is unusual enough that description alone is not landing.
Related reading: Prompt engineering complete guide | 50+ AI prompt examples | What is agentic AI