BerriAI/litellm · error · Exception

Invalid Message passed in - {messages[msg_i]}. File an issue

Error message

Invalid Message passed in - {messages[msg_i]}. File an issue https://github.com/BerriAI/litellm/issues

What it means

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.

Source

Thrown at litellm/llms/vertex_ai/gemini/transformation.py:1055

            if msg_i < len(messages) and messages[msg_i]["role"] in tool_call_message_roles:
                _part = convert_to_gemini_tool_call_result(
                    messages[msg_i],
                    last_message_with_tool_calls,
                    forward_function_call_id=forward_function_call_id,
                )
                msg_i += 1
                # Handle both single part and list of parts (for Computer Use with images)
                if isinstance(_part, list):
                    tool_call_responses.extend(_part)
                else:
                    tool_call_responses.append(_part)
            if msg_i < len(messages) and (messages[msg_i]["role"] not in tool_call_message_roles):
                if len(tool_call_responses) > 0:
                    contents.append(ContentType(role="user", parts=tool_call_responses))
                    tool_call_responses = []

            if msg_i == init_msg_i:  # prevent infinite loops
                raise Exception(
                    f"Invalid Message passed in - {messages[msg_i]}. File an issue https://github.com/BerriAI/litellm/issues"
                )
        if len(tool_call_responses) > 0:
            contents.append(ContentType(role="user", parts=tool_call_responses))

        if len(contents) == 0:
            verbose_logger.warning("""
                No contents in messages. Contents are required. See
                https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.publishers.models/generateContent#request-body.
                If the original request did not comply to OpenAI API requirements it should have failed by now,
                but LiteLLM does not check for missing messages.
                Setting an empty content to prevent an 400 error.
                Relevant Issue - https://github.com/BerriAI/litellm/issues/9733
                """)
            contents.append(ContentType(role="user", parts=[PartType(text=" ")]))
        return contents
    except Exception as e:
        raise e

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Fix the malformed message at the reported index.
  2. If the message looks valid, file an issue at the linked GitHub URL.

Example fix

# ensure each message has valid role/content structure.
Defensive patterns

Strategy: validation

When it happens

Trigger: Triggered when a message passed to the Vertex AI Gemini transformation has an invalid structure.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/280393fcefa8913a. Report an issue: GitHub.