{"record":{"id":"bf40b55828135b51","repo":"BerriAI/litellm","slug":"tool-call-function-name-must-be-a-string","errorCode":null,"errorMessage":"Tool call `function.name` must be a string","messagePattern":"Tool call `function\\.name` must be a string","errorType":"exception","errorClass":"OCIError","httpStatus":400,"severity":"error","filePath":"litellm/llms/oci/chat/generic.py","lineNumber":133,"sourceCode":"    \"\"\"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(\n                id=tool_call_id,\n                type=\"FUNCTION\",\n                name=function_name,\n                arguments=arguments,\n            )\n        )\n\n    return OCIMessage(","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/oci/chat/generic.py#L115-L151","documentation":"Within a tool call's function dict, `name` must be a string because OCI GENERIC requires the invoked function's name. A missing, None, or non-string name raises OCIError 400 client-side. This is the last shape check before the OCIToolCall is constructed.","triggerScenarios":"tool_calls entries like {\"function\":{\"arguments\":\"{}\"}} (no name), {\"function\":{\"name\":None}}, or {\"function\":{\"name\":42}} replayed to an oci/generic.* model in assistant history.","commonSituations":"Models emitting tool calls without names when a name was optional in your prompt; history trimming dropping the name key; name populated from a variable that is occasionally undefined; renaming keys (func->name) mid-migration.","solutions":["Always include a string function name matching one of the tools you declared","Default/derive at build time: tc[\"function\"].setdefault(\"name\", fallback_name)","Filter out malformed tool calls from replayed history rather than forwarding them","Assert name is str in your history serializer"],"exampleFix":"# before\n{\"id\":\"1\",\"type\":\"function\",\"function\":{\"arguments\":\"{\\\"city\\\":\\\"SF\\\"}\"}}\n\n# after\n{\"id\":\"1\",\"type\":\"function\",\"function\":{\"name\":\"get_weather\",\"arguments\":\"{\\\"city\\\":\\\"SF\\\"}\"}}","handlingStrategy":"type-guard","validationCode":"def drop_tool_calls_without_name(tool_calls: list) -> list:\n    return [tc for tc in tool_calls if isinstance(tc.get(\"function\", {}).get(\"name\"), str)]","typeGuard":"def tool_call_has_string_name(tc) -> bool:\n    fn = tc.get(\"function\")\n    return isinstance(fn, dict) and isinstance(fn.get(\"name\"), str)","tryCatchPattern":null,"preventionTips":["Name tool functions at construction; treat name as non-optional in your tool schemas","When models emit nameless calls, map them to a fallback handler name before replay"],"tags":["oci","tool-calls","function-name","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"}