BerriAI/litellm · error · Exception
Unable to convert openai tool calls=
Error message
Unable to convert openai tool calls={message} to gemini tool calls. Received error={e} What it means
Converting an OpenAI-style assistant tool_calls message into Gemini functionCall parts failed; the outer except wraps the concrete cause in the '{e}' suffix. The visible inner failure in this region is the explicit 'function_call missing' raise: a tool call with type='function' but no usable function name/arguments.
Solutions
- Inspect the wrapped error suffix and the message payload; fix the tool_call to include function.name
- Normalize/filter tool_calls before sending: drop entries without a function object
- Retry with a provider/model that returns well-formed tool calls
Example fix
# before: tool call without a function name
{"role": "assistant", "content": None, "tool_calls": [{"id": "call_1", "type": "function", "function": {"arguments": "{}"}}]}
# after
{"role": "assistant", "content": None, "tool_calls": [{"id": "call_1", "type": "function", "function": {"name": "get_weather", "arguments": "{}"}}]} Defensive patterns
Strategy: try-catch
Validate before calling
def normalize_tool_calls(messages: list[dict]) -> list[dict]:
"""Drop assistant tool_calls entries lacking a function name."""
for m in messages:
if m.get("role") == "assistant" and isinstance(m.get("tool_calls"), list):
m["tool_calls"] = [
tc for tc in m["tool_calls"]
if isinstance(tc, dict)
and isinstance(tc.get("function"), dict)
and tc["function"].get("name")
]
if not m["tool_calls"]:
m.pop("tool_calls")
return messages Type guard
from typing import Any, TypeGuard
def is_wellformed_tool_call(tc: Any) -> TypeGuard[dict]:
return (
isinstance(tc, dict)
and tc.get("type") == "function"
and isinstance(tc.get("function"), dict)
and bool(tc["function"].get("name"))
and isinstance(tc["function"].get("arguments"), str)
) Try / catch
try:
litellm.completion(model="gemini/...", messages=messages)
except Exception as e:
if "Unable to convert openai tool calls" in str(e):
# inspect str(e) suffix + logged message; fix or drop the malformed tool_call, retry
messages = normalize_tool_calls(messages)
else:
raise Prevention
- Validate assistant tool_calls shape before replaying captured or hand-built messages
- Always persist tool_calls including function.name and arguments verbatim
- Wrap conversions and log the exact message payload on failure for quick diagnosis
When it happens
Trigger: Hand-built assistant messages whose tool_calls entries lack function.name or arguments; replaying captured model output where fields were dropped; empty tool_call objects in the array; any exception during part construction gets wrapped here.
Common situations: Crafting assistant prefill messages with tool calls by hand; checkpoint/resume pipelines that serialize tool_calls lossily; provider drift changing tool_call shapes.
Related errors
- Missing corresponding tool call for tool response message…
- Unable to parse anthropic tool result for message
- BedrockException - . Enable 'litellm.modify_params=True'…
- Chat provider: Invalid function argument delta
- Either 'model' or 'agent' must be provided
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/0dd34a3107edd9c6.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/prompt_templates/factory.py:1360
)
if isinstance(provider_fields, dict):
thought_signature = provider_fields.get("thought_signature")
# If no signature found and model is gemini-3, use dummy signature
if not thought_signature and model and VertexGeminiConfig._is_gemini_3_or_newer(model):
thought_signature = _get_dummy_thought_signature()
if thought_signature:
part_dict_function["thoughtSignature"] = thought_signature
_parts_list.append(part_dict_function)
else: # don't silently drop params. Make it clear to user what's happening.
raise Exception(
f"function_call missing. Received tool call with 'type': 'function'. No function call in argument - {message}"
)
return _parts_list
except Exception as e:
raise Exception(f"Unable to convert openai tool calls={message} to gemini tool calls. Received error={e}")
def convert_to_gemini_tool_call_result(
message: ChatCompletionToolMessage | ChatCompletionFunctionMessage,
last_message_with_tool_calls: dict | None,
forward_function_call_id: bool = False,
) -> VertexPartType | list[VertexPartType]:
"""
OpenAI message with a tool result looks like:
{
"tool_call_id": "tool_1",
"role": "tool",
"content": "function result goes here",
},
# NOTE: Function messages have been deprecated
OpenAI message with a function call result looks like:
{View on GitHub (pinned to 77b7c6c40c)