Writing System and User Prompts
30-second answer
A system prompt (system message) sets the model's role, rules, tone and output format for the whole conversation, while a user prompt is the actual question or task. Good prompts give clear instructions, say what format to return, show few-shot examples, supply grounding data inside delimiters and ask for step-by-step work on hard problems. You then test and iterate, and add a safety system message that tells the model what it must refuse.
Simulate it » No Azure account neededExam objective: 2.1.1 Create effective system and user prompts for generative AI models. (Skills measured as of April 15, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
With a vague system message, the assistant happily answers anything, even off-topic questions.
👆 Click the glowing item in the portal to continue
Read the steps as text
- With a vague system message, the assistant happily answers anything, even off-topic questions.
- Give it a role, a scope, a tone, a length and what to do when unsure.
- Add examples (few-shot) to show the exact output format you want.
- Ground the model: paste trusted facts between clear delimiters and tell it to answer only from them.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
Test in the playground
The chat playground lets you try a deployment with no code. The system message sets the rules, the user message asks the question, and parameters such as temperature tune the answer.
🤔 What happens if…
Read this tour as text
- Resource and project. A Foundry resource is the Azure resource that holds your models, tools, security and billing. Inside it, a project is the workspace where a team builds one app: its deployments, agents, files and evaluations.
- The model catalog. The model catalog lists thousands of models: OpenAI GPT models, Microsoft Phi, Meta Llama, Mistral, DeepSeek and more. Each has a model card, benchmarks and the deployment types it supports.
- Deploy a model. Before an app can call a model you deploy it and give the deployment a name. Global Standard (pay per token, the default), Data Zone (keeps processing in the US or EU), Provisioned (reserved throughput) and Batch (cheaper, within 24 hours) trade price, speed and data location.
- Test in the playground. The chat playground lets you try a deployment with no code. The system message sets the rules, the user message asks the question, and parameters such as temperature tune the answer.
- Call it from your app. Your Python app uses the Foundry SDK (
azure-ai-projects): connect to the project endpoint with Microsoft Entra ID, get an OpenAI-compatible client and call the deployment by its name. - An agent: model + instructions + tools. An agent is a model with instructions and tools that can decide what to do next. Foundry Agent Service keeps the conversation and runs the tools for you.
- Tools in action. Ask "What is our refund limit, and what is 15% of ₹4,200?" The agent uses file search for the policy and the code interpreter for the maths, then answers in one reply. That loop of plan, act and observe is what makes it agentic.
- Guardrails and monitoring. Every request passes guardrails (content filters) on the way in and out. Tracing and evaluations show what the agent did, how long it took and whether answers are grounded and safe.
Same model, different instructions, very different answers. Keep an assistant on topic, ground it in your own facts and teach it a format by example.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
Your assistant rambles, goes off-topic and invents policies.
😊 THE SOLUTION
A clear system message with scope, format, examples and facts.
- Off-topic answers✓ Set the scope
- Wrong format✓ Show an example
- Invented facts✓ Ground with context
Start with a question
Why does the same AI give a great answer to one person and a useless one to another?
Two people ask a model about trains. One types “trains?”. The other types “I’m travelling from Bengaluru to Mysuru on Saturday morning with a toddler. List three train options in a table with departure time and duration.”
The second person gets a far better answer, and it’s not luck. They told the model who they are, what they want and how to lay it out. That’s prompt engineering, and in an app you do most of it once, in the system prompt, so every user gets the good version.
Explain it like I’m 10
Visual: prompts in motion
One support bot, one question, and the same model getting better with each change to the prompt.
Read the video script
- A prompt is a list of messagesWhen your app calls a model, it doesn't send one line. It sends a list of messages, and each one has a role.
- The system message sets the rulesThe system message is written by you, the developer. It sets the persona, the scope, the tone and the format.
- The user asksThe user message is what the person typed for this turn.
- Without facts, it guessesWithout the facts, the model fills the gap with something that sounds right. Sixty days is made up.
- Ground it in your dataSo ground it. Paste the real policy between tags, and tell the model to answer only from that text. Now the answer is right.
- Show examples for a fixed formatNeed a fixed format your code can read? Show two or three examples. That is called few-shot prompting, and it beats a paragraph of rules.
- Off-topic? Decline safelyLast, add a safety system message that says what to refuse. It works alongside Foundry's guardrails, not instead of them.
The technical explanation
Every chat request to a model is a list of messages, each with a role:
| Role | Who writes it | What goes in it |
|---|---|---|
system | You, the developer | Persona, scope, rules, tone, output format, safety rules |
user | The person using your app | The question or task for this turn |
assistant | The model | Its earlier replies, sent back so it remembers the conversation |
Techniques that make prompts work
- Be clear and specific. Say the task, the audience and the length. “Summarise this for a busy store manager in two sentences” beats “summarise this”.
- Give it a role. “You’re a customer support agent for Contoso Electronics” sets vocabulary and tone.
- Ask for a format. A table, a numbered list, or JSON with named keys your code can read.
- Show examples (few-shot). Two or three input and output pairs teach a pattern faster than a paragraph of rules. With no examples it’s zero-shot.
- Ground it. Paste the facts the answer must come from, and say “If the answer isn’t in the text, say you don’t know.”
- Use delimiters. Wrap pasted content in
""",###or tags like<policy>…</policy>so the model can tell instructions from data. - Ask for steps on hard problems. “Work through it step by step, then give the final answer” helps with maths and logic.
- Iterate. Test in the playground, look at bad answers, change one thing, test again.
Here’s a system message that uses most of them:
You are a support assistant for Contoso Electronics.
Answer only questions about Contoso products, using the policy text between <policy> tags.
If the answer is not in the policy, say "I'm not sure, please contact support."
Reply in at most 3 sentences, in plain English.
Never give medical, legal or financial advice. Politely decline off-topic requests.
<policy>
Returns are accepted within 30 days with a receipt. Laptops carry a 1-year warranty.
</policy>
The last two lines of rules are a small safety system message. Microsoft recommends adding one to every app: it sets what the model should refuse and how. It works alongside Foundry’s guardrails (content filters and Prompt Shields), not instead of them.
Architect level Prompting reasoning models and agents
Reasoning models (such as the o-series and GPT-5 reasoning modes) already think step by step, so “think step by step” adds little. Give them a clear goal and constraints instead, and use the reasoning effort setting. For agents, the system prompt is called instructions and also tells the agent when to use each tool. Keep instructions short and testable; long, contradictory instructions are a common reason agents misbehave.
Real-world business scenario
Contoso Air (fictional)
- The problem
- The airline's chatbot answered baggage questions from general internet knowledge, gave other airlines' rules and wrote long paragraphs on phones.
- What they used
- A new system message with a role, a three-sentence limit, the airline's baggage policy as grounding data inside tags, two few-shot examples and a refusal rule for off-topic questions.
- Why that choice
- Grounding stops the model inventing rules, few-shot examples fix the format, and the safety lines keep it on topic.
- The result
- Answers now quote the airline's own allowance, fit on one phone screen and decline unrelated requests politely.
When to use it and when not to
✓ Use it when…
- Always. Every generative AI app needs a clear system prompt.
- Few-shot examples when the output must follow an exact pattern.
- Grounding when answers must match your own documents or policies.
✕ Think twice when…
- Pasting a whole manual into every prompt. Use retrieval or an agent with file search so only the relevant parts are sent.
- Relying on the prompt alone for safety. Keep guardrails turned on.
↔ Alternatives to consider
- Retrieval-augmented generation (RAG) to add grounding data automatically.
- Fine-tuning when the same style or task is needed at scale and prompting can't get it right.
Test yourself with exercises
5 original practice questions in the AI-901 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner What's the difference between a system prompt and a user prompt?
Model answer
The system prompt is the standing instruction from the developer, like "You're a polite travel assistant for Contoso Air, answer in under 80 words". The user prompt is what the customer types, like "Can I carry a power bank?". The system prompt shapes every answer; the user prompt changes each turn.
Interviewer follows up
Can a user override the system prompt?
You
They can try, for example with "ignore your instructions". A clear system message helps, but I'd also turn on Prompt Shields in Foundry's guardrails to catch jailbreak attempts.
Intermediate When would you use few-shot examples?
Model answer
When the format or style matters and instructions alone don't get it right. If I need every product description as exactly three bullet points, showing two examples gets more consistent output than describing the format in words.
Experienced developer How do you reduce hallucinations through prompting?
Model answer
I ground the model. I put the relevant facts in the prompt inside clear delimiters and tell it to answer only from that content and say "I don't know" otherwise. For bigger knowledge bases I'd use retrieval so the right passages are added automatically. Then I test with questions the data can't answer and check it refuses.
Scenario A bank's chatbot keeps giving long, chatty answers and sometimes talks about cricket. How would you fix it with prompts?
Model answer
In the system message I'd set the role and scope ("You answer questions about Contoso Bank savings accounts only"), a length and format rule ("Reply in at most three sentences"), and a refusal rule for anything off-topic. Then I'd test off-topic questions in the playground and tighten the wording until it declines politely.
Quick revision
Key points
- The system prompt sets role, rules, tone and format; the user prompt asks the question.
- Be specific about the task, audience, length and output format (for example JSON or a table).
- Few-shot examples show the model the exact pattern you want.
- Grounding data in delimiters keeps answers tied to your facts.
- Iterate in the playground and add a safety system message for refusals.
Important terminology
- System prompt
- The instruction, usually hidden from end users, that sets the model's role, rules, tone and format for every turn.
- User prompt
- The message from the user that asks the question or describes the task.
- Few-shot prompting
- Including a few example inputs and ideal outputs in the prompt so the model copies the pattern.
- Zero-shot prompting
- Asking the model to do a task with instructions only and no examples.
- Grounding data
- Facts you paste into the prompt (or retrieve automatically) so the model answers from your content instead of memory.
- Delimiter
- Markers such as triple quotes,
- Safety system message
- Lines in the system prompt that set safety rules, such as refusing harmful requests and staying on topic.
Common mistakes
- Putting the rules in the user message and expecting them to hold for the whole chat. Standing rules go in the system prompt.
- Thinking a system message alone stops every jailbreak. Use guardrails such as Prompt Shields as well.
Exam tips
- "Set the assistant's persona and rules for every turn" = system prompt.
- "Include sample inputs and outputs" = few-shot.
- "Answer only from the supplied policy text" = grounding.
Five quick revision questions
-
1.Where do you set the assistant's tone and rules?Show
In the system prompt.
-
2.What's few-shot prompting?Show
Giving a few example inputs and outputs in the prompt.
-
3.Why use delimiters?Show
To separate instructions from the content the model should process.
-
4.How does grounding help?Show
It makes the model answer from facts you provide, which reduces made-up answers.
-
5.What does a safety system message do?Show
It tells the model what to refuse and how to stay on topic and safe.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Deploy a Model and Chat in the Foundry Portal
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.