One of AI21 Maestro’s core capabilities is providing validated output, which addresses a critical problem that even advanced language models can struggle with - consistently following complex instructions that include multiple constraints.AI21 Maestro ensures your language model’s outputs meet your specific requirements. Instead of relying on prompts to work reliably on their own, it uses computational resources to validate and refine outputs until they satisfy your constraints.AI21 Maestro’s Validated Output addresses this by:
Validating outputs against your explicit requirements
Automatically fixes outputs that don’t meet the requirements
Provides a report on requirement fulfillment with detailed scores
Requirements: Explicit constraints you define for your outputs (e.g., format, tone, content rules).
Budget: Controls computational effort and trade-offs—higher budgets use more resources (increasing cost and latency) to achieve better adherence to requirements (high/medium/low).
Requirements Report: Provides detailed scoring and feedback on how well each requirement was met.
Model Agnostic: Maestro works with both AI21’s first-party models and popular third-party models (e.g., GPT-4, Claude, Gemini)—choose the model that best fits your needs.
import osfrom ai21 import AI21Clientclient = AI21Client(api_key=os.getenv("AI21_API_KEY"))# create_and_poll() returns after the processing ended or the default timeout is passedrun = client.beta.maestro.runs.create_and_poll( input="Write a Python function to calculate fibonacci numbers", requirements=[ { "name": "function_length", "description": "The function should be no more than 10 lines long" }, { "name": "include_docstring", "description": "Include a Google-style docstring explaining the function" } ], budget="low", include=["requirements_result"])# Result is available immediately when this returnsprint(f"Result: {run.result}")print(f"Requirements Score: {run.requirements_result.score}")
Understanding Asynchronous ExecutionMaestro runs execute asynchronously in the backend. The create() method returns immediately with a run ID, while processing happens in the background:
Explore the API Reference for full parameter details.
If you have any technical questions about Maestro, feel free to reach out to our support team via email or click the chat icon in the lower right corner.