Microsoft Certified: Azure AI Engineer AssociateImplement generative AI solutionsHard

A development team is building an Azure OpenAI Service application that generates legal summaries. These summaries must adhere to a very specific, predefined structure, including sections like 'Case Name', 'Facts', 'Ruling', and 'Reasoning', each with its own heading and content. The team needs to ensure the LLM consistently produces output in this exact format. Which prompt engineering technique is most effective for achieving this strict structural adherence?

  1. AIncreasing the `temperature` parameter to encourage structured creativity.
  2. BUsing a system message to instruct the model on the desired output format.
  3. CProviding a single example of a well-formed summary (one-shot prompting).
  4. DEmploying constrained output prompting with JSON schema or regular expressions.
Show answer & explanation

Correct answer: D. Employing constrained output prompting with JSON schema or regular expressions.

Constrained output prompting, especially with JSON schema or regular expressions, allows developers to enforce a very strict and specific format for the LLM's output. This is ideal for scenarios like legal summaries where adherence to a predefined structure is critical and variations are unacceptable.

Why the other options are wrong

  • A. Increasing temperature would make the output more varied and less structured, which is the opposite of the requirement.
  • B. A system message helps, but it's less robust than explicit constraints for ensuring exact structural adherence.
  • C. One-shot prompting provides an example but doesn't guarantee strict adherence to the structure every time.

Constrained Output Prompting

A prompt engineering technique that guides or forces an LLM to generate output in a specific, predefined format, often using formal specifications like JSON schema or regular expressions.

  • Ensures strict adherence to desired output structure.
  • Useful for structured data extraction, API calls, or specific document formats.
  • Reduces the need for post-processing the LLM's output.

Memory trick: To build a perfect structure, constrain the output with a schema.

More Implement generative AI solutions questions