Microsoft Certified: Azure AI Engineer AssociateImplement generative AI solutionsHard

A software company is integrating Azure OpenAI Service into its code generation platform. They need to ensure that the generated code adheres to strict internal style guides and includes specific boilerplate comments. What is the most effective prompt engineering strategy to consistently enforce these coding standards?

  1. AProviding a single example of the desired code format (one-shot prompting).
  2. BIncluding the entire style guide as part of the system message.
  3. CUsing a very low temperature value to reduce creativity.
  4. DStructuring the prompt with clear instructions and a few examples demonstrating the style guide compliance.
Show answer & explanation

Correct answer: D. Structuring the prompt with clear instructions and a few examples demonstrating the style guide compliance.

Combining clear instructions with a few examples (few-shot prompting) is highly effective for enforcing specific formatting, style guides, and boilerplate. The instructions define the rules, and the examples demonstrate their application, reinforcing the desired behavior more reliably than instructions alone or a single example.

Why the other options are wrong

  • A. One-shot prompting might not be sufficient for complex style guides; the model may not generalize perfectly from a single example.
  • B. Including an entire style guide can make the prompt excessively long, consume too many tokens, and dilute the model's focus, leading to less consistent application.
  • C. A low temperature reduces creativity but doesn't guarantee adherence to specific structural or stylistic rules without explicit guidance on those rules.

Instruction-Few-Shot Prompting for Style

A prompt engineering technique that combines explicit instructions with a few illustrative examples to guide an LLM to produce outputs that conform to specific formatting, style, or content requirements.

  • Instructions define the rules, examples show application.
  • Highly effective for complex or nuanced output constraints.
  • Balances direct guidance with practical demonstrations.

Memory trick: Instructions and 'Few-Shot' examples are like a 'Recipe with Pictures' for AI style.

More Implement generative AI solutions questions