Microsoft Certified: Azure AI Engineer AssociateImplement generative AI solutionsHard
A team is developing an Azure OpenAI Service application for generating legal summaries. They need to categorize each summary based on the legal topics discussed (e.g., 'Contract Law', 'Intellectual Property', 'Litigation'). To ensure consistent and accurate categorization, the model should only output categories from a predefined list. Which prompt engineering technique is best suited to enforce this constraint?
- AUsing a 'stop' sequence that includes all valid category names.
- BInstructing the model to select categories exclusively from a provided list within the prompt.
- CSetting the 'temperature' to a high value to encourage diverse categorization.
- DProviding a few-shot example that includes an invalid category name.
Show answer & explanationAnswer & explanation
Correct answer: B. Instructing the model to select categories exclusively from a provided list within the prompt.
Instructing the model to select categories exclusively from a predefined list within the prompt (often combined with few-shot examples if the format is complex) is the most direct and effective way to enforce strict adherence to a specific set of allowed outputs for categorization.
Why the other options are wrong
- A. A 'stop' sequence would end generation when a category is encountered, not enforce that the chosen category comes from a predefined list or that only one category is chosen.
- C. High temperature would increase randomness and make the model more likely to invent categories outside the list.
- D. Providing an invalid example is counterproductive; it might confuse the model or teach it to generate invalid categories.
Constrained Output Prompting
A prompt engineering technique that explicitly limits the model's output to a predefined set of choices, format, or structure.
- Crucial for categorization, structured data extraction, and function calling.
- Often involves listing valid options or defining a strict schema.
- Reduces hallucinations and ensures parseable, predictable output.
Memory trick: Instruct with List, Lock the Output: Give clear 'instructions with a list' to 'lock' the output.