-
Notifications
You must be signed in to change notification settings - Fork 533
feat: add structured output support #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add structured output support to Python SDK, matching TypeScript implementation.
API:
```python
from claude_agent_sdk import query, ClaudeAgentOptions
schema = {
"type": "object",
"properties": {"count": {"type": "number"}},
"required": ["count"]
}
async for msg in query(
prompt="Count files in src/",
options=ClaudeAgentOptions(
output_format={"type": "json_schema", "schema": schema}
)
):
if hasattr(msg, 'structured_output'):
print(msg.structured_output)
```
See: https://docs.claude.com/en/docs/agent-sdk/structured-outputs
cd2e29a to
073d95e
Compare
073d95e to
ba5eb1f
Compare
ashwin-ant
approved these changes
Nov 18, 2025
Collaborator
|
@zhammer yes, this works in the Agent SDK without any configuration on your part. |
|
@ashwin-ant great, just confirmed on our end. i was just a bit confused by the discrepancy with docs. thank you |
Collaborator
|
For the agent sdk there are specific docs on structured output here: https://platform.claude.com/docs/en/agent-sdk/structured-outputs |
|
Can you use the structured output with ClaudeSDKClient or it's only for query() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add structured output support to Python SDK.
Usage
Documentation
https://docs.claude.com/en/docs/agent-sdk/structured-outputs
Tests
tests/test_integration.py::TestIntegration::test_structured_outpute2e-tests/test_structured_output.py(4 tests)