From e1a092044599ffeda5122fafd9adce879bb941e5 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 25 Aug 2026 13:54:34 -0700 Subject: [PATCH] refactor(anthropic): bind tool_result file parts once instead of seeding an empty tuple --- .../responses_adapters/transformation.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py index 43c3e504964..d9d62e0719f 100644 --- a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py @@ -271,7 +271,16 @@ class LiteLLMAnthropicToResponsesAPIAdapter: elif btype == "tool_result": tool_use_id = block.get("tool_use_id", "") inner = block.get("content") - tool_file_parts: tuple[dict[str, str], ...] = () # mutable-ok: json content parts + document_candidates = ( + tuple( + self._translate_anthropic_document_block_to_file_part(c) + for c in inner + if isinstance(c, dict) and c.get("type") == "document" + ) + if isinstance(inner, list) + else () + ) + tool_file_parts = tuple(part for part in document_candidates if part is not None) if inner is None: output_text = "" elif isinstance(inner, str): @@ -297,12 +306,6 @@ class LiteLLMAnthropicToResponsesAPIAdapter: {"type": "input_image", "image_url": url} # mutable-ok: json content part for url in image_urls ) - document_candidates = tuple( - self._translate_anthropic_document_block_to_file_part(c) - for c in inner - if isinstance(c, dict) and c.get("type") == "document" - ) - tool_file_parts = tuple(part for part in document_candidates if part is not None) else: output_text = str(inner) # tool_result is a top-level item, not inside the message