Clear instructions, roles & context
Write prompts with explicit task, context, constraints and output format.
By Invicly Tech, , in AI Engineering with Python. About 12 minutes to read.
In short
Good prompts read like clear instructions to a smart new colleague: the task, the relevant context, the constraints and the exact output format. Clarity beats clever tricks.
Explained simply
A prompt is the text you give a model to tell it what to do. The model cannot ask you what you meant, see your screen, or know your company. Everything it needs has to be in the prompt.
A useful test: imagine handing your prompt to a smart new colleague on their first day. Would they know exactly what to produce, for whom, and how long it should be? If they would need to ask questions, the model needs those answers written down too.
Good prompts usually have the same parts: the task in one clear sentence, the background the model needs, the rules (length, tone, what to avoid, what to do when unsure), and the exact shape of the answer. Clear and specific beats clever wording.
Prompting is a loop, not a one-time job. Write a first version, try it on 10 or 20 real inputs, read the bad answers, and fix one thing at a time. Most improvements come from adding a missing detail, not from magic phrases.
Press Play on a diagram to walk through it one step at a time.
- 1Role
Who the model is acting as, and for whom
- 2Task
One explicit instruction of what to do
- 3Context
Relevant facts, data and audience
- 4Constraints
Length, tone, what to avoid, what if unsure
- 5Output format
Exact structure, such as JSON or three bullets
- Summarise this
- No audience or purpose
- No length or format
- Nothing about missing info
- Summarise for the on-call engineer
- Used to decide who to page
- 3 bullets, error codes included
- If unclear, reply Needs clarification
- Email inside labelled tags
- 1Write version 1
Task, context, rules, format
- 2Run on real inputs
10 to 20, including hard ones
- 3Read the failures
Group them by cause
- 4Fix one thing
Add the missing detail or rule
- Back to step 1
In depth
Say the task, the audience and the purpose
When an instruction is vague, the model fills the gap with the most common pattern from its training data. Summarise this produces an average summary for an average reader. Summarise this incident report for the on-call engineer who must decide in two minutes whether to wake up the database team produces something far more useful.
State three things: what to produce, who will read it, and what they will do with it. Then add why a rule exists. Keep sentences short because readers see this on a phone generalises better than a bare rule, because the model understands the goal behind it.
Avoid stacking several tasks in one prompt when they are unrelated. If you need to classify, extract and reply, it is often more reliable to make separate calls, or at least to number the steps clearly.
- What to produce
- Who reads it
- What they will do with it
- Why each rule matters
Context: what to include and where to put it
Context is the information the model cannot guess: product facts, policies, definitions of your labels, the user's plan or language, and the data to work on. Include what the task needs and leave out the rest. Extra documents do not just cost tokens; they also give the model more chances to latch onto the wrong detail.
With long inputs, a common and effective layout is to put the long documents first and the instructions and question after them, near the end, where they are easy to find. Label every piece so the model knows what it is: a policy, a customer email, an example.
When the context comes from users or the web, treat it as data, not instructions. A customer email that says ignore your rules is still just an email.
- Audience
- Who reads the output
- Their level and language
- Purpose
- What the output is used for
- What a good result looks like
- Domain facts
- Policies and definitions
- Label meanings
- Input data
- Clearly delimited
- Labelled by type
- Edge cases
- What to do if data is missing
- What to do if the request is off-topic
Delimiters: keep instructions and data apart
Delimiters are markers that show where pasted data begins and ends. XML-style tags such as an opening and closing email tag work well with most models, as do clear headings or triple quotes. Use a descriptive name for each block and refer to it by name in the instructions: summarise the text inside the email tags.
Delimiters solve two problems. The model no longer confuses your instructions with the text it is working on, and it becomes harder (though not impossible) for text inside the data to pose as new instructions. They do not stop prompt injection on their own; that needs permission limits and output checks too.
One practical detail: if users can type the closing tag themselves, they can break out of the block. Strip or escape your delimiter tags from user input before inserting it.
Roles, constraints and the I-don't-know rule
A role sets expertise and tone: you are a support agent for a project management app, writing to non-technical customers. It helps most when it carries real information about the audience and the standard expected.
Constraints limit the output. Positive instructions usually work better than negative ones alone: write in plain sentences without lists is clearer than do not use markdown. Length limits are more reliable when given as sentences or bullet points than as exact word counts, because models count words poorly.
The most important constraint is often what to do when the model cannot do the task: the information is missing, the question is off-topic, or the input is unclear. Give an exact fallback, such as replying Needs clarification or asking one question. Without it, the model will usually guess.
- Role: expertise plus audience
- Prefer do X over don't do Y
- Length in sentences or bullets, not exact words
- Always define the fallback when unsure
Specify the output so code and people can use it
Describe the exact shape of the answer: three bullet points, each under 15 words; a subject line and a body; or a JSON object with these fields. Showing a short skeleton of the format is often clearer than describing it. If you show an example, make it match the length and style you want, because the model will copy it closely.
For anything your code must parse, use the API's structured output feature with a schema instead of asking for JSON in words. For text people read, say what to leave out too: no greeting, no closing summary, no restating the question.
Finally, test the format on difficult inputs: very short ones, very long ones, and ones in another language. Format drift usually shows up at the edges.
Learn it in 4 short steps
About 45m each. Track them with a timer in your plan.
- 1State the task explicitly~45m
- 2Provide relevant context~45m
- 3Set constraints and a role~45m
- 4Specify the output format~45m
Key points
- Say exactly what you want; models do not read your mind.
- Separate instructions from data with clear delimiters like tags or headings.
- Tell the model what to do when information is missing.
- Specify the output format so code can parse it reliably.
Key terms
Tap a card to flip it. 0/4 known
Examples
PROMPT = '''You are a support assistant for a project management app.
Task: Summarise the customer email below for an engineer.
Rules:
- Maximum 3 bullet points.
- Include the product area and any error messages.
- If the issue is unclear, say "Needs clarification".
Output format: bullet points only, no intro.
<email>
{email}
</email>'''Role, task, rules, format and clearly delimited input.
From a one-line request to a usable prompt
Marketing asks for release notes, and Write release notes for these changes gives a long, salesy text with internal ticket numbers. Step 1: name the audience (existing customers, not developers) and the purpose (see what changed and whether they must act). Step 2: add rules learned from the bad output: no ticket numbers, no hype words, one line per change. Step 3: say what to do with internal-only changes. Step 4: give the exact format. Step 5: put the raw changes in labelled tags at the end.
You write release notes for existing customers of a project management app.
Readers want to know what changed and whether they need to do anything.
Rules:
- One line per change, plain language, no marketing words.
- Never include ticket numbers or internal names.
- Skip changes marked internal; do not mention them at all.
- If a change needs customer action, start the line with "Action needed:".
Format: three headings (New, Improved, Fixed), each followed by bullet lines.
Leave out any heading that has no items.
<changes>
{changes}
</changes>Telling the model what to do when data is missing
You extract action items from meeting notes, and the model invents owners when nobody was named. Step 1: define what counts as an action item. Step 2: give an exact value for missing owners and dates, so the model has a correct option other than guessing. Step 3: define the empty case, so a meeting with no actions returns a fixed phrase instead of made-up tasks. Step 4: test on notes that have no owners and no actions at all.
Task: list the action items from the meeting notes below.
An action item is a task someone agreed to do after the meeting.
For each item write: task | owner | due date
- If no owner was named, write "unassigned". Never guess a name.
- If no date was given, write "no date".
- If there are no action items, reply exactly: No action items.
<notes>
{notes}
</notes>Quick reference
- State the task, the audience and what the output is used for
- Explain why a rule exists; the model generalises from the reason
- Put long documents first and the instructions and question near the end
- Wrap pasted data in labelled tags and refer to them by name
- Strip your delimiter tags from user input so it cannot break out
- Give length in sentences or bullets, not exact word counts
- Always say what to do when information is missing or unclear
- Machine-read output: use structured output with a schema, not JSON in words
Common mistakes
- Writing vague prompts like make this better.
- Mixing instructions and user data so the model confuses them.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Rewrite the prompt Explain Docker so that it names the audience, the purpose, a length limit and an output format.
- Exercise 2medium
Write a prompt that summarises customer emails for engineers, run it on 10 emails (including one off-topic and one in another language), and list every failure you see.
- Exercise 3hard
Build a small prompt test: 15 inputs with notes on what a good answer must contain. Score two prompt versions on the same inputs and decide which to keep.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Does saying you are an expert make the model smarter?
- A bare role gives a small effect at most. A role that carries real information, such as who the audience is and what standard is expected, helps much more.
- Should I write prompts in capital letters or say IMPORTANT?
- Usually not needed with current models, and it can make them over-apply a rule. Explain the rule and why it matters instead.
- Where should instructions go: system prompt or user message?
- Put stable rules and the role in the system prompt, and the specific task and data in the user message. That also keeps the stable part identical across calls for caching.
- Is prompt engineering still needed with smarter models?
- Yes, but it is less about tricks and more about clear specifications: the task, the context, the rules and the format. Smarter models follow clear instructions better, not unclear ones.