{"record":{"id":"f70e9d7a325c204a","repo":"BerriAI/litellm","slug":"tool-result-message-must-have-a-string-tool-call","errorCode":null,"errorMessage":"Tool result message must have a string `tool_call_id`","messagePattern":"Tool result message must have a string `tool_call_id`","errorType":"exception","errorClass":"OCIError","httpStatus":400,"severity":"error","filePath":"litellm/llms/oci/chat/generic.py","lineNumber":195,"sourceCode":"        tool_calls = message.get(\"tool_calls\")\n        tool_call_id = message.get(\"tool_call_id\")\n\n        if role == \"assistant\" and tool_calls is not None:\n            if not isinstance(tool_calls, list):\n                raise OCIError(status_code=400, message=\"Message `tool_calls` must be a list\")\n            new_messages.append(adapt_messages_to_generic_oci_standard_tool_call(role, tool_calls))\n\n        elif role in [\"system\", \"user\", \"assistant\"] and content is not None:\n            if not isinstance(content, (str, list)):\n                raise OCIError(\n                    status_code=400,\n                    message=\"Message `content` must be a string or list of content parts\",\n                )\n            new_messages.append(adapt_messages_to_generic_oci_standard_content_message(role, content))\n\n        elif role == \"tool\":\n            if not isinstance(tool_call_id, str):\n                raise OCIError(\n                    status_code=400,\n                    message=\"Tool result message must have a string `tool_call_id`\",\n                )\n            if not isinstance(content, str):\n                raise OCIError(\n                    status_code=400,\n                    message=\"Tool result message `content` must be a string\",\n                )\n            new_messages.append(adapt_messages_to_generic_oci_standard_tool_response(role, tool_call_id, content))\n\n    return new_messages\n\n\n# ---------------------------------------------------------------------------\n# Tool definition adaptation\n# ---------------------------------------------------------------------------\n\n","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/oci/chat/generic.py#L177-L213","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\n{\"role\": \"tool\", \"content\": \"22C sunny\"}\n\n# after\n{\"role\": \"tool\", \"tool_call_id\": \"call_abc123\", \"content\": \"22C sunny\"}","handlingStrategy":"type-guard","validationCode":"def tool_messages_have_ids(messages: list) -> bool:\n    return all(\n        isinstance(m.get(\"tool_call_id\"), str)\n        for m in messages if m.get(\"role\") == \"tool\"\n    )","typeGuard":"def is_valid_tool_result_message(m) -> bool:\n    return m.get(\"role\") == \"tool\" and isinstance(m.get(\"tool_call_id\"), str)","tryCatchPattern":null,"preventionTips":["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"],"tags":["oci","tool-calls","correlation-id","request-validation"],"backgroundTag":"request-body-validation-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}