This guide focuses specifically on the Validated Output, providing practical examples that range from basic usage to advanced scenarios.
Understanding the Problem
Traditional LLM interactions often look like this:Python
- LLMs often fail to consistently meet all the individual requirements outlined in the promp
- There is no visibility into which requirements were not met
- Requires manual trial and error to achieve the desired output
How AI21 Maestro Works
Maestro’s instruction following enhancer uses a Generate → Validate → Fix cycle:- Generate: Creates initial response following your requirements
- Validate: Evaluates and scores each requirement (0.0 to 1.0)
- Fix: Refines output for requirements that scored < 1.0
- Repeat: Continues until all requirements are met or budget is exhausted
text
Using the API
The Input parameter You can pass a string to Maestro as an input and it will be treated as a user message.Python
Python
System Prompt
Thesystem_prompt defines the agent’s identity, operating principles, and boundaries before it processes any input.It guides how Maestro interprets inputs, chooses tools, and reasons throughout the run. Use it to:
- Define the agent’s role and identity
Example: “You are a cautious financial journalist. Verify all data before reporting” - Provide context or environment
Example: Today’s date is November 10, 2025. User location: New York. - Define behavioral rules
Example: “Always verify numbers from reliable sources before reporting. If data is unclear, ask a clarifying question.”
Working with Requirements
Writing Effective Requirements
Good Requirements:Python
Python
Requirement Categories
Format Requirements:Python
Python
Python
Python
Requirements Report
Enable detailed reporting by including requirements_result:Python
Python
- 2 out of 3 requirements were perfectly met
- The rating requirement needs refinement
- You might need a higher budget or clearer requirement
Budget Control and Performance
Use thebudget parameter to control how much computational effort AI21 Maestro applies when executing your task. Higher budgets improve reasoning reliability but increase latency and cost.
The snippet below shows how to set different budget levels in your Maestro run. Replace
task and requirements with your own input values and make sure the client is initialized with your API key as shown in the Quickstar.Python
Using Third-Party Models
You can run Maestro tasks with both AI21 and third-party models.Use the
models parameter to specify which model to run your task with.If no model is specified, Maestro will automatically select a suitable model based on the task requirements.
Python
Setting the Response Language
You can control the output language of Maestro’s response using theresponse_language parameter. For example, to receive the result in Spanish: