From 058f264a16adc9e176f994717d089264a784a5a9 Mon Sep 17 00:00:00 2001 From: Jah-yee <166608075+Jah-yee@users.noreply.github.com> Date: Thu, 28 May 2026 02:02:23 +0800 Subject: [PATCH] fix(ollama): properly parse tool_calls with dict arguments Fixes: https://github.com/BerriAI/litellm/issues/24091 --- litellm/llms/ollama/chat/transformation.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/litellm/llms/ollama/chat/transformation.py b/litellm/llms/ollama/chat/transformation.py index e36150a4954..d709f33afa7 100644 --- a/litellm/llms/ollama/chat/transformation.py +++ b/litellm/llms/ollama/chat/transformation.py @@ -377,6 +377,20 @@ class OllamaChatConfig(BaseConfig): response_json_message["reasoning_content"] = reasoning_content response_json_message["content"] = content + # Handle tool_calls explicitly - ensure they're properly converted + # Fixes: https://github.com/BerriAI/litellm/issues/24091 + tool_calls = response_json_message.get("tool_calls") if response_json_message else None + if tool_calls and isinstance(tool_calls, list): + converted_tool_calls = [] + for tc in tool_calls: + # Ensure arguments is a string (not a dict) for ChatCompletionMessageToolCall + if "function" in tc: + func = tc["function"] + if "arguments" in func and isinstance(func["arguments"], dict): + tc["function"]["arguments"] = json.dumps(func["arguments"]) + converted_tool_calls.append(tc) + response_json_message["tool_calls"] = converted_tool_calls + if ( request_data.get("format", "") == "json" and litellm_params.get("function_name") is not None