Commit 2bcc87c
committed
feat: add structured outputs support with Pydantic integration
Add support for Anthropic's structured outputs beta feature using the
anthropic-beta: structured-outputs-2025-11-13 header. Enables type-safe
JSON responses through Pydantic models or raw JSON schemas.
Features:
- Pydantic v1/v2 automatic detection and schema conversion
- Per-query output_format parameter for flexibility
- Deep copy schema validation to prevent mutations
- Comprehensive examples demonstrating advanced Pydantic features
- Full test coverage (34 new tests, 151 total passing)
Implementation:
- Added schema_utils.py for Pydantic → JSON schema conversion
- Modified query() and ClaudeSDKClient.query() to accept output_format
- Created examples/structured_outputs.py with 4 production scenarios
- Updated README.md with usage examples and documentation
Note: Actual functionality blocked pending CLI support for --json-schema
flag (see anthropics/claude-code#9058). Infrastructure complete and ready.1 parent ff425b2 commit 2bcc87c
File tree
10 files changed
+1563
-1
lines changed- examples
- src/claude_agent_sdk
- _internal
- transport
- tests
10 files changed
+1563
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
79 | 131 | | |
80 | 132 | | |
81 | 133 | | |
| |||
271 | 323 | | |
272 | 324 | | |
273 | 325 | | |
| 326 | + | |
| 327 | + | |
274 | 328 | | |
275 | 329 | | |
276 | 330 | | |
| |||
0 commit comments