Skip to content

fix(anthropic): align translate_thinking_for_model with default summary injection + docs#22909

Merged
Chesars merged 1 commit intoBerriAI:litellm_oss_staging_03_05_2026from
Chesars:fix/greptile-reasoning-summary-followup
Mar 5, 2026
Merged

fix(anthropic): align translate_thinking_for_model with default summary injection + docs#22909
Chesars merged 1 commit intoBerriAI:litellm_oss_staging_03_05_2026from
Chesars:fix/greptile-reasoning-summary-followup

Conversation

@Chesars
Copy link
Copy Markdown
Contributor

@Chesars Chesars commented Mar 5, 2026

Relevant issues

Follow-up to #22904.

Pre-Submission checklist

  • I have Added testing in the tests/test_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

Type

🐛 Bug Fix
📖 Documentation

Changes

  • Updated translate_thinking_for_model to use is_default_reasoning_summary_disabled() and inject summary="detailed" by default (matching the other two code paths).
  • Added 2 new tests verifying the flag behavior in this code path.
  • Updated existing test assertion to reflect the new default behavior.
  • Added docs section "Default Summary Injection for /v1/messages Adapter" in reasoning_content.md covering SDK, env var, and proxy config usage.

…ry injection + add docs

- Update translate_thinking_for_model (3rd code path) to inject
  summary="detailed" by default, consistent with the other two paths
- Add disable_default_reasoning_summary flag check via shared helper
- Add tests for flag enabled/disabled and user-provided summary
- Document disable_default_reasoning_summary in reasoning_content.md
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 5, 2026

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

Project Deployment Actions Updated (UTC)
litellm Error Error Mar 5, 2026 3:23pm

Request Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 5, 2026

Greptile Summary

This PR aligns translate_thinking_for_model with the default summary="detailed" injection behavior introduced in #22904, and adds documentation and tests for the opt-out flag.

  • Core change: translate_thinking_for_model in adapters/transformation.py now injects {"effort": ..., "summary": "detailed"} by default when no user-provided summary is present and disable_default_reasoning_summary is not set, changing the return shape from {"reasoning_effort": "<string>"} to an object.
  • Flag wiring: Correctly reuses the existing is_default_reasoning_summary_disabled() helper from experimental_pass_through/utils.py, consistent with the other two call sites in adapters/handler.py and responses_adapters/transformation.py.
  • Tests: Two new mock-only tests added verifying both the default behavior (with summary injection) and the disabled-flag behavior (plain string return); existing assertions updated appropriately; global state is properly restored via try/finally.
  • Docs: New section in reasoning_content.md documents the SDK flag, env var, and proxy config opt-out options clearly, including a note that user-provided summaries are always preserved.
  • Backwards-compatibility concern: The default return shape change from {"reasoning_effort": "<string>"} to {"reasoning_effort": {"effort": "<string>", "summary": "detailed"}} is opt-out rather than opt-in. Downstream consumers expecting a string value may silently break unless they set the flag. However, the pattern aligns with changes already accepted in feat(anthropic): add opt-out flag for default reasoning summary #22904, and the new documentation makes the opt-out flag discoverable.

Confidence Score: 4/5

  • Safe to merge with awareness of the opt-out backwards-compatibility pattern. The change is consistent with feat(anthropic): add opt-out flag for default reasoning summary #22904, tests are proper, and documentation is clear.
  • The logic is correct, tests are proper mock-only unit tests with appropriate state cleanup, and the change is consistent with the two other code paths updated in feat(anthropic): add opt-out flag for default reasoning summary #22904. The primary concern is that the default behavior change from {"reasoning_effort": "<string>"} to {"reasoning_effort": {"effort": "<string>", "summary": "detailed"}} is opt-out rather than opt-in, which could silently affect downstream consumers expecting a plain string. However, this is mitigated by (1) clear documentation of the opt-out flag, (2) the pattern having been established and accepted in feat(anthropic): add opt-out flag for default reasoning summary #22904, and (3) a straightforward disable mechanism. This is a deliberate design choice aligned with the earlier PR rather than an oversight.
  • litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py — the default return shape change may impact downstream consumers that expect reasoning_effort to be a plain string. The disable_default_reasoning_summary flag provides an opt-out, but existing users must discover and use it to avoid the new behavior.

Important Files Changed

Filename Overview
litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py Adds summary="detailed" default injection to translate_thinking_for_model when no user-provided summary is present and disable_default_reasoning_summary is not set. Logically correct and consistent with the other two code paths, but changes the existing default return shape from a plain string to an object. This is a backwards-incompatible change, opt-out rather than opt-in, which could silently affect downstream consumers that expected reasoning_effort to be a plain string.
tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py Two new unit tests added (test_translate_thinking_for_model_no_summary_when_disabled and test_non_claude_model_converts_thinking_to_reasoning_effort) properly verify the disabled-flag path and the default injection behavior. Both are mock-only tests that correctly restore global state via try/finally. Existing test assertions properly updated to reflect the new default behavior of including summary="detailed".
docs/my-website/docs/reasoning_content.md New "Default Summary Injection for /v1/messages Adapter" section clearly documents the opt-out flag with SDK, env var, and proxy config examples. Documentation explains how to disable the default injection and includes a note that user-provided summaries are always preserved regardless of the flag. Clear and accurate.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[translate_thinking_for_model] --> B{is_anthropic_claude_model?}
    B -- Yes --> C[Return thinking param as-is]
    B -- No --> D[translate_anthropic_thinking_to_reasoning_effort]
    D --> E{reasoning_effort resolved?}
    E -- No --> F[Return empty dict]
    E -- Yes --> G{User provided summary<br/>in thinking dict?}
    G -- Yes --> H["Return {effort, summary: user_value}"]
    G -- No --> I{is_default_reasoning_summary_disabled?<br/>litellm flag OR env var}
    I -- True --> J["Return {reasoning_effort: string}"]
    I -- False --> K["Return {effort, summary: 'detailed'}"]
Loading

Last reviewed commit: 5b904f6

@Chesars Chesars merged commit 5c418d8 into BerriAI:litellm_oss_staging_03_05_2026 Mar 5, 2026
4 of 5 checks passed
@Chesars Chesars deleted the fix/greptile-reasoning-summary-followup branch March 5, 2026 15:41
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.

1 participant