feat: enable support for non-tool structured outputs on Anthropic Claude Opus 4.5 and 4.6 (use output_format param)#20548
Merged
Sameerlite merged 3 commits intoBerriAI:mainfrom Feb 11, 2026
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile OverviewGreptile SummaryAdded native structured output support for Anthropic Claude Opus 4.5 and 4.6 models by including their model name variants in the
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/chat/transformation.py | Added opus-4.5 and opus-4.6 variants to native structured output support |
| tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py | Added comprehensive tests for Opus 4.5/4.6 native structured outputs and fallback behavior |
Sequence Diagram
sequenceDiagram
participant User
participant LiteLLM
participant AnthropicConfig
participant Anthropic API
User->>LiteLLM: Request with response_format
LiteLLM->>AnthropicConfig: map_openai_params(model, response_format)
alt Opus 4.5/4.6 or Sonnet 4.5
AnthropicConfig->>AnthropicConfig: Check if model contains opus-4.5/opus-4-5/opus-4.6/opus-4-6
AnthropicConfig->>AnthropicConfig: map_response_format_to_anthropic_output_format()
AnthropicConfig-->>LiteLLM: Return params with output_format (native)
LiteLLM->>Anthropic API: Call with output_format
else Older models (e.g., Sonnet 3.5)
AnthropicConfig->>AnthropicConfig: map_response_format_to_anthropic_tool()
AnthropicConfig-->>LiteLLM: Return params with tools + tool_choice (workaround)
LiteLLM->>Anthropic API: Call with tool-based structured output
end
Anthropic API-->>LiteLLM: Structured response
LiteLLM-->>User: Formatted output
Contributor
Author
|
Initially closed in favor of #20518, but realize that PR may take longer to push through given complexity. Also this issue was missed in @Sameerlite's #20551 (which aimed to fully support Opus 4.6) |
Contributor
Greptile OverviewGreptile Summary
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/chat/transformation.py | Adds Opus 4.5/4.6 model substrings to the allowlist for mapping OpenAI response_format to Anthropic native structured outputs via output_format; logic change is localized to response_format handling. |
| tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py | Adds unit tests asserting Opus 4.5/4.6 use output_format (no tool workaround) and that older models still use tools/tool_choice; removes an unused TestClient import. |
| poetry.lock | Lockfile regenerated with a different Poetry version and includes a resolved merge conflict section; large unrelated marker/constraint changes make this file unsafe as-is and likely to break dependency resolution. |
Sequence Diagram
sequenceDiagram
participant Caller as LiteLLM caller
participant AC as AnthropicConfig.map_openai_params
participant RF as response_format mapping
Caller->>AC: non_default_params{response_format}, model
AC->>RF: if model contains opus-4.5/4.6 or sonnet/opus allowlist
alt Allowlisted model (Opus 4.5/4.6)
RF-->>AC: map_response_format_to_anthropic_output_format()
AC-->>Caller: optional_params.output_format set
else Other models
RF-->>AC: map_response_format_to_anthropic_tool()
AC-->>Caller: optional_params.tools + optional_params.tool_choice set
end
AC-->>Caller: optional_params.json_mode = true
3c89541 to
82ba496
Compare
This was referenced Feb 6, 2026
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.
Relevant issues
Fixes #20533
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
Changes
Add Anthropic Opus 4.5 and 4.6 to native structured outputs support
Summary
Add opus-4.5 and opus-4.6 model variants to the set of Anthropic models that use native structured outputs (
output_format) instead of the tool-based workaroundAdd unit tests verifying Opus 4.5/4.6 use
output_formatand older models still use the tool-based fallbackTest plan
test_opus_uses_native_structured_output— parametrized across 4 model name variants, verifies output_format is set and no tool workaround is createdtest_non_structured_output_model_uses_tool_workaround— verifies older models still use tool+tool_choice approach