Courseiva

System Messages for Guiding Code Output in Azure OpenAI

A developer uses the Azure OpenAI API to generate code. They want to ensure that the generated code is in Python. Which parameter should they set?

⚠ Common exam trap

Microsoft often tests the distinction between parameters that control output randomness (temperature, top_p) and those that control output structure or behavior (system message), leading candidates to mistakenly choose temperature or top_p for language specification.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

system message

The system message is used to set the behavior and context of the AI model, including specifying the desired output format or language. By setting the system message to 'You are a helpful assistant that always writes code in Python', the developer can instruct the model to generate Python code consistently. This parameter is part of the chat completions API and directly influences the model's persona and constraints.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    temperature

    Why it's wrong here

    temperature adjusts sampling randomness, controlling creativity versus determinism, not the programming language produced. It is tempting because low values yield consistent output, but language selection comes from the prompt or system message; temperature cannot force Python over another language.

  • ✗

    top_p

    Why it's wrong here

    top_p controls nucleus sampling, restricting token selection to a cumulative probability mass, which shapes randomness rather than language. It is tempting for tuning output diversity, but specifying Python requires a system message or prompt instruction, since top_p cannot enforce a programming language.

  • ✓

    system message

    Why this is correct

    The system message sets the model's behavioural context before any user turn, so instructing it there to respond only in Python reliably constrains the generated code's language. A user message or temperature setting cannot enforce this persistent constraint.

  • ✗

    max_tokens

    Why it's wrong here

    max_tokens caps the response length, truncating output once that budget is reached. It is tempting for controlling cost or verbosity, but it cannot dictate which language the model writes in; a system message or prompt must specify Python.

About these practice questions

This AI-102 question is part of Courseiva's 761-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

2 more ways this is tested on AI-102

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. You are using Azure OpenAI Service to generate code snippets for a development team. You notice that the generated code sometimes contains security vulnerabilities. You need to minimize the risk of generating insecure code while maintaining productivity. What should you do?

medium
  • ✓ A.Use system messages to instruct the model to prioritize security
  • B.Fine-tune the model on a dataset of secure code
  • C.Set the temperature parameter to 0
  • D.Disable content filtering to allow more flexibility

Why A: System messages in Azure OpenAI Service allow you to set the context and behavior of the model, including instructing it to prioritize security when generating code. This approach directly influences the model's output without requiring retraining or sacrificing flexibility, making it the most effective way to reduce security vulnerabilities while maintaining productivity.

Variation 2. You are a generative AI engineer at a financial services company. The company uses Azure OpenAI Service to generate investment summaries. You have deployed a GPT-4 model with a content filter set to 'Low' for hate speech. The model frequently generates summaries that include biased language against certain demographics. You need to reduce biased outputs while maintaining the ability to generate detailed financial analysis. You cannot afford to retrain the model. You have the following options: A) Change the content filter severity to 'High' for all categories, B) Add a system message instructing the model to avoid bias and provide examples of unbiased summaries in the prompt, C) Use the Azure AI Language service to detect bias in the output and regenerate if bias is found, D) Deploy a different model like GPT-3.5 which has less bias. Which course of action should you take?

hard
  • A.Use the Azure AI Language service to detect bias in the output and regenerate if bias is found.
  • ✓ B.Add a system message instructing the model to avoid bias and provide examples of unbiased summaries in the prompt.
  • C.Change the content filter severity to 'High' for all categories.
  • D.Deploy a different model like GPT-3.5 which has less bias.

Why B: Adding a system message that explicitly instructs the model to avoid bias and providing few-shot examples of unbiased summaries is the most direct and cost-effective way to steer the model's behavior without retraining. This approach leverages prompt engineering to influence the model's output distribution while preserving the ability to generate detailed financial analysis.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This AI-102 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AI-102 exam.