Prompt Engineering, Parameters and Self-Critique
30-second answer
Tune generation in two places. Prompts set role, rules, format and examples, and a few-shot example often fixes format faster than more rules. Parameters shape the sampling: a low temperature gives steady, factual wording, a high one gives variety, and max output tokens caps length, so a reply cut off with an incomplete status needs a higher cap. A self-critique loop drafts, checks against a checklist and revises once. Reasoning models use reasoning effort instead of temperature.
Simulate it » No Azure account neededExam objective: 2.3.1 Tune generation behavior, such as prompt engineering and adjusting model parameters. 2.3.2 Implement model reflection, chain-of-thought evaluations and self-critique loops. (Skills measured as of April 16, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Start with clear <strong>instructions</strong>: who the model is, the audience, the rules and the length.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Start with clear instructions: who the model is, the audience, the rules and the length.
- For facts and extraction use a low temperature. Raise it for brainstorming. Max output tokens limits the reply, and too low a value cuts it off.
- One worked example often fixes format and tone faster than more rules.
- Compare outputs side by side, then lock in the winner with an evaluation. A reasoning model such as o4-mini ignores temperature and uses reasoning effort instead.
🧪 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
Tune prompts and parameters
Instructions shape tone and rules, a few-shot example shows the format, temperature and top_p change how adventurous the wording is, and max output tokens caps length. A self-critique loop drafts, checks against a checklist and revises once.
🤔 What happens if…
Read this tour as text
- Deploy a model, call the deployment. A deployment is a named copy of a model with a version, a deployment type and capacity. Your app calls the deployment name, never the model name. Pick a large model for hard work and a small language model for cheap, fast, simple work.
- RAG: retrieve first, then answer. Retrieval-augmented generation searches your own content (Azure AI Search, hybrid keyword plus vector), puts the best chunks in the prompt and asks the model to answer from them with citations. Without retrieval the model guesses.
- A multistep flow with checks. A workflow breaks one big request into steps you control: classify, extract to a JSON schema, call a tool, draft, then verify. Retries, fallbacks and a final check live in code, so one bad step can’t slip through unseen.
- Evaluate before you ship. Evaluators score each answer on a test set: groundedness (is it supported by the context?), relevance, coherence and safety checks. A fabrication shows up as a low groundedness score on one row, so you fix it before users see it.
- SDK, project endpoint and connections. The Foundry SDK (
azure-ai-projects) opens one door: AIProjectClient with the project endpoint and DefaultAzureCredential. From it your app gets an OpenAI-compatible client, deployments and connections (Azure AI Search, Application Insights) with no secrets in code. - Design the agent: role, goal, tool schema. An agent is a model plus instructions (role and goal), tools and a conversation (thread). A strict function schema names each parameter and marks the required ones, so the model asks the user instead of inventing a value.
- Retrieval, function calling and memory. One agent can use file search for documents, a function for live data and memory for what it learned about a user. The model asks to call a function; your code runs it and returns the result. Memory survives into a new conversation.
- Multi-agent orchestration. Several specialist agents can share a job. Sequential passes work down a line, concurrent fans out and merges, handoff moves control to the right specialist, group chat lets agents take turns in one shared conversation and Magentic lets a manager agent plan and delegate. Microsoft Agent Framework builds all five.
- Autonomy with approvals. Reads are safe, writes are not. A tool marked approval required pauses the run until a person decides. A hard limit in code blocks what no one should approve, whatever the model says.
- Monitor and debug agent runs. Agent evaluators read the whole run: intent resolution, tool call accuracy and task adherence. Error analysis groups the failing rows, such as a made-up tool argument, and points to the fix.
- Tune prompts and parameters. Instructions shape tone and rules, a few-shot example shows the format, temperature and top_p change how adventurous the wording is, and max output tokens caps length. A self-critique loop drafts, checks against a checklist and revises once.
- Trace every call and count tokens. OpenTelemetry spans record each agent run, model call and tool call, with tokens and latency, and Application Insights stores them. Tracing is opt-in, and recording message content is for development only because it captures prompts and answers.
- Route requests to the right model. A hybrid design puts rules first for answers code can decide, a small model for easy language work and a large or reasoning model only when needed. A model router can pick for you. Fewer big-model calls means a lower bill and faster replies.
Contoso's product descriptions come out different every time. Change temperature, add an example, cap the length too low, and try a self-critique pass to see what each one does.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
Product descriptions are wildly different each time, and some stop mid-sentence.
😊 THE SOLUTION
Tighten the instructions, add an example and set sensible parameters.
- Too creative or too flat✓ Temperature or top P
- Cut-off replies✓ Raise max output tokens and check the status
- Wrong facts in the draft✓ A self-critique pass with a checklist
Start with a question
Why do two cooks make different dishes from the same recipe?
One recipe says “season to taste”. One cook adds a pinch, another adds a fistful. One follows the recipe card exactly, another improvises. If you want the same dish every time, you write clearer steps, show a photo of the finished plate and tell them how much to use.
A model is the cook. Instructions are the recipe. A worked example is the photo. Temperature is how much the cook improvises. Max output tokens is the size of the plate.
Explain it like I’m 10
The technical explanation
1. Prompt: say it clearly
A good instruction names the role, the audience, the rules, the format and the length.
You are Contoso's product copywriter. Write a product description for an Indian online shop.
Use plain English, mention the warranty, and stay under 60 words.
Example
Input: steel water bottle
Output: Keeps chai hot for 12 hours. Leak-proof lid, 1-year warranty.
Put separate parts in clear sections, give the answer format, and add one or two examples when the format matters. That’s few-shot prompting.
2. Parameters: shape the sampling
| Setting | Effect | Use |
|---|---|---|
| Temperature | Low is steady, high is varied | 0 to 0.3 for facts and extraction, higher for ideas |
| Top P | Limits to the most likely words | Change it or temperature, not both |
| Max output tokens | Caps reply length | Too low cuts the answer. Check the status |
r = openai.responses.create(model="support-chat", instructions=instructions, input=product,
temperature=0.2, top_p=1, max_output_tokens=300)
print(r.output_text, r.status, r.incomplete_details) # status "incomplete" means a cap was hit
Reasoning models such as o4-mini don’t take temperature. You steer them with reasoning effort (low, medium or high), and a higher effort costs more tokens and time.
3. Reflection and self-critique
Let the model check its work. Draft, then critique against a checklist, then revise once:
draft = openai.responses.create(model=m, instructions=instructions, input=product).output_text
critique = openai.responses.create(model=m, input=f"Check this against the rules and list problems: {draft}").output_text
final = openai.responses.create(model=m, input=f"Rewrite fixing: {critique}\n{draft}").output_text
Keep the checklist short and the loop to one or two rounds. It costs extra calls, so measure whether it raises evaluation scores. For reasoning, a chain-of-thought style prompt (“work through the steps, then answer”) can help standard models on multistep problems. Reasoning models think by themselves, so you don’t need to ask. You can evaluate the reasoning by scoring intermediate steps against a rubric, or by comparing several attempts and keeping the consistent answer.
Architect level Change one thing at a time
If you change the prompt, the temperature and the model together, you won’t know which helped. Change one setting, run your evaluation set, and keep the change only if scores improve. Prompts are code: store them in Git, version them, and compare versions on the same data.
Real-world business scenario
Fabrikam Appliances (fictional)
- The problem
- Product descriptions changed tone every time, some got the warranty wrong, and a few stopped mid-sentence.
- What they used
- Instructions with role, audience, a 60-word limit and one worked example, temperature 0.2, max output tokens 300 with a check of the response status, and a self-critique pass against a three-line checklist.
- Why that choice
- The example fixed the format, the low temperature steadied the wording, the higher cap stopped cut-offs, and the critique caught the wrong warranty.
- The result
- Descriptions came out consistent, and the evaluation score for rule-following rose by a clear margin.
When to use it and when not to
✓ Use it when…
- Output format, tone or length is inconsistent.
- You need steadier answers for facts or extraction.
- A draft benefits from a check against rules before it is used.
✕ Think twice when…
- Using the prompt to enforce exact business rules. Use code.
- Raising temperature for factual answers.
- Endless critique loops that cost more than they help.
↔ Alternatives to consider
- RAG when the problem is missing knowledge, not wording.
- Structured outputs when code must parse the reply.
- Fine-tuning only when prompts can't hold a style at high volume.
Test yourself with exercises
5 original practice questions in the AI-103 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 does temperature do?
Model answer
It controls how adventurous the wording is. Near 0 the model picks the most likely words and the answer is steady. Higher, the answers vary more, which is nice for ideas and risky for facts.
Intermediate A reply stops mid-sentence. What do you check?
Model answer
The response status. If it says incomplete because of max output tokens, the cap was too low. I raise it, or I ask for a shorter answer in the instructions.
Experienced developer How do you design a self-critique loop?
Model answer
I draft with the normal prompt, then ask the model to check the draft against a short checklist and list problems, then revise once with those problems. I limit it to one or two rounds, and I evaluate whether it really improves the score, because it costs extra calls.
Scenario Product descriptions vary wildly and sometimes get the warranty wrong. What do you change?
Model answer
I lower the temperature, add a worked example in the instructions that shows the format and the warranty line, state the length, and add a verification step that compares the warranty with the product data.
Quick revision
Key points
- Instructions set role, audience, rules and length.
- A few-shot example fixes format and tone quickly.
- Low temperature for facts; higher for ideas.
- Incomplete status points to the output token cap.
- Reasoning models take reasoning effort, not temperature.
Important terminology
- Temperature
- A sampling setting. Lower values give steadier wording, higher values give more varied wording.
- Top P
- A sampling setting that limits choices to the most likely words. Change it or temperature, not both.
- Max output tokens
- A cap on how many tokens the model may generate. Too low cuts the reply short.
- Few-shot prompting
- Putting one or more worked examples in the prompt so the model copies the format and tone.
- Self-critique
- A loop where the model checks its own draft against criteria and revises it.
- Reasoning effort
- A setting on reasoning models that controls how much the model thinks before answering.
Common mistakes
- Changing temperature and top_p together.
- Setting max output tokens so low that replies are cut.
- Running endless self-critique loops.
Exam tips
- "Consistent, factual output" = low temperature.
- "Reply cut off, status incomplete" = raise max output tokens.
- "Reasoning model rejects temperature" = use reasoning effort.
Five quick revision questions
-
1.What does a low temperature give?Show
Steady, repeatable wording.
-
2.What fixes a cut-off reply?Show
A higher max output tokens value.
-
3.What does a few-shot example do?Show
It shows the format and tone.
-
4.What is a self-critique loop?Show
Draft, check against criteria, revise.
-
5.What replaces temperature on reasoning models?Show
Reasoning effort.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Tracing, Token Analytics and Latency
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.