# 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#