---
title: "Get structured output from agents Code Agent SDK"
source: https://docs.autohand.ai/agent-sdk/io/structured-output
---

# Get structured output from agents

Extract structured data from agent responses using JSON schemas and type definitions. Get JSON, typed objects, or specific formats from your agents instead of free-form text.

Agents can return structured data instead of free-form text. This is useful for integrating with APIs, databases, or other systems that require specific data formats.

## JSON Output

Request JSON output from agents by specifying the desired format in your instructions or using schema validation.

## Schema Validation

Define JSON schemas to validate that agent output matches your expected structure.

## Best Practices

-   **Be explicit in instructions:** Tell the agent exactly what fields you need and their formats
-   **Use validation:** Always validate the output against a schema before using it
-   **Handle errors gracefully:** If the agent returns invalid JSON, ask it to retry
-   **Provide examples:** Include example JSON in your instructions for better results

## Use Cases

-   **API Integration:** Extract data to send to external APIs
-   **Database Operations:** Generate SQL queries or database records
-   **Configuration Files:** Generate YAML, TOML, or JSON config files
-   **Test Data:** Generate structured test data for testing
-   **Report Generation:** Create structured reports from unstructured data