# Practical ways to use the Claude Agent SDK
๐ฆ Get typed JSON output from agents and bind it directly to your UI components.
Structured Output uses `output_format` to receive agent results as typed data conforming to a JSON schema, validated with Zod or Pydantic.
๐ Title: Getting Structured Output from Agents
๐ URL:
๐งฉ Overview
Specify a JSON schema in `output_format` and the agent returns structured JSON instead of free text. Type-safe validation is available via Zod (TypeScript) / Pydantic (Python).
๐ How to use it
Set `output_format={"type": "json_schema", "schema": your_schema}` in your options. Generate schemas with Pydantic's `.model_json_schema()` or Zod's `z.toJSONSchema()`. Results appear in `ResultMessage.structured_output`.
๐ Practical usage
- In a recipe app, get web search results as `{name, prep_time_minutes, ingredients[], steps[]}` and bind directly to UI components.
- Build a TODO extraction agent that runs Grep + Bash(git blame) autonomously and returns `{todos[{text, file, line, author?, date?}], total_count}`.
- Receive feature implementation plans as `{summary, steps[{description, complexity}], risks[]}` for automatic project management tool integration.
๐ก Use cases
๐จ Direct data binding to UI components
๐ Structured analysis report generation
๐ง Automatic data ingestion into project management tools
โ ๏ธ Watch out
Structured output is incompatible with streaming. JSON results only appear in the final `ResultMessage.structured_output`. Handle `error_max_structured_output_retries` by retrying with simpler prompts or falling back to unstructured output.
#
ClaudeAgentSDK# #
AI#