Skip to main content
Structured output asks an agent to return predefined fields for extraction, classification, and downstream processing. Pass a Pydantic model class to 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 uses Literal to constrain categories and priorities; listing values in a field description alone does not enforce them
ticket.py

Parse the response

Run python 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 the agent definition above with:
VeADK converts the schema to the Responses API 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 adk runtime; configuring output_schema with codex or piagent fails
  • Google ADK 2.2 supports output_schema alongside 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
Last modified on September 19, 2026