{"record":{"id":"280393fcefa8913a","repo":"BerriAI/litellm","slug":"invalid-message-passed-in-messages-msg-i-fil","errorCode":null,"errorMessage":"Invalid Message passed in - {messages[msg_i]}. File an issue https://github.com/BerriAI/litellm/issues","messagePattern":"Invalid Message passed in - (.+?)\\. File an issue https://github\\.com/BerriAI/litellm/issues","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/gemini/transformation.py","lineNumber":1055,"sourceCode":"            if msg_i < len(messages) and messages[msg_i][\"role\"] in tool_call_message_roles:\n                _part = convert_to_gemini_tool_call_result(\n                    messages[msg_i],\n                    last_message_with_tool_calls,\n                    forward_function_call_id=forward_function_call_id,\n                )\n                msg_i += 1\n                # Handle both single part and list of parts (for Computer Use with images)\n                if isinstance(_part, list):\n                    tool_call_responses.extend(_part)\n                else:\n                    tool_call_responses.append(_part)\n            if msg_i < len(messages) and (messages[msg_i][\"role\"] not in tool_call_message_roles):\n                if len(tool_call_responses) > 0:\n                    contents.append(ContentType(role=\"user\", parts=tool_call_responses))\n                    tool_call_responses = []\n\n            if msg_i == init_msg_i:  # prevent infinite loops\n                raise Exception(\n                    f\"Invalid Message passed in - {messages[msg_i]}. File an issue https://github.com/BerriAI/litellm/issues\"\n                )\n        if len(tool_call_responses) > 0:\n            contents.append(ContentType(role=\"user\", parts=tool_call_responses))\n\n        if len(contents) == 0:\n            verbose_logger.warning(\"\"\"\n                No contents in messages. Contents are required. See\n                https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.publishers.models/generateContent#request-body.\n                If the original request did not comply to OpenAI API requirements it should have failed by now,\n                but LiteLLM does not check for missing messages.\n                Setting an empty content to prevent an 400 error.\n                Relevant Issue - https://github.com/BerriAI/litellm/issues/9733\n                \"\"\")\n            contents.append(ContentType(role=\"user\", parts=[PartType(text=\" \")]))\n        return contents\n    except Exception as e:\n        raise e","sourceCodeStart":1037,"sourceCodeEnd":1073,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/gemini/transformation.py#L1037-L1073","documentation":"Gemini message-conversion sentinel: the message at messages[msg_i] has a role/shape the converter does not recognize (neither valid content nor tool-call result), so transformation fails and the user is pointed to the issue tracker.","triggerScenarios":"Triggered when a message passed to the Vertex AI Gemini transformation has an invalid structure.","commonSituations":"See trigger scenarios.","solutions":["Fix the malformed message at the reported index.","If the message looks valid, file an issue at the linked GitHub URL."],"exampleFix":"# ensure each message has valid role/content structure.","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}