Back to catalog / Agent output
Get a JSON Schema-shaped agent result
Set output_format and read structured data from the terminal ResultMessage.structured_output.
Goal
Have the agent return structured output the application can validate.
Steps
- Set ClaudeAgentOptions.output_format to
{"type":"json_schema","schema":{...}}with required fields and types. [types] - Run the task and wait for terminal ResultMessage; do not treat concatenated streaming text as a structured object. [types]
- Read
ResultMessage.structured_output, then validate business rules, unknown-field handling, and missing values. [types]
How to verify
Test valid and invalid examples, checking field types and that semantically invalid or incomplete results are rejected.
Troubleshooting
If structured_output is absent, check CLI support for this schema mode and that a terminal ResultMessage arrived; do not blindly parse natural language as fallback.
Permissions
Prerequisites
- Python 3.10+, claude-agent-sdk, and authenticated Claude Code CLI support for structured output.
Permissions
- Write structured results only to approved application storage; never use untrusted fields for commands or account actions.
Limitations
JSON Schema constrains structure, not semantic correctness; application validation and unknown-value rejection remain necessary.
Pinned upstream source
- Repository
- anthropics/claude-agent-sdk-python
- File path
- src/claude_agent_sdk/types.py
- Pinned commit
b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: MIT
Main topic
Take a coding Agent change from context to verification