Here's a messy prompt:
Level 1: Take a prompt apart and rebuild itReorganize it using the four-element framework (role, task, format, constraints) so it's clearer.
Learning goals:
- Master the four core elements of a prompt
- Learn to turn a vague request into a structured instruction
- Understand how each element shapes the AI's output
Prerequisites: << Lesson 1: What a Prompt Is, and Why It Matters | Next: Lesson 3 >>
You ask the AI to "write a project summary" and it hands you a generic template with none of your project's actual details. Where did it go wrong? It isn't that the AI lacks the ability. Your instruction was missing the pieces that matter: what project is this, who's it for, what should it contain, and what format should it take.
An effective prompt isn't one line thrown over the wall. It's a complete instruction built from four elements. This lesson covers what those four elements are, what each one does, and how to combine them.
A clear prompt usually contains four parts1:
You don't need all four every time, but the more complex the task, the more elements it needs. Let's look at each one.
Role tells the AI what perspective and level of expertise to answer with2. The same question gets a completely different answer from a technical expert versus an elementary school teacher.
Compare these two prompts:
Without a role:
The AI might give you:
With a role:
Now the AI will:
Common role patterns:
Task is the heart of the prompt. It answers the "what do you want done" question1. A vague task description is the single most common problem.
Compare:
Vague task:
The AI has no idea which angle to take: performance? security? readability? bugs?
Clear task:
Now the AI knows:
A task has three layers:
Format tells the AI how to organize its answer1. With no format constraint, the AI picks whatever it thinks fits: maybe a wall of text, maybe a list, maybe a table.
Compare:
No format requirement:
The AI might give you:
Specified format:
The AI will follow this structure exactly, and you can paste the result straight into your own document.
Common format constraints:
Constraints are the "don't..." and "only..." rules that keep the AI from wandering off track1.
Compare:
No constraints:
The AI might give you:
With constraints:
Now the AI will:
Common constraint types:
A complete prompt brings all four elements together. Here's a real scenario.
Scenario: have the AI draft meeting notes
Task only, missing the other elements:
All four elements:
This prompt is clear, complete, and reusable. Turn the transcript part into a placeholder and you have a template you can run again and again. Next meeting, you only swap in the new transcript.
Now let's practice turning a vague prompt into a structured one.
Step 1: pin down the task
Step 2: add a role
Step 3: specify the format
Step 4: add constraints
Compared to the original, the rewrite tells the AI clearly: what role to take, what to do, how to output, and under what limits.
The four elements aren't dogma, they're a checklist:
The test is simple: after reading your prompt, can the AI know exactly what to do and what result to produce? If you can't answer that clearly yourself, the AI has even less chance.
An effective prompt contains four elements: role (what identity), task (what to do), format (how to organize), and constraints (what the boundaries are). You don't use all four every time, but the more complex the task, the more complete the set of elements it needs.
The rewrite process: pin down the core task first, then decide what role, what output format, and what constraints it needs. Expand a vague one-liner into a structured instruction and the quality of the AI's output rises sharply.
Next lesson covers few-shot learning: how to use 2-5 examples to make the AI understand the pattern you want, instead of describing it in words.
Next lesson Few-Shot Learning: Guiding AI with Examples >>
OpenAI Prompt Engineering Best Practices — https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-the-openai-api ↩ ↩2 ↩3 ↩4
Anthropic Prompt Engineering Overview — https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/overview ↩
Reorganize it using the four-element framework (role, task, format, constraints) so it's clearer.
Design a complete prompt with all four elements.
Explain what Docker is.You are a teacher who's good at explaining technical concepts througheveryday analogies. Explain what Docker is to a product manager who hasno programming background.Analyze this code.Analyze this Python code for performance bottlenecks. Point out whichoperations could get slow with large datasets, and suggest how to fix them.Summarize the key points of this article.Summarize this article in this format:
Core argument: [one sentence]
Supporting evidence (3 points):1. [point 1, one sentence]2. [point 2, one sentence]3. [point 3, one sentence]
Conclusion: [one sentence]Recommend some resources for learning Python.Recommend 3 resources for learning Python. Requirements:- Completely free- In English- Suitable for absolute beginners- Includes hands-on projects
Describe each resource in two sentences: the first says what it is, thesecond says why it suits a beginner.Write up notes from this meeting transcript.[Role] You are an experienced project assistant.
[Task] Write meeting notes from the transcript below.
[Format] Organize it like this:- Meeting basics (time, attendees)- Issues discussed (ordered by priority)- The decision reached on each issue- Action items (owner + due date)
[Constraints]- Only record discussions that reached a clear conclusion; skip small talk- Every action item must be actionable (a verb + a checkable deliverable)- Keep the whole thing under 500 words
Transcript:[paste the transcript here]Optimize this code for me.You are a senior performance engineer.
Analyze the Python code below for performance problems and suggest fixes.
Output in this format:1. Current bottlenecks (ordered by impact, largest first) - Description of the bottleneck - At what data volume it becomes a problem2. Optimization plan - Specific change to make - The optimized code snippet - Expected performance gain
Constraints:- Don't change the function's input/output interface- Don't introduce new external dependencies- Prioritize changes that give at least a 2x speedup
Code:[paste the code here]Write a function, input is a list of strings, output is the deduplicatedresult, make it fast, use Python, add comments.