Skip to content

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
kelvin-tran:kt/anthropic-opus-4-6-structured-outputs
Feb 11, 2026
Merged

feat: enable support for non-tool structured outputs on Anthropic Claude Opus 4.5 and 4.6 (use output_format param)#20548
Sameerlite merged 3 commits intoBerriAI:mainfrom
kelvin-tran:kt/anthropic-opus-4-6-structured-outputs

Conversation

@kelvin-tran
Copy link
Contributor

Relevant issues

Fixes #20533

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • 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 workaround
Add unit tests verifying Opus 4.5/4.6 use output_format and older models still use the tool-based fallback

Test plan

  • test_opus_uses_native_structured_output — parametrized across 4 model name variants, verifies output_format is set and no tool workaround is created
  • test_non_structured_output_model_uses_tool_workaround — verifies older models still use tool+tool_choice approach
  • Existing structured output tests continue to pass

@vercel
Copy link

vercel bot commented Feb 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 6, 2026 5:25pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 6, 2026

Greptile Overview

Greptile Summary

Added native structured output support for Anthropic Claude Opus 4.5 and 4.6 models by including their model name variants in the output_format parameter check.

  • Extended the model substring check to include opus-4.5, opus-4-5, opus-4.6, and opus-4-6
  • Models matching these patterns now use Anthropic's native output_format parameter instead of the tool-based workaround
  • Added comprehensive test coverage with parametrized tests for all 4 model name variants
  • Included regression test to ensure older models still use the tool-based fallback
  • poetry.lock changes are purely formatting updates from Poetry version change (2.3.2 → 2.2.1)

Confidence Score: 5/5

  • This PR is safe to merge with no risks identified
  • The change is minimal and surgical - only adds 4 new string patterns to an existing conditional check. The implementation follows the exact same pattern as existing opus-4.1 support. Comprehensive test coverage validates both the new functionality and ensures backward compatibility with older models.
  • No files require special attention

Important Files Changed

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
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@kelvin-tran
Copy link
Contributor Author

kelvin-tran commented Feb 6, 2026

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)

@kelvin-tran kelvin-tran closed this Feb 6, 2026
@kelvin-tran kelvin-tran reopened this Feb 6, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 6, 2026

Greptile Overview

Greptile Summary

  • Extends Anthropic response_format handling to treat Opus 4.5/4.6 model variants as supporting native structured outputs via output_format, instead of the existing tool+tool_choice workaround.
  • Adds unit tests asserting Opus 4.5/4.6 map response_formatoutput_format (and do not emit tools), while older Claude models still use the tool workaround.
  • Includes a large, unrelated poetry.lock regeneration/formatting change that should not be part of this feature PR.

Confidence Score: 3/5

  • Feature logic looks safe, but the lockfile changes make the PR risky to merge as-is.
  • The functional code change is small and covered by targeted tests, but poetry.lock has been broadly regenerated (different Poetry version header, widespread marker/constraint drift) which can break dependency resolution and is not required for the feature; this should be reverted or regenerated consistently before merge.
  • poetry.lock

Important Files Changed

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
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@kelvin-tran kelvin-tran force-pushed the kt/anthropic-opus-4-6-structured-outputs branch from 3c89541 to 82ba496 Compare February 6, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support Anthropic structured outputs on Opus 4.5 and 4.6 in Python SDK

2 participants