{"record":{"id":"55dad91d9fb2663b","repo":"BerriAI/litellm","slug":"tool-call-id-must-be-a-string","errorCode":null,"errorMessage":"Tool call `id` must be a string","messagePattern":"Tool call `id` must be a string","errorType":"validation","errorClass":"OCIError","httpStatus":400,"severity":"error","filePath":"litellm/llms/oci/chat/generic.py","lineNumber":125,"sourceCode":"        role=open_ai_to_generic_oci_role_map[role],\n        content=new_content,\n        toolCalls=None,\n        toolCallId=None,\n    )\n\n\ndef adapt_messages_to_generic_oci_standard_tool_call(role: str, tool_calls: list) -> OCIMessage:\n    \"\"\"Convert an assistant tool-call message to OCI format.\"\"\"\n    tool_calls_formatted: Final = []\n    for tool_call in tool_calls:\n        if not isinstance(tool_call, dict):\n            raise OCIError(status_code=400, message=\"Each tool call must be a dictionary\")\n        if tool_call.get(\"type\") != \"function\":\n            raise OCIError(status_code=400, message=\"OCI only supports function tool calls\")\n\n        tool_call_id = tool_call.get(\"id\")\n        if not isinstance(tool_call_id, str):\n            raise OCIError(status_code=400, message=\"Tool call `id` must be a string\")\n\n        tool_function = tool_call.get(\"function\")\n        if not isinstance(tool_function, dict):\n            raise OCIError(status_code=400, message=\"Tool call `function` must be a dictionary\")\n\n        function_name = tool_function.get(\"name\")\n        if not isinstance(function_name, str):\n            raise OCIError(status_code=400, message=\"Tool call `function.name` must be a string\")\n\n        arguments = tool_call[\"function\"].get(\"arguments\", \"{}\")\n        if not isinstance(arguments, str):\n            raise OCIError(\n                status_code=400,\n                message=\"Tool call `function.arguments` must be a JSON string\",\n            )\n\n        tool_calls_formatted.append(\n            OCIToolCall(","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/oci/chat/generic.py#L107-L143","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\n{\"role\": \"assistant\", \"tool_calls\": [{\"type\": \"function\", \"function\": {\"name\": \"f\", \"arguments\": \"{}\"}}]}\n\n# after\n{\"role\": \"assistant\", \"tool_calls\": [{\"id\": \"call_abc123\", \"type\": \"function\", \"function\": {\"name\": \"f\", \"arguments\": \"{}\"}}]}","handlingStrategy":"type-guard","validationCode":"from uuid import uuid4\n\ndef ensure_tool_call_ids(tool_calls: list) -> list:\n    out = []\n    for tc in tool_calls:\n        if not isinstance(tc.get(\"id\"), str):\n            tc = {**tc, \"id\": f\"call_{uuid4().hex[:24]}\"}\n        out.append(tc)\n    return out","typeGuard":"def tool_call_has_string_id(tc) -> bool:\n    return isinstance(tc, dict) and isinstance(tc.get(\"id\"), str)","tryCatchPattern":null,"preventionTips":["Thread the model-issued call id into the paired tool message; never regenerate one side","Keep id in required fields when persisting history schemas"],"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"}