Prompt Engineering
Use constrained outputs
Set clear boundaries and rules for the model’s responses to improve accuracy, consistency, and utility
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
- Set clear instructions: Be explicit about the constraints you want the model to follow.
- Specify the format: Define the exact format or pattern you expect.
- Limit the length: Set boundaries on the response length, such as word or character counts.
- Use controlled vocabularies: Restrict the model to use only certain words or phrases.
- 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.
Was this page helpful?