feat: add structured output support to ChatAnthropic#474
Merged
brainlid merged 1 commit intobrainlid:mainfrom Feb 28, 2026
Merged
feat: add structured output support to ChatAnthropic#474brainlid merged 1 commit intobrainlid:mainfrom
brainlid merged 1 commit intobrainlid:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds native structured output support to ChatAnthropic using Anthropic's output_config.format API. The implementation allows developers to constrain Claude's responses to follow specific JSON schemas, which is supported on Claude Opus 4.6, Sonnet 4.6, Sonnet 4.5, Opus 4.5, and Haiku 4.5.
Changes:
- Added
json_response(boolean) andjson_schema(map) fields to ChatAnthropic model with appropriate defaults - Implemented validation requiring
json_schemawhenjson_response: true, reflecting Anthropic's requirement for schema (unlike OpenAI/DeepSeek which support schema-less JSON mode) - Updated API formatting to include
output_configwith proper structure when structured outputs are enabled - Added comprehensive documentation with examples and compatibility notes
- Added serialization support for the new fields
- Included comprehensive test coverage for validation, API formatting, and serialization
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/chat_models/chat_anthropic.ex | Core implementation: added fields, validation, API formatting (set_output_config), serialization, and comprehensive documentation for structured outputs |
| test/chat_models/chat_anthropic_test.exs | Comprehensive test coverage: field initialization, validation errors, API formatting, and serialization tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Owner
|
Nice @nallwhy! Thanks! |
brainlid
added a commit
that referenced
this pull request
Mar 4, 2026
* main: feat: add file_id support to ChatAnthropic (#475) fix: handle nil content in run_message_processors (#473) feat: add structured output support to ChatAnthropic (#474) fix: Fix verbosity parameter and better error handling (#476) formatting feat(gemini): adding inline_data support for pdf and csv (#478)
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
json_responseandjson_schemafields toChatAnthropicfor Anthropic's native structured outputs API (output_config.format)json_schemawhenjson_response: truevia changeset validation, since Anthropic has no schema-less JSON mode unlike OpenAIReferences