From 67426ac2633e76dcaf5fc2c7990d955ae645ecc9 Mon Sep 17 00:00:00 2001 From: Mrunmayee Daware <165297479+Mrun25@users.noreply.github.com> Date: Wed, 7 Oct 2026 19:25:14 +0530 Subject: [PATCH] refactor: compute tool_result content once, annotate as Final --- .../anthropic/pass_through/adapters/transformation.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/llms/anthropic/pass_through/adapters/transformation.py b/litellm/llms/anthropic/pass_through/adapters/transformation.py index 8bf0d43b235..f2734e77aec 100644 --- a/litellm/llms/anthropic/pass_through/adapters/transformation.py +++ b/litellm/llms/anthropic/pass_through/adapters/transformation.py @@ -525,9 +525,12 @@ class LiteLLMAnthropicMessagesAdapter: self._add_cache_control_if_applicable(content, doc_obj, model) new_user_content_list.append(doc_obj) elif content.get("type") == "tool_result": - tool_result_content = self._tool_result_content(content.get("content")) - if content.get("is_error"): - tool_result_content = self._mark_tool_result_as_error(tool_result_content) + raw_tool_result_content: Final = self._tool_result_content(content.get("content")) + tool_result_content: Final = ( + self._mark_tool_result_as_error(raw_tool_result_content) + if content.get("is_error") + else raw_tool_result_content + ) tool_result = ChatCompletionToolMessage( role="tool", tool_call_id=content.get("tool_use_id", ""),