Conversation
Wire output_config into the Anthropic chat payload when a schema is
provided, using the GA format ({ format: { type: 'json_schema', schema } })
with no beta headers required. The build_output_config method deep-dups the
schema and strips :strict keys that Anthropic rejects.
Fix model detection regexes in capabilities to match Claude 4+ model IDs
(supports_functions?, supports_json_mode?, capabilities_for) and add
supports_structured_output? for Claude 4.5+ models.
Re-record Anthropic VCR cassettes.
| def supports_structured_output?(model_id) | ||
| model_id.match?(/claude-(?:sonnet|opus|haiku)-4-[56789]/) |
There was a problem hiding this comment.
# Structured output supported on Claude 4.5+ and all future major versions (5+).
# Uses \d{1,2} with boundary anchor to avoid matching date suffixes.
def supports_structured_output?(model_id)
match = model_id.match(/claude-(?:opus|sonnet|haiku)-(\d+)-(\d{1,2})(?:\b|-)/)
return false unless match
major, minor = match[1].to_i, match[2].to_i
major > 4 || (major == 4 && minor >= 5)
end
llenodo
left a comment
There was a problem hiding this comment.
Nice PR I almost implemented the same thing before finding this.
One suggestion to make it more future proof which assumes future versions of claude (5+) will support structured outputs so we wont need to come back to this later
|
@hiasinho Any chance this PR could also include structured output for anthropic models through AWS Bedrock? The AWS bedrock integration was recently rewritten to use converse API, which support structured output: https://docs.aws.amazon.com/bedrock/latest/userguide/structured-output.html |
Done! |
Would love to do it, but I don't use AWS. So no creds to create VCRs. Tests will fail. Feel free to build on it. |
Extend the Bedrock Converse API provider to support structured output via outputConfig.textFormat, building on crmne#608's Anthropic implementation. Key differences from the direct Anthropic API: schema must be a JSON string (not a Hash), nested under structure.jsonSchema with a required name field, and uses camelCase Converse API naming. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extend the Bedrock Converse API provider to support structured output via outputConfig.textFormat, building on crmne#608's Anthropic implementation. Key differences from the direct Anthropic API: schema must be a JSON string (not a Hash), nested under structure.jsonSchema with a required name field, and uses camelCase Converse API naming. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
What this does
Adds native structured output support for Anthropic Claude 4.5+ models using the GA output_config API. When with_schema is called on a chat using a supported Anthropic model, the schema is sent via output_config.format with type json_schema, and the response is automatically parsed as JSON.
Because I can't contribute to PR #528, I opened this one.
Type of change
Scope check
Required for new features
PRs for new features or enhancements without a prior approved issue will be closed.
Quality check
overcommit --installand all hooks passbundle exec rake vcr:record[provider_name]bundle exec rspecmodels.json,aliases.json)AI-generated code
API changes