Skip to content

fix(adapter): normalize reasoning effort with graceful degradation - #26111

Merged
krrish-berri-2 merged 5 commits into
BerriAI:litellm_oss_staging_04_22_2026from
Vigilans:vigilans/reasoning-effort-fields-v2
Apr 23, 2026
Merged

krrish-berri-2 merged 5 commits into
BerriAI:litellm_oss_staging_04_22_2026from
Vigilans:vigilans/reasoning-effort-fields-v2

Conversation

@Vigilans

@Vigilans Vigilans commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Relevant issues

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory
  • 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
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5

Type

🐛 Bug Fix

Changes

Problem

Anthropic's adaptive thinking (thinking.type="adaptive") and output_config.effort are silently dropped when translating /v1/messages requests to OpenAI format — the outgoing request has no reasoning_effort, so the model doesn't use extended thinking.

Additionally, clients that request effort levels like max or minimal get hard failures if the target model doesn't support that exact level, instead of degrading gracefully.

Solution

1. normalize_reasoning_effort_value() — graceful degradation

A normalize function that maps unsupported effort levels to the closest supported one, using model capability fields from the registry:

  • max → max / xhigh / high (depending on supports_max_reasoning_effort)
  • xhigh → xhigh / high (depending on supports_xhigh_reasoning_effort)
  • minimal → minimal / low (depending on supports_minimal_reasoning_effort)
  • high, medium, low pass through unchanged

This lets clients request max effort without knowing model-specific constraints.

2. Capability fields in model registry

  • supports_max_reasoning_effort: true for all Opus 4.7 entries
  • supports_minimal_reasoning_effort: true for all Claude 4.6/4.7 entries (Opus 4.6, Sonnet 4.6, Opus 4.7) across all provider variants (Bedrock, Vertex AI, Azure AI)
  • supports_minimal_reasoning_effort added to ProviderSpecificModelInfo TypedDict + _get_model_info_helper

3. Adapter path wiring

  • Adaptive thinking (type: "adaptive") now maps to reasoning_effort: "medium" by default
  • output_config.effort extracted and passed through as reasoning_effort
  • Normalize function called at both adapter paths (messages→completions and messages→responses)

Files changed:

File Change
.../utils.py normalize_reasoning_effort_value() + is_reasoning_auto_summary_enabled()
.../adapters/transformation.py Adaptive thinking branch + output_config passthrough
.../adapters/handler.py Extract output_config, call normalize before routing
.../responses_adapters/transformation.py Adaptive thinking branch in translate_thinking_to_reasoning()
.../responses_adapters/handler.py Call normalize after translation
litellm/types/utils.py Add supports_minimal_reasoning_effort to TypedDict
litellm/utils.py Read supports_minimal_reasoning_effort in _get_model_info_helper
model_prices_and_context_window.json Add capability fields to Claude 4.6/4.7 model entries

Test plan

29 tests:

Model registry fields:

  • get_model_info returns supports_minimal_reasoning_effort and supports_max_reasoning_effort
  • JSON entries: Opus 4.7 has supports_max=True, all 4.6/4.7 have supports_minimal=True

normalize_reasoning_effort_value:

  • All degradation chains: max→xhigh→high, xhigh→high, minimal→low
  • Passthrough for high/medium/low
  • Exception fallback (returns original value)

Adapter translation:

  • Adaptive thinking returns medium default
  • output_config.effort overrides reasoning_effort

…_info

_get_model_info_helper constructs ModelInfoBase explicitly but never
reads supports_xhigh/minimal/none_reasoning_effort from the cost map
JSON. Add the three fields so get_model_info() returns them correctly.

Also add supports_minimal_reasoning_effort to the ModelInfo TypedDict
(xhigh and none were already declared, minimal was missing).
….6/4.7

Claude Opus 4.7 supports max reasoning effort (above xhigh).
The field was present for Opus 4.6 but missing for all Opus 4.7
entries (base, dated, Bedrock, Vertex AI, Azure AI).

All Claude 4.6/4.7 models (Opus 4.6, Sonnet 4.6, Opus 4.7) support
minimal reasoning effort via adaptive thinking. Add the field to all
provider variants.
…5079)

Anthropic's adaptive thinking (thinking.type="adaptive") and
output_config.effort were silently dropped when translating to
OpenAI format, resulting in no reasoning_effort on the outgoing
request.

Adapter changes (format translation):
- adapters/transformation.py: add "adaptive" branch to
  translate_anthropic_thinking_to_reasoning_effort(); pass through
  output_config.effort as-is in _translate_thinking_to_openai();
  add "output_config" to translatable_anthropic_params
- adapters/handler.py: extract output_config from extra_kwargs into
  request_data so it reaches the translation layer
- responses_adapters/transformation.py: add "adaptive" branch and
  output_config param to translate_thinking_to_reasoning()

Handler changes (model-aware normalization):
- utils.py: add normalize_reasoning_effort_value() that uses
  get_model_info() to map "max" → "xhigh"/"high" and
  "minimal" → "minimal"/"low" based on model capabilities
- adapters/handler.py: call normalization before responses routing
- responses_adapters/handler.py: call normalization after translation

Relates to BerriAI#25079
…rmalize logic

Test coverage for:
- get_model_info returning supports_minimal/max_reasoning_effort fields
- JSON registry entries for claude 4.6/4.7 across all providers
- normalize_reasoning_effort_value degradation chains and exception fallback
- Adapter translation of adaptive thinking + output_config.effort
@greptile-apps

greptile-apps Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes silent dropping of Anthropic adaptive thinking (thinking.type="adaptive") and output_config.effort when translating /v1/messages requests to OpenAI format. It adds a normalize_reasoning_effort_value() helper with graceful degradation chains (max→xhigh→high, minimal→low), wires output_config through both adapter paths, and populates new capability fields (supports_max_reasoning_effort, supports_minimal_reasoning_effort) in the model registry — following the existing pattern for model-capability flags.

Confidence Score: 5/5

Safe to merge — all findings are P2 or lower; logic, tests, and registry additions are correct.

No P0/P1 issues found. The normalization logic is correct, degradation chains are properly tested with mocks, adapter wiring handles both completions and responses paths, and capability flags follow the established model registry pattern. The previous thread concerns around custom_llm_provider forwarding in responses_adapters/handler.py have been addressed.

No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/anthropic/experimental_pass_through/utils.py Adds normalize_reasoning_effort_value() with lazy get_model_info import and exception fallback; logic and degradation chains are correct.
litellm/llms/anthropic/experimental_pass_through/adapters/handler.py Adds _normalize_reasoning_effort static method and output_config extraction from extra_kwargs; normalization correctly runs before _route_openai_thinking to avoid model-name mangling.
litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py Adds adaptive thinking branch returning 'medium' default; output_config.effort override in _set_reasoning_effort is correctly applied after the early-return guard.
litellm/llms/anthropic/experimental_pass_through/responses_adapters/handler.py Adds post-translation normalization for reasoning.effort in responses path; custom_llm_provider correctly extracted from extra_kwargs (previous thread concern addressed).
litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py translate_thinking_to_reasoning refactored to handle adaptive/enabled/disabled types distinctly; output_config parameter added with correct fallback to 'medium' default.
litellm/types/utils.py Adds supports_minimal_reasoning_effort and supports_max_reasoning_effort to ProviderSpecificModelInfo TypedDict with Optional[bool] as expected.
litellm/utils.py _get_model_info_helper correctly reads both new fields from model registry JSON with None default.
model_prices_and_context_window.json Capability flags added to Claude 4.6/4.7 entries across all provider variants (Bedrock, Vertex, Azure AI, OpenRouter); matches PR description's scope.
tests/test_litellm/llms/anthropic/experimental_pass_through/test_reasoning_effort_fields.py 29 tests covering degradation chains, JSON registry correctness, and adapter translation; all use mocks or local file reads — no real network calls.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Anthropic /v1/messages request\n(thinking: adaptive or enabled,\noutput_config.effort)"] --> B{Adapter path}

    B -->|completions| C["handler.py\nExtract output_config → request_data"]
    B -->|responses| D["responses_adapters/handler.py\ntranslate_request()"]

    C --> E["transformation.py\ntranslate_anthropic_thinking_to_reasoning_effort()"]
    E -->|type == adaptive| F["reasoning_effort = 'medium'"]
    E -->|type == enabled| G["reasoning_effort from budget_tokens\n≥10000→high, ≥5000→med, ≥2000→low, else→minimal"]

    F --> H["_set_reasoning_effort()\noverride with output_config.effort if present"]
    G --> H

    H --> I["_normalize_reasoning_effort()\ncompletion_kwargs"]
    I --> J["normalize_reasoning_effort_value()\nlookup model_info via get_model_info()"]

    D --> K["translate_thinking_to_reasoning()\nadaptive→effort=medium or output_config.effort\nenabled→budget_tokens mapping"]
    K --> L["normalize_reasoning_effort_value()\nlookup model_info via get_model_info()"]

    J --> M{effort level}
    L --> M

    M -->|max| N["supports_max? → max\nsupports_xhigh? → xhigh\nelse → high"]
    M -->|xhigh| O["supports_xhigh? → xhigh\nelse → high"]
    M -->|minimal| P["supports_minimal? → minimal\nelse → low"]
    M -->|high/medium/low| Q["pass through unchanged"]

    N --> R["Final OpenAI/Responses API request\nwith normalized reasoning_effort"]
    O --> R
    P --> R
    Q --> R
Loading

Reviews (3): Last reviewed commit: "fix: forward custom_llm_provider to norm..." | Re-trigger Greptile

if model_info.get("supports_minimal_reasoning_effort"):
return "minimal"
return "low"
return "medium"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Unreachable return "medium" — dead code

The early guard on line 29 guarantees that by the time execution reaches the if/elif chain, effort is one of "max", "xhigh", or "minimal". Each branch has an explicit return, so this final return "medium" can never be reached. It could mislead future maintainers into thinking there is a code path that falls through to it.

Suggested change
return "medium"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Keeping it intentionally as a defensive fallback — if future changes add new effort levels or modify the early guard, this ensures a safe default instead of falling off the function. No runtime cost.

)

effort = reasoning["effort"]
normalized = normalize_reasoning_effort_value(effort, model=model)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 custom_llm_provider not forwarded to normalize call

The parallel call in adapters/handler.py passes custom_llm_provider so that get_model_info can resolve Bedrock/Vertex model entries correctly. This call omits it, which means capability lookups for provider-prefixed model names (e.g. vertex_ai/claude-opus-4-7) may silently fall back to the bare-model entry — or miss it entirely — and produce wrong degradation.

Suggested change
normalized = normalize_reasoning_effort_value(effort, model=model)
normalized = normalize_reasoning_effort_value(effort, model=model, custom_llm_provider=responses_kwargs.get("custom_llm_provider"))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

@codecov

codecov Bot commented Apr 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...opic/experimental_pass_through/adapters/handler.py 42.85% 12 Missing ⚠️
...imental_pass_through/responses_adapters/handler.py 85.71% 1 Missing ⚠️
.../llms/anthropic/experimental_pass_through/utils.py 95.83% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Vigilans

Copy link
Copy Markdown
Contributor Author

@greptileai request re-review

@Vigilans
Vigilans force-pushed the vigilans/reasoning-effort-fields-v2 branch from 7621690 to 70855c9 Compare April 20, 2026 15:19
@krrish-berri-2

Copy link
Copy Markdown
Contributor

@Vigilans can you include a screenshot of this working?

@Vigilans

Copy link
Copy Markdown
Contributor Author

@Vigilans can you include a screenshot of this working?

@krrish-berri-2

  1. Anthropic's adaptive thinking (thinking.type="adaptive") and output_config.effort are silently dropped when translating /v1/messages requests to OpenAI format

    Request (gpt-5.4-mini with effort=high and mode=chat, without this PR):
    image

    Response:
    image

    We can see that in response effort is none but not high. After this PR, the response effort will be high.

  2. normalize_reasoning_effort_value() — graceful degradation
    Without graceful degradation, max effort will cause error on gpt model:
    image

    The minimal -> low mapping I don't recall the specific scenario I encountered the problem (about half a month ago). Somehow a coding agent passed the minimal to a GPT model that does not support it and the error occurred.

@krrish-berri-2
krrish-berri-2 changed the base branch from litellm_internal_staging to litellm_oss_staging_04_22_2026 April 23, 2026 02:19
@krrish-berri-2
krrish-berri-2 merged commit b42b86d into BerriAI:litellm_oss_staging_04_22_2026 Apr 23, 2026
40 of 41 checks passed
AlataChan added a commit to AlataChan/litellm that referenced this pull request Apr 24, 2026
LiteLLM v1.83.13-nightly 的内置 deepseek/ 适配器尚未登记 V4 新模型(
deepseek-v4-flash / deepseek-v4-pro),直接用 deepseek/ 前缀可能报
unknown model。

改用 openai/ 前缀 + 显式 api_base: https://api.deepseek.com,走 DeepSeek
官方的 OpenAI 兼容端点,不依赖 LiteLLM 模型表更新,未来新模型立刻能用。

同时把 reasoning_effort / thinking 这些自定义参数统一放到 extra_body,
避免被 LiteLLM 的 OpenAI-effort 校验 "graceful degrade"(BerriAI#26111)。

README 排查清单新增两条对应症状。

Made-with: Cursor
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.

/v1/messages: output_config.effort not mapped to reasoning_effort for non-Anthropic providers

2 participants