Lesson 1 of 4 Optimizing and Operationalizing Generative AI

Tuning Prompts and Generation Parameters

This lesson explains prompt engineering techniques and the main generation parameters, the fastest ways to change model behaviour, and the point at which fine-tuning becomes worth considering.

Learning outcomes

After completing this lesson, you will be able to:

  • Apply prompt engineering techniques such as delimiters and few-shot examples.
  • Tune generation parameters such as temperature and maximum output tokens.
  • Decide when supervised fine-tuning or DPO is worth the effort.

Prompt engineering techniques

A prompt is the complete input sent to a model: the instructions (the system prompt), any supplied content such as retrieved passages or a document, and the user's message. Prompt engineering is the practice of designing that input so that the model produces the required output reliably. Small changes in wording, structure or examples can change the output considerably, and reliable prompts share the following techniques.

Clear instructions state the task, the audience and the constraints, so the model does not have to guess what is wanted.

Delimiters, such as XML-style tags, separate instructions from supplied content. This also helps the model treat content as data rather than as instructions.

Few-shot examples show the expected mapping from input to output for formats or judgements that are hard to describe in words.

Output specifications or schemas define the structure of the response, such as named fields or a fixed list of labels.

Decomposition asks the model to work through a problem in steps rather than answering at once.

Uncertainty handling tells the model what to do when information is missing, such as answering "Unknown" instead of guessing.

The order of the prompt also matters: stable content goes first and variable content last, which also allows prompt caching.

Applying the techniques to one task shows how they work together. A weak prompt for summarizing customer complaints might say only "Summarize this complaint." A stronger version states the audience and purpose ("for a quality manager deciding whether to open an investigation"), places the complaint between <complaint> tags so that any instructions inside it are treated as text, defines the output as three labelled fields (product, problem, severity from 1 to 3), gives two short examples showing how severity is judged, and says what to do when the product cannot be identified ("use Unknown; do not guess"). Each addition removes a source of variation: the reader, the boundary between instruction and data, the format, the judgement and the edge case.

Prompt changes are tested like code changes. A small edit that fixes one example can break others, so each version is run against the evaluation dataset before it replaces the previous one, and prompts are stored in source control with the agent or application they belong to.

Match the pairs

Prompt techniques

Exam skills 2.3.1

Match each prompt technique with what it achieves.

Log in to try this activity Interactive activities are free with an account.

Generation parameters

A model generates text one token at a time. At each step it assigns a probability to every possible next token, and a sampling procedure picks one. Generation parameters control that procedure and the overall length of the output, so they change how predictable and how long a response is without changing the prompt.

Temperature reshapes the probabilities: at 0 the model almost always picks the most likely token, which gives focused, repeatable output suited to extraction, classification and grounded answers; higher values flatten the distribution and produce more varied, creative text. top_p achieves a similar effect differently, by restricting the choice to the smallest set of tokens whose probabilities add up to p. Because both control randomness, changing both at once makes the effect hard to reason about, so one is adjusted and the other left at its default.

max_output_tokens caps the length of the response. It protects cost and latency, and a realistic value also helps rate limits, because quota accounting includes the maximum requested output. A response that reaches the cap is cut off and reported as incomplete. For reasoning models, reasoning effort takes the place of temperature: lower effort answers faster and more cheaply, higher effort spends more reasoning tokens on hard problems. The following table summarizes the parameters most often tuned in AI-103 scenarios.

ParameterEffectGuidance
temperatureRandomness of token selection (0 to 2)0 to 0.3 for extraction and factual answers; higher for creative text
top_pNucleus sampling: limits choices to a probability massAdjust temperature or top_p, not both
max_output_tokensUpper bound on output lengthSet to a realistic maximum; truncated output reports an incomplete status
reasoning effortDepth of internal reasoning for reasoning modelsLower for speed and cost; higher for hard problems
seedMore repeatable sampling where supportedUseful for testing; not a guarantee
Stop sequences, frequency and presence penaltiesEnd output early; reduce repetitionChat Completions; check model support

Reasoning models do not support temperature or top_p; requests that set them fail or ignore them, so tuning those models uses reasoning effort, instructions and output limits.

For a reasoning model, the Foundry playground shows only the parameters the model accepts. The following screenshot shows the parameters of a gpt-5.4-mini deployment: a maximum number of completion tokens and a reasoning effort from none to xhigh, with no temperature setting.

Playground parameters with Max Completion Tokens and Reasoning Effort options xhigh, high, medium, low and none
Higher reasoning effort improves multistep answers at the cost of latency and tokens.
Scenario questions

Tune generation

Exam skills 2.3.1

Practise choosing generation parameters.

Log in to try this activity Interactive activities are free with an account.

When to fine-tune

Prompting changes what a model is told; fine-tuning changes the model itself. It continues training an existing model on the organization's own examples, producing a customized model that behaves in the required way without long instructions. Three methods differ in the kind of example they learn from.

Supervised fine-tuning uses pairs of inputs and ideal outputs, and teaches the model to produce outputs like the examples.

Direct preference optimization (DPO) uses pairs of preferred and rejected outputs for the same input, and teaches the model which of two acceptable answers is better.

Reinforcement fine-tuning is used for reasoning models. Instead of fixed answers, it uses graders that score the model's outputs, and the model learns to produce outputs that score well.

Fine-tuning suits a consistent format, tone or domain style that prompting cannot achieve reliably, or a smaller model that must match a larger one on a narrow task. It does not suit knowledge that changes, which belongs in retrieval. Fine-tuned models are evaluated on a held-out set before deployment.

Worked example

Tuning a classifier

A ticket classifier sometimes returns labels that are not in the list and gives different labels to the same ticket on different runs.

Set temperature to 0, supply the label set as an enum in a structured output schema, and add a few examples of difficult tickets. If accuracy is still too low after evaluation, consider fine-tuning a small model on labelled tickets. Raising temperature or switching to a larger model without a schema would not prevent invalid labels.

Check yourself

Should fine-tuning be used to give a model new knowledge?

Show answer

No. Fine-tuning suits a consistent style or format. Knowledge that changes is better supplied through grounding and retrieval.

Exam Tips

Remember for the exam

  • Low temperature plus a schema for consistent structured output.
  • Adjust temperature or top_p, not both; reasoning models use reasoning effort instead.
  • Fine-tune for consistent style or format, not for changing knowledge.