BerriAI/litellm · error · OCIError
Tool call `id` must be a string
Error message
Tool call `id` must be a string
What it means
Each function tool call in an assistant message must carry a string `id`, because OCI GENERIC requires a tool-call identifier to correlate the subsequent tool-result message. A missing, None, or non-string id raises OCIError 400 during translation. Client-side fail-fast: no network call happens.
Solutions
- Preserve the original tool_call ids from the model response when replaying history
- Synthesize deterministic ids where none exist: f"call_{uuid4().hex}" — but use the same value in the paired tool message's tool_call_id
- Fix trimming logic to treat id as required, not optional
- Map framework field names (call_id -> id) at your boundary
Example fix
# before
{"role": "assistant", "tool_calls": [{"type": "function", "function": {"name": "f", "arguments": "{}"}}]}
# after
{"role": "assistant", "tool_calls": [{"id": "call_abc123", "type": "function", "function": {"name": "f", "arguments": "{}"}}]} Defensive patterns
Strategy: type-guard
Validate before calling
from uuid import uuid4
def ensure_tool_call_ids(tool_calls: list) -> list:
out = []
for tc in tool_calls:
if not isinstance(tc.get("id"), str):
tc = {**tc, "id": f"call_{uuid4().hex[:24]}"}
out.append(tc)
return out Type guard
def tool_call_has_string_id(tc) -> bool:
return isinstance(tc, dict) and isinstance(tc.get("id"), str) Prevention
- Thread the model-issued call id into the paired tool message; never regenerate one side
- Keep id in required fields when persisting history schemas
When it happens
Trigger: Replayed assistant tool_calls where ids were stripped by history compression, replaced with ints, or lost through serialization — sent with an oci/generic.* model. The matching tool message's tool_call_id would also be uncorrelatable, hence the strict check.
Common situations: Context-window trimming code that drops small-looking keys; LLM-generated assistant messages (from a model, not an API) lacking ids; custom agent frameworks that fabricate tool_calls without ids; id renamed (call_id) by a framework abstraction.
Related errors
- Tool result message must have a string `tool_call_id`
- Each tool call must be a dictionary
- Message `tool_calls` must be a list
- OCI only supports function tool calls
- Tool call `function.arguments` must be a JSON string
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/55dad91d9fb2663b.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/oci/chat/generic.py:125
role=open_ai_to_generic_oci_role_map[role],
content=new_content,
toolCalls=None,
toolCallId=None,
)
def adapt_messages_to_generic_oci_standard_tool_call(role: str, tool_calls: list) -> OCIMessage:
"""Convert an assistant tool-call message to OCI format."""
tool_calls_formatted: Final = []
for tool_call in tool_calls:
if not isinstance(tool_call, dict):
raise OCIError(status_code=400, message="Each tool call must be a dictionary")
if tool_call.get("type") != "function":
raise OCIError(status_code=400, message="OCI only supports function tool calls")
tool_call_id = tool_call.get("id")
if not isinstance(tool_call_id, str):
raise OCIError(status_code=400, message="Tool call `id` must be a string")
tool_function = tool_call.get("function")
if not isinstance(tool_function, dict):
raise OCIError(status_code=400, message="Tool call `function` must be a dictionary")
function_name = tool_function.get("name")
if not isinstance(function_name, str):
raise OCIError(status_code=400, message="Tool call `function.name` must be a string")
arguments = tool_call["function"].get("arguments", "{}")
if not isinstance(arguments, str):
raise OCIError(
status_code=400,
message="Tool call `function.arguments` must be a JSON string",
)
tool_calls_formatted.append(
OCIToolCall(View on GitHub (pinned to 77b7c6c40c)