BerriAI/litellm · error · ValueError

Invalid completion response: no message found in choice

Error message

Invalid completion response: no message found in choice

What it means

Transform guard in translate_completion_to_generate_content: the first choice exists but carries no message object, so the adapter cannot extract content to build the generate_content response.

Solutions

  1. The completion response choice contained no message; retry the request or check the provider response.
  2. Verify the model supports the requested generation and returns a message payload.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/google_genai/adapters/transformation.py:498 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at litellm/google_genai/adapters/transformation.py:498

        """
        Transform litellm completion response to Google GenAI generate_content format

        Args:
            response: ModelResponse from litellm.completion

        Returns:
            Dict in Google GenAI generate_content response format
        """

        # Extract the main response content
        choice: Final = response.choices[0] if response.choices else None
        if not choice:
            raise ValueError("Invalid completion response: no choices found")

        # Handle different choice types (Choices vs StreamingChoices)
        if isinstance(choice, Choices):
            if not choice.message:
                raise ValueError("Invalid completion response: no message found in choice")
            parts = self._transform_openai_message_to_google_genai_parts(choice.message)
        else:
            # Fallback for generic choice objects
            message_content = getattr(choice, "message", {}).get("content", "") or getattr(choice, "delta", {}).get(
                "content", ""
            )
            parts = [{"text": message_content}] if message_content else []

        # Create Google GenAI format response
        generate_content_response: Final[dict[str, object]] = {
            "candidates": [
                {
                    "content": {"parts": parts, "role": "model"},
                    "finishReason": self._map_finish_reason(getattr(choice, "finish_reason", None)),
                    "index": 0,
                    "safetyRatings": [],
                }
            ],

View on GitHub (pinned to 77b7c6c40c)