BerriAI/litellm · error · OCIError
Tool result message must have a string `tool_call_id`
Error message
Tool result message must have a string `tool_call_id`
What it means
Tool-result messages (role "tool") must reference the call they answer via a string `tool_call_id`; OCI GENERIC needs that correlation. A missing, None, or non-string tool_call_id raises OCIError 400 before the tool response is adapted. Fail-fast client-side, mirroring how strictly the assistant side validates ids (1691).
Solutions
- Copy the id from the assistant tool call you are answering: tool_call_id=call["id"]
- Thread ids through your agent loop state rather than rebuilding them
- Map framework field names to tool_call_id at your boundary
- Drop orphan tool messages (no matching call) instead of sending them
Example fix
# before
{"role": "tool", "content": "22C sunny"}
# after
{"role": "tool", "tool_call_id": "call_abc123", "content": "22C sunny"} Defensive patterns
Strategy: type-guard
Validate before calling
def tool_messages_have_ids(messages: list) -> bool:
return all(
isinstance(m.get("tool_call_id"), str)
for m in messages if m.get("role") == "tool"
) Type guard
def is_valid_tool_result_message(m) -> bool:
return m.get("role") == "tool" and isinstance(m.get("tool_call_id"), str) Prevention
- Answer tool calls with the exact id the model issued — store it alongside the pending call
- Drop tool results whose originating call was trimmed from history; unpaired results always fail
When it happens
Trigger: messages containing {"role":"tool","content":"result"} without tool_call_id, or with tool_call_id=1 (int), sent to an oci/generic.* model. Fires in the message loop immediately, before content checks.
Common situations: Compressing history and dropping tool_call_id; agent loops that respond to tool calls without threading the id through; ids renamed by framework abstractions (call_id, tool_callId); pairing logic that looks up ids from the wrong previous turn.
Related errors
- Tool call `id` must be a string
- 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/f70e9d7a325c204a.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/oci/chat/generic.py:195
tool_calls = message.get("tool_calls")
tool_call_id = message.get("tool_call_id")
if role == "assistant" and tool_calls is not None:
if not isinstance(tool_calls, list):
raise OCIError(status_code=400, message="Message `tool_calls` must be a list")
new_messages.append(adapt_messages_to_generic_oci_standard_tool_call(role, tool_calls))
elif role in ["system", "user", "assistant"] and content is not None:
if not isinstance(content, (str, list)):
raise OCIError(
status_code=400,
message="Message `content` must be a string or list of content parts",
)
new_messages.append(adapt_messages_to_generic_oci_standard_content_message(role, content))
elif role == "tool":
if not isinstance(tool_call_id, str):
raise OCIError(
status_code=400,
message="Tool result message must have a string `tool_call_id`",
)
if not isinstance(content, str):
raise OCIError(
status_code=400,
message="Tool result message `content` must be a string",
)
new_messages.append(adapt_messages_to_generic_oci_standard_tool_response(role, tool_call_id, content))
return new_messages
# ---------------------------------------------------------------------------
# Tool definition adaptation
# ---------------------------------------------------------------------------
View on GitHub (pinned to 77b7c6c40c)