add anthropic json schema support#339
Merged
TonsOfFun merged 3 commits intoJun 25, 2026
Merged
Conversation
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).
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.
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.
TonsOfFun
approved these changes
Jun 25, 2026
TonsOfFun
left a comment
Contributor
There was a problem hiding this comment.
I'm going to merge this as the only failure is from a deprecation on rails main that is now resolved on activeagent main
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
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.
Summary
Adds native JSON Schema structured output support for the Anthropic provider by mapping the common
response_format: :json_schemaAPI to Anthropic's
output_config.formatAPI. This allows agents using Anthropic to get schema-validated JSON responses using the same interface as OpenAI — no provider-specific code required.The implementation adds
normalize_response_formatinTransforms, which converts the common format to Anthropic's native structure.json_objectemulation (prompt prefill) is unchanged.How it works
normalize_response_formattranslates the commonresponse_formathash into Anthropic'soutput_config.formatstructure.nameandstrictfrom the common format are intentionally dropped — Anthropic's API does not use them. JSON Schema Hashes are passed through as-is and are not converted toAnthropic::BaseModel. No beta header is required;output_configis part of the stable Messages API.Usage
Place a schema file at app/views/agents/colors_agent/primary_colors.json:
ActiveAgent serializes the request as:
Supported input forms
All four input forms produce the same output_config payload:
response_format: :json_schemaresponse_format: { type: "json_schema" }response_format: { type: "json_schema", json_schema: { name:, schema:, strict: } }response_format: { type: "json_schema", json_schema: "other" }Files changed
Production code (2 files):
normalize_response_formatto convertjson_schematooutput_config.format; call it innormalize_paramsresponse_formatwithout deleting so@response_formatis preserved forjson_objectemulation;normalize_paramshandles deletion and conversionTest code (1 file, 6 tests):
test_request_builderfor all four input forms; enable live VCR test assertingresponse.format.type == "json_schema"andresponse.message.parsed_json[:colors]is an ArraySupporting files:
json_schemavariantsjson_schema: ❌ → 🟩)Design decisions
implementation provider-agnostic and consistent with how OpenAI structured output works in ActiveAgent.
but not forwarded.
prefill are incompatible, so they remain separate code paths.
Test plan