Prompts and a chat client

Message roles, prompting techniques that actually move the needle, and the shape of a lightweight Foundry chat client.

  • Gen AI apps & agents
  • 20 minutes
  • High priority

After this lesson you can

  • Put the right content in system, user and assistant messages
  • Choose between zero-shot, few-shot and chain-of-thought prompting
  • Describe what a Foundry chat client needs and how it authenticates

Three message roles

RoleWho writes itWhat goes in it
systemThe developerPersona, scope, rules, tone, output format, what to do when unsure. Newer APIs also accept a developer role, and the Responses API takes the same content as instructions.
userThe end userThe current question or instruction
assistantThe modelPrevious replies, replayed to give the model conversation history
Try itChange the system message and see how the same question gets answered differently.
system

(none)

user

My order #4471 has not arrived. What do I do?

assistant

I'm sorry to hear that! Order delays can happen for lots of reasons - carrier backlogs, weather, an address issue, or the parcel being held at a depot. Have you checked your tracking link? Usually the carrier updates it within 24 hours. If it has been more than a week, most retailers will let you open a claim, and some will send a replacement while the investigation runs. You may also want to check with neighbours…

Rambling, no format, no boundaries, and it invents policy the company may not have.

Check your understanding

Gen AI apps & agents

What belongs in the system message rather than the user message?

Prompting techniques

TechniqueWhat it isUse it when
Zero-shotState the task, give no examplesThe task is common and the format is obvious
Few-shotInclude several input → output examplesYou need an exact output format or labelling scheme
Chain-of-thoughtAsk the model to reason step by stepMulti-step reasoning or logic problems

Know this: None of these change the model

All three are inference-time techniques that cost prompt tokens and require no training. Fine-tuning is the one that changes weights. A question offering "fine-tune the model" as a fix for a formatting or tone problem is usually the wrong answer - try the system prompt first.

Check your understanding

Gen AI apps & agents

A prompt includes three worked examples of input and the desired labelled output before the real input. What is this technique called?

Check your understanding

Gen AI apps & agents

Which prompting technique most improves a model's performance on a multi-step arithmetic or logic problem?

What makes a system prompt good

  1. Role and scope - who the assistant is, and explicitly what it will not discuss.
  2. Output format - state it, and show an example of it.
  3. Failure behaviour - "if the answer is not in the provided context, say you do not know". This single line prevents a great deal of hallucination in grounded apps.
  4. Tone - one concrete sentence beats three adjectives.
A system prompt with all four elements
You are a support assistant for Contoso Cloud.
Answer only from the context provided in the conversation.
If the answer is not in the context, say: "I don't have that information."
Never discuss competitors or pricing.
Reply in at most three sentences, plain language, no marketing tone.

Check your understanding

Gen AI apps & agents

A support assistant sometimes answers questions about competitors and occasionally replies in a chatty tone that does not match the brand.

What is the most appropriate first fix?

Check your understanding

Gen AI apps & agents Hard

Which two practices make a system prompt more effective? (Choose two.)

Choose 2. Each correct answer is part of the solution. Each correct selection is worth one point.

Choose 2, then check.

A lightweight chat client

You will not be asked to write this from scratch, but you should recognise the shape and know what each piece is for.

What every Foundry chat client does

  1. Get a credential

    Microsoft Entra ID (keyless) is the recommendation - DefaultAzureCredential for development, a specific credential such as a managed identity in production. Keys work too, but never put them in source code.

  2. Point at the project endpoint

    Typically https://<your-resource>.services.ai.azure.com/api/projects/<project-name>, read from an environment variable such as PROJECT_ENDPOINT.

  3. Build the messages

    A system message with your standing instructions, then the user message, plus any prior assistant messages for history.

  4. Call the model by deployment name

    Pass the deployment name you chose in the portal - or, with instant access, the model name - plus any parameters that model supports.

  5. Read the reply

    Take the generated content out of the response and show it to the user.

The current shape - project endpoint, Entra credential, deployment name, Responses API
import os
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential

# pip install "azure-ai-projects>=2.3.0" azure-identity
project = AIProjectClient(
    endpoint=os.environ["PROJECT_ENDPOINT"],
    credential=DefaultAzureCredential(),
)

openai = project.get_openai_client()

response = openai.responses.create(
    model=os.environ["MODEL_DEPLOYMENT_NAME"],
    instructions="You are a concise IT support assistant.",
    input="What is an AI agent?",
)

print(response.output_text)

You will also meet the older Chat Completions shape - client.chat.completions.create(messages=[...]), reading response.choices[0].message.content. It still works and the message roles are identical; Microsoft recommends the Responses API for new apps because it carries the newest features.

Changed: If your notes use a connection string

Older samples authenticate with AIProjectClient.from_connection_string(...), or use version 1.x of azure-ai-projects. Current samples use version 2.x with a project endpoint and a Microsoft Entra credential. Recognise both, prefer the current one.

Check your understanding

Gen AI apps & agents

Which two values does a lightweight Foundry chat client typically need in order to call a deployed model?

Check your understanding

Gen AI apps & agents

Which authentication approach does Microsoft recommend for a Foundry client application?