From 2a1d9866458adf1ec336b3629d162ab87790869f Mon Sep 17 00:00:00 2001 From: Gennaro Malafronte <8798987+malafronte@users.noreply.github.com> Date: Mon, 27 Apr 2026 18:18:02 +0200 Subject: [PATCH] fix(anthropic): sanitize think tags across pass-through handlers --- .../experimental_pass_through/messages/handler.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py index a4d611d3568..6c255a69690 100644 --- a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py @@ -323,7 +323,7 @@ async def anthropic_messages( response = await init_response else: response = init_response - return response + return _sanitize_think_tag_text_blocks(response) def validate_anthropic_api_metadata(metadata: Optional[Dict] = None) -> Optional[Dict]: @@ -458,10 +458,12 @@ def anthropic_messages_handler( **kwargs, ) if _should_route_to_responses_api(custom_llm_provider): - return LiteLLMMessagesToResponsesAPIHandler.anthropic_messages_handler( - **_shared_kwargs + return _sanitize_think_tag_text_blocks( + LiteLLMMessagesToResponsesAPIHandler.anthropic_messages_handler( + **_shared_kwargs + ) ) - return ( + return _sanitize_think_tag_text_blocks( LiteLLMMessagesToCompletionTransformationHandler.anthropic_messages_handler( **_shared_kwargs )