output_schema to provide structural constraints. Applications must still validate responses and handle empty output, invalid formats, and unmet business rules
Define a schema and create an agent
Complete installation and model configuration and select a model that supports structured output. This example usesLiteral to constrain categories and priorities; listing values in a field description alone does not enforce them
ticket.py
Parse the response
Runpython ticket.py. A successful result resembles this JSON; wording and classification can vary:
Runner.run returns text, not a Ticket instance. Ticket.model_validate_json(raw) parses JSON and validates fields. The example handles validation failures, not model request exceptions. Production applications should distinguish request failures from invalid results and also check business rules, such as whether a ticket contains enough information
Use native Ark structured output
Both the model and endpoint must support the Ark Responses API and JSON Schema. Replace theagent definition above with:
json_schema format with strict: true. Accepted schemas and supported constraints depend on the model and service. This does not guarantee successful requests or factually correct business data
Responses caching has compatibility restrictions with structured output. VeADK removes conflicting cache settings from relevant requests. Setting enable_responses_cache=False makes this choice explicit. See Responses API for other settings
Tool and runtime limitations
- Use the default
adkruntime; configuringoutput_schemawithcodexorpiagentfails - Google ADK 2.2 supports
output_schemaalongside tools, applying structure to the final response; verify tool and transfer compatibility with your model, API, and ADK version - To separate tool work from extraction, complete retrieval or tool tasks first, then use a dedicated structured-output agent to produce the final record