> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Why Structured Outputs Matter and How ADK Handles Them

> Explains why structured outputs are important and how ADK uses agent schemas and tool-level structured results for reliable help desk ticketing workflows.

Most large language models (LLMs) produce free-form text by default. While natural for conversation, unstructured responses are brittle when you need machine-readable results. Common problems include:

* Difficulty reliably extracting structured fields (IDs, statuses, severities).
* Inconsistent severity labels (low/medium/high) across responses.
* Unpredictable formats that break downstream integrations (databases, APIs, analytics).

These are exactly the issues we face in our help desk ticketing workflow: model replies are stochastic and freeform, so we can’t dependably populate ticket fields.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5avJoheCFB2a-Y-C/images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/free-text-vs-structured-use-cases.jpg?fit=max&auto=format&n=5avJoheCFB2a-Y-C&q=85&s=bea1c3dbc48d7fdd1c942b8183dcc27e" alt="A presentation slide titled &#x22;Free-Text vs Structured Output&#x22; showing three numbered panels. Each panel lists a use case where free-text is weak: extracting tickets from text, standardizing severity levels, and producing API-ready structured fields." width="1920" height="1080" data-path="images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/free-text-vs-structured-use-cases.jpg" />
</Frame>

ADK provides two primary ways to get structured outputs instead of raw text:

1. Agent-level schemas (input and output models).
2. Tool-level structured results (tools that return typed objects).

This guide compares both approaches and shows why we’ll use tool-level structured outputs for our help desk assistant.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5avJoheCFB2a-Y-C/images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/adk-structured-output-options.jpg?fit=max&auto=format&n=5avJoheCFB2a-Y-C&q=85&s=c33512f422c1536d98ccb61409138e3d" alt="A dark-themed slide titled &#x22;ADK's Structured Output Options&#x22; showing two circular icons and labels: &#x22;Agent-Level Schemas&#x22; (database icon) with the caption &#x22;Facilitate structured agent interactions,&#x22; and &#x22;Tool-Level Structured Results&#x22; (toolbox icon) with the caption &#x22;Ensure organized and interpretable output.&#x22;" width="1920" height="1080" data-path="images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/adk-structured-output-options.jpg" />
</Frame>

|                      Approach | Best for                                                                  | Key tradeoffs                                                            |
| ----------------------------: | ------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
|           Agent-level schemas | Single-step, deterministic lookups or function-like agents                | Strongly typed outputs but limited tool use and orchestration            |
| Tool-level structured results | Multi-step workflows that call tools, use RAG, or integrate with services | Flexible orchestration; requires each tool to guarantee its return shape |

## Agent-level schemas (typed agents)

Agent-level schemas let you give an ADK agent explicit input and output models (for example, Pydantic classes). This makes the agent behave like a typed function: it accepts structured inputs and is guided to return a fixed JSON shape.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5avJoheCFB2a-Y-C/images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/agent-structured-outputs-pydantic-schemas.jpg?fit=max&auto=format&n=5avJoheCFB2a-Y-C&q=85&s=35217efee2930c80d6ce9daeba72399e" alt="A presentation slide titled &#x22;Agent-Level Structured Outputs&#x22; showing two colorful cards labeled &#x22;input_schema&#x22; (teal) and &#x22;output_schema&#x22; (orange), which describe Pydantic models for what an agent expects and should return." width="1920" height="1080" data-path="images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/agent-structured-outputs-pydantic-schemas.jpg" />
</Frame>

Example — an agent that returns the capital of a country. We define a small Pydantic model for the output and pass it as the agent's `output_schema`. ADK steers the model to emit JSON matching that schema so the system reliably receives a `capital` field instead of a paragraph.

```python theme={null}
from pydantic import BaseModel, Field
from google.adk.agents import Agent

class CapitalOutput(BaseModel):
    capital: str = Field(description="The capital of the country.")

capital_agent = Agent(
    name="capital_agent",
    model="gemini-2.5-flash",
    instruction="Return the capital of the requested country.",
    output_schema=CapitalOutput,
)
```

There is an important limitation: agent-level output schemas are intended for single-step, reply-style agents. Agents constrained by an output schema often cannot:

* invoke tools,
* perform retrieval-augmented generation (RAG),
* or hand off to other agents.

That makes agent-level schemas great for pure lookups or deterministic functions, but unsuitable for workflows needing tool calls or orchestration.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5avJoheCFB2a-Y-C/images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/important-caveat-only-reply-no-tools.jpg?fit=max&auto=format&n=5avJoheCFB2a-Y-C&q=85&s=31b8e338ca4c8719bed427a7c18038b3" alt="A slide titled &#x22;Important Caveat&#x22; showing a two-column table with a green check for &#x22;Only reply&#x22; and a red X listing &#x22;No functional tools, No RAG, No agent transfer.&#x22; A footer notes this is fine for pure-function agents but not suitable for a tool-driven helpdesk." width="1920" height="1080" data-path="images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/important-caveat-only-reply-no-tools.jpg" />
</Frame>

<Callout icon="lightbulb" color="#1CB2FE">
  Agent-level output schemas are excellent when your agent should behave like a deterministic function and return a fixed schema. If your workflow requires calling tools or RAG, prefer structured tool outputs instead.
</Callout>

## Tool-level structured outputs (recommended for help desk)

The second approach is to make each tool return a strictly structured object (dict or Pydantic model). ADK can generate schemas from type hints and docstrings so the LLM sees tools as reliable, JSON-shaped building blocks. This is the pattern we’ll use for ticket creation.

Benefits:

* Tools guarantee the return shape (e.g., ticket fields), making downstream integration deterministic.
* Agents remain free to orchestrate multiple tools, call external services, and perform RAG.
* Easier to log, persist, and analyze outputs because the shape is standardized.

For a help desk, the create\_ticket tool should return a ticket object with fields like `ticket_id`, `summary`, `severity`, `service`, `user_email`, and `status`. Once that contract is enforced, other systems (databases, dashboards, external platforms) can consume tickets without extra parsing.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5avJoheCFB2a-Y-C/images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/ticket-object-structure-fields.jpg?fit=max&auto=format&n=5avJoheCFB2a-Y-C&q=85&s=e9f254154b4b6347bb1098497d96c66d" alt="A slide titled &#x22;Ticket Object Structure&#x22; showing fields for a create_ticket tool, with labeled boxes for ticket_id, summary, severity, service, user_email, and status." width="1920" height="1080" data-path="images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/ticket-object-structure-fields.jpg" />
</Frame>

Because the ticket is a well-defined object, integration is straightforward: log it, write it to the DB, push it to an external helpdesk, or feed it to analytics and dashboards.

We want a smart IT help desk assistant that:

* decides whether a ticket is needed,
* calls the `create_ticket` tool when appropriate,
* receives a structured ticket object back, and
* responds to the user with a clear confirmation such as: "I've created ticket IT-1234 with severity high for the VPN outage."

That structured ticket is the bridge between conversation and operations.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5avJoheCFB2a-Y-C/images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/why-this-matters-helpdesk-assistant-workflow.jpg?fit=max&auto=format&n=5avJoheCFB2a-Y-C&q=85&s=77c3d29787a7797d80f42e2c5c4f09ef" alt="A presentation slide titled &#x22;Why This Matters&#x22; that outlines a four-step helpdesk assistant + tickets workflow: Decide, Call Tool, Get Structure, Respond. Each step is shown as a colored stacked block with a brief action description (e.g., call create_ticket and tell the user &#x22;I've created ticket IT-1234...&#x22;)." width="1920" height="1080" data-path="images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/why-this-matters-helpdesk-assistant-workflow.jpg" />
</Frame>

## Implementation plan — concrete next steps

To move from concept to working ADK code, we’ll:

* define the ticket Pydantic schema,
* implement the `create_ticket` function tool that returns a typed ticket object,
* register and wire that tool into the help desk agent flow so the agent can open tickets when needed,
* log and persist tickets (DB / external API / analytics).

This refactor makes our assistant both intelligent and reliably integrated.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5avJoheCFB2a-Y-C/images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/next-steps-refactor-create-ticket-helpdesk.jpg?fit=max&auto=format&n=5avJoheCFB2a-Y-C&q=85&s=90e7d83ef9936283bc35d098774721df" alt="A presentation slide titled &#x22;Next Steps&#x22; showing four numbered items: refactor the project, define a ticket schema, implement a create_ticket function tool, and wire it into the helpdesk flow. The design uses teal circular number icons and thin horizontal lines on a dark background." width="1920" height="1080" data-path="images/Google-ADK/Deploying-and-Operating-ADK-Agents/Why-Structured-Outputs-Matter-and-How-ADK-Handles-Them/next-steps-refactor-create-ticket-helpdesk.jpg" />
</Frame>

## References and further reading

* [Large language model — Wikipedia](https://en.wikipedia.org/wiki/Large_language_model)
* [Pydantic documentation](https://docs.pydantic.dev/latest/)
* [Retrieval-augmented generation (RAG) — Wikipedia](https://en.wikipedia.org/wiki/Retrieval-augmented_generation)
* [Kubernetes Documentation (for related orchestration patterns)](https://kubernetes.io/docs/)

<Callout icon="warning" color="#FF6B6B">
  When you choose agent-level schemas, remember you trade off orchestration and tool calls. For help desk workflows that must interact with services or perform multi-step logic, use tool-level structured outputs.
</Callout>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/google-adk/module/672589ad-758d-4e70-8408-bd4bd4409388/lesson/fed1683d-d6f3-43d9-bb54-237ecbc8a9c3" />
</CardGroup>
