What are constrained outputs

Constrained outputs involve instructing the LLM to generate responses that adhere to specific limitations or formats. This could mean setting a word limit, specifying a response type (like “yes” or “no”), or requiring the output to match a particular pattern or structure.

How to implement constrained outputs

  1. Set clear instructions: Be explicit about the constraints you want the model to follow.
  2. Specify the format: Define the exact format or pattern you expect.
  3. Limit the length: Set boundaries on the response length, such as word or character counts.
  4. Use controlled vocabularies: Restrict the model to use only certain words or phrases.
  5. Provide templates: Offer a template that the model should fill in.

Example

Why use constrained outputs

  • Increase precision: Helps the model provide exactly what you need without unnecessary information.
  • Enhance consistency: Ensures uniformity across multiple outputs, which is crucial for tasks like data entry or form filling.
  • Simplify parsing: Makes it easier to programmatically process the responses.
  • Reduce errors: Minimizes the chance of irrelevant or incorrect information creeping into the output.