AI Foundry Structured Output
Understand prompt-guided output in the classic Foundry adapter and use Azure OpenAI for native structured output.
The classic adapter requests JSON through prompt instructions and parses the response locally. Both agents below use that same path: strict_output=True does not enable provider-enforced JSON Schema on the normal Agent(output_schema=...) path.
Passing a Pydantic class directly to the model's response_format uses a separate tuple-construction branch that can fail before the SDK sends a request. The two Agent declarations below do not take that branch.
This source uses Agno's classic AzureAIFoundry adapter and the azure-ai-inference package, which Microsoft retired on August 26, 2026. Existing endpoint availability is separate from SDK retirement. For a new integration, use the current Foundry API setup with a compatible deployment. The classic setup below applies only to an existing compatible endpoint unless a current adaptation is explicitly provided.
"""
Azure Structured Output
=======================
Cookbook example for `azure/ai_foundry/structured_output.py`.
"""
from typing import List
from agno.agent import Agent, RunOutput # noqa
from agno.models.azure import AzureAIFoundry
from pydantic import BaseModel, Field
from rich.pretty import pprint # noqa
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
class MovieScript(BaseModel):
setting: str = Field(
..., description="Provide a nice setting for a blockbuster movie."
)
ending: str = Field(
...,
description="Ending of the movie. If not available, provide a happy ending.",
)
genre: str = Field(
...,
description="Genre of the movie. If not available, select action, thriller or romantic comedy.",
)
name: str = Field(..., description="Give a name to this movie")
characters: List[str] = Field(..., description="Name of characters for this movie.")
storyline: str = Field(
..., description="3 sentence storyline for the movie. Make it exciting!"
)
# Agent that uses structured outputs with strict_output=True (default)
structured_output_agent = Agent(
model=AzureAIFoundry(id="gpt-5.6-luna"),
description="You write movie scripts.",
output_schema=MovieScript,
)
# Agent with strict_output=False (guided mode)
# strict_output=False: Attempts to follow the schema as a guide but may occasionally deviate
guided_output_agent = Agent(
model=AzureAIFoundry(id="gpt-5.6-luna", strict_output=False),
description="You write movie scripts.",
output_schema=MovieScript,
)
# Get the response in a variable
# structured_output_response: RunOutput = structured_output_agent.run("New York")
# pprint(structured_output_response.content)
structured_output_agent.print_response("New York")
guided_output_agent.print_response("New York")
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passoutput_schema describes the expected type. If parsing or validation fails, result.content can remain a string. Before accessing schema fields in a run result, use isinstance(result.content, YourSchema), replacing YourSchema with the class you passed as output_schema.
Current Alternative
Use Azure OpenAI Structured Output for a supported Pydantic output-schema example.
Full source: cookbook/90_models/azure/ai_foundry/structured_output.py