BerriAI/litellm · error · ValueError

Message {i} must be a dictionary

Error message

Message {i} must be a dictionary

What it means

Error "Message {i} must be a dictionary" thrown in BerriAI/litellm.

Source

Thrown at litellm/llms/anthropic/count_tokens/transformation.py:101

        Args:
            model: The model name
            messages: The messages to count tokens for

        Raises:
            ValueError: If the request is invalid
        """
        if not model:
            raise ValueError("model parameter is required")

        if not messages:
            raise ValueError("messages parameter is required")

        if not isinstance(messages, list):
            raise ValueError("messages must be a list")

        for i, message in enumerate(messages):
            if not isinstance(message, dict):
                raise ValueError(f"Message {i} must be a dictionary")

            if "role" not in message:
                raise ValueError(f"Message {i} must have a 'role' field")

            if "content" not in message:
                raise ValueError(f"Message {i} must have a 'content' field")

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Pass each message as a dictionary.

When it happens

Trigger: Thrown at litellm/llms/anthropic/count_tokens/transformation.py:101 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/1bb583f1ef23a04e. Report an issue: GitHub.