Commit 3cbd61a
authored
add anthropic json schema support (#339)
* feat: add Anthropic json_schema support via output_config.format
Add native structured output support for the Anthropic provider by
mapping the common response_format: :json_schema to Anthropic's
output_config.format API.
Changes:
- transforms.rb: add normalize_response_format to convert json_schema
response_format to { format: { type: "json_schema", schema: ... } }
for output_config. json_object and text remain unhandled (nil) to
preserve existing behavior.
- transforms.rb: call normalize_response_format in normalize_params,
deleting response_format and setting output_config when applicable.
- request.rb: read response_format without deleting so @response_format
is preserved for json_object emulation; normalize_params handles
deletion and conversion.
Design decisions:
- JSON Schema Hashes are passed through as-is; not converted to
Anthropic::BaseModel.
- name and strict from the common format are not forwarded;
Anthropic's output_config.format does not use them.
- Beta header is not required for output_config (stable API).
* test: enable Anthropic json_schema integration tests
Activate previously commented-out json_schema tests now that the
Anthropic provider supports output_config.format.
Changes:
- Update REQUEST_JSON_SCHEMA to include output_config.format.schema
as the expected serialized request shape.
- Enable test_request_builder for response_json_schema_inline,
response_json_schema_implicit, response_json_schema_named, and
response_json_schema_implicit_bare, verifying all four input forms
produce the same output_config payload.
- Enable live VCR test asserting response.format.type == "json_schema"
and response.message.parsed_json[:colors] is an Array.
- Add VCR cassettes for the four json_schema variants and update
text cassettes to reflect current request format.
* docs: update Anthropic provider docs for json_schema support
Document Anthropic's native json_schema structured output support.
Changes:
- structured_output.md: update provider support table, marking
Anthropic json_schema as supported (🟩) with a note about
output_config.format on supported Claude models.
- anthropic.md: add JSON Schema Support section with usage example,
serialized request format, and notes on name/strict not forwarded
and model availability.
- anthropic.md: update Response Format parameter reference to include
JSON Schema Support link.
- anthropic.md: update Limitations section to reflect that Anthropic
now natively supports json_schema via output_config.format.1 parent b569eb5 commit 3cbd61a
9 files changed
Lines changed: 287 additions & 20 deletions
File tree
- docs
- actions
- providers
- lib/active_agent/providers/anthropic
- test
- fixtures/vcr_cassettes/integration/anthropic/common_format/response_format_test
- integration/anthropic/common_format
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
128 | 181 | | |
129 | 182 | | |
130 | 183 | | |
| |||
155 | 208 | | |
156 | 209 | | |
157 | 210 | | |
158 | | - | |
| 211 | + | |
159 | 212 | | |
160 | 213 | | |
161 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| |||
159 | 165 | | |
160 | 166 | | |
161 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
162 | 214 | | |
163 | 215 | | |
164 | 216 | | |
| |||
Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
77 | 93 | | |
78 | 94 | | |
79 | 95 | | |
| |||
141 | 157 | | |
142 | 158 | | |
143 | 159 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
148 | 164 | | |
149 | 165 | | |
150 | 166 | | |
| |||
175 | 191 | | |
176 | 192 | | |
177 | 193 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
182 | 198 | | |
183 | | - | |
184 | | - | |
| 199 | + | |
| 200 | + | |
185 | 201 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
191 | 207 | | |
192 | 208 | | |
193 | 209 | | |
| |||
0 commit comments