Roles, Context & System Prompts
"Act as an experienced HR manager" is one of the most popular prompt openings. Giving the model a role can help, but it is only a small part of the story. What really changes the answer is context: the facts, the situation and the purpose behind your request. And when you build an app, a third tool appears: the system prompt, which sets rules for the whole conversation.
In this lesson you will learn how to use roles sensibly, how to supply context well, and how system prompts and saved instructions work in apps and APIs.
Roles: a shortcut to tone and focus
A role tells the model which kind of expert to sound like and what to pay attention to:
You are a patient maths teacher for Class 8 students in a Hindi-medium school.
Explain why we flip the second fraction when dividing fractions.
Use one everyday example with rotis or rupees, and short sentences.The role here does useful work: it sets the level (Class 8), the style (patient, simple) and the audience's background (Hindi-medium, so avoid heavy English terms). Roles help most when they bring a point of view: "Review this as a strict examiner" finds different problems than "review this as a friendly classmate".
But a role does not give the model new knowledge. "You are a senior tax lawyer" will make the answer sound expert, not make it correct. For legal, medical, tax and financial questions, the role is never a substitute for checking with a qualified person and official sources.
Context: the biggest lever you have
The model knows a great deal about the world in general, but nothing about your situation unless you tell it. Useful context includes:
- Facts: dates, names, numbers, the policy text, the error message.
- Situation: what happened so far, what has already been tried.
- Purpose: what the result is for and what success looks like.
- Examples of your style: a previous email you liked, your company's tone.
When you paste longer material, wrap each piece in clearly named tags. Tags are not special commands; they are labels that keep the pieces apart and let you refer to them in your instructions. A small Python helper makes this tidy:
def wrap(name, text):
return f"<{name}>\n{text.strip()}\n</{name}>"
policy = """Refunds are allowed within 7 days of purchase with the bill.
Sale items can be exchanged but not refunded."""
complaint = """I bought a kurta on sale 3 days ago and it is too small.
I want my ₹899 back. - Ananya, Kochi"""
prompt = "\n\n".join([
"You are a polite customer support agent for a clothing store.",
wrap("policy", policy),
wrap("customer_message", complaint),
"Reply to the customer in under 80 words. Follow the policy exactly, "
"and offer the option the policy allows.",
])
print(prompt)You are a polite customer support agent for a clothing store. <policy> Refunds are allowed within 7 days of purchase with the bill. Sale items can be exchanged but not refunded. </policy> <customer_message> I bought a kurta on sale 3 days ago and it is too small. I want my ₹899 back. - Ananya, Kochi </customer_message> Reply to the customer in under 80 words. Follow the policy exactly, and offer the option the policy allows.
Without the policy, the model would guess, and might promise a refund the shop does not give. With it, the correct answer (an exchange, not a refund) is right there in the context.
System prompts
When you chat in an app, there are actually two kinds of instructions:
- The system prompt (also called system instructions or developer instructions) is written by whoever built the app. It sets standing rules: the role, the tone, what to refuse, what format to use. You usually cannot see it.
- The user messages are what you type.
Developers write the system prompt in code. With the Claude API in Python, it is the system argument; other providers use a similar field (OpenAI calls it instructions, Gemini calls it system_instruction). This sketch shows the shape; you will run real calls in Using AI APIs from Python:
import anthropic
client = anthropic.Anthropic() # reads the ANTHROPIC_API_KEY environment variable
response = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=500,
system=(
"You are the help desk assistant for Green Valley School, Jaipur. "
"Answer only questions about admissions, fees and timings. "
"If you do not know, tell the parent to call the school office."
),
messages=[{"role": "user", "content": "When do admissions for Class 1 open?"}],
)
for block in response.content:
if block.type == "text":
print(block.text)A good system prompt is like a job description: who the assistant is, who it serves, what it may and may not do, and what to do when it is unsure.
Saved instructions in chat apps
You do not need code to get the benefit of a system prompt. Most assistants let you save standing instructions that apply to every chat or to a group of chats: custom instructions and custom GPTs in ChatGPT, Projects in Claude, Gems in Gemini, and agents in Microsoft Copilot. Typical things to save:
- who you are ("I am a B.Com student in Lucknow", "I write reports for a logistics company");
- your preferences ("British spelling, short paragraphs, no jargon");
- recurring context (a style guide, product details, a glossary).
Common mistakes
- Relying on a grand role and no facts. "You are a world-class marketer" with no product details still gives generic copy.
- Contradicting yourself. A role of "strict examiner" plus "be very encouraging" confuses the model. Decide what you want.
- Forgetting saved instructions. If every answer suddenly comes in bullet points, check your custom instructions.
- Trusting role-based expertise. A model playing a doctor is still not a doctor.
Key points
- A role sets tone, level and point of view, but it does not add knowledge or accuracy.
- Context (facts, situation, purpose, examples) is the most powerful part of a prompt.
- Wrap pasted material in named tags so the model can tell instructions from data.
- System prompts set standing rules for an app; users usually cannot see them.
- Chat apps offer saved instructions, projects and custom assistants that work like system prompts.
Exercise
Write a function support_prompt(policy, message, max_words) that builds a prompt like the one in this lesson, with the role line, the two tagged sections and the closing instruction using max_words. Use it for a bookshop in Jaipur whose policy says "Books can be returned within 10 days if unmarked. Exam guides cannot be returned." and a message from Rohan who wants to return an exam guide bought yesterday.
Show solution
def wrap(name, text):
return f"<{name}>\n{text.strip()}\n</{name}>"
def support_prompt(policy, message, max_words):
return "\n\n".join([
"You are a polite customer support agent for a bookshop in Jaipur.",
wrap("policy", policy),
wrap("customer_message", message),
f"Reply to the customer in under {max_words} words. "
"Follow the policy exactly, and offer any option the policy allows.",
])
policy = ("Books can be returned within 10 days if unmarked. "
"Exam guides cannot be returned.")
message = "I bought an SSC exam guide yesterday but I don't need it now. Can I return it? - Rohan"
print(support_prompt(policy, message, 60))You are a polite customer support agent for a bookshop in Jaipur. <policy> Books can be returned within 10 days if unmarked. Exam guides cannot be returned. </policy> <customer_message> I bought an SSC exam guide yesterday but I don't need it now. Can I return it? - Rohan </customer_message> Reply to the customer in under 60 words. Follow the policy exactly, and offer any option the policy allows.
The policy in the prompt tells the model that exam guides cannot be returned, so a correct reply politely says no instead of inventing a refund.
Quick Quiz
1. What does giving the model a role mainly change?
A role shapes style and focus, but it does not add knowledge or guarantee accuracy.
2. A support bot keeps promising refunds that the shop does not offer. What is the best fix?
The model needs the real policy as context; otherwise it guesses.
3. Who usually writes the system prompt of an app?
The system prompt is set by the app's builder and applies to the whole conversation.
4. Why wrap pasted documents in tags like <policy>?
Tags are labels that organise the prompt; they are not special commands.
Learn Generative AI with a mentor
Free lessons get you started. Our AI Training & Workshops training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
