Agent Wealth HubFree public resources
中文 EN العربية

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

  1. Set ClaudeAgentOptions.output_format to {"type":"json_schema","schema":{...}} with required fields and types. [types]
  2. Run the task and wait for terminal ResultMessage; do not treat concatenated streaming text as a structured object. [types]
  3. 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

Permissions

Limitations

JSON Schema constrains structure, not semantic correctness; application validation and unknown-value rejection remain necessary.

Pinned upstream source

https://github.com/anthropics/claude-agent-sdk-python/blob/b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c/src/claude_agent_sdk/types.py

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

Related resources