{"record":{"id":"e3464b5af79e634f","repo":"BerriAI/litellm","slug":"invalid-completion-response-no-message-found-in-c","errorCode":null,"errorMessage":"Invalid completion response: no message found in choice","messagePattern":"Invalid completion response: no message found in choice","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/google_genai/adapters/transformation.py","lineNumber":498,"sourceCode":"        \"\"\"\n        Transform litellm completion response to Google GenAI generate_content format\n\n        Args:\n            response: ModelResponse from litellm.completion\n\n        Returns:\n            Dict in Google GenAI generate_content response format\n        \"\"\"\n\n        # Extract the main response content\n        choice: Final = response.choices[0] if response.choices else None\n        if not choice:\n            raise ValueError(\"Invalid completion response: no choices found\")\n\n        # Handle different choice types (Choices vs StreamingChoices)\n        if isinstance(choice, Choices):\n            if not choice.message:\n                raise ValueError(\"Invalid completion response: no message found in choice\")\n            parts = self._transform_openai_message_to_google_genai_parts(choice.message)\n        else:\n            # Fallback for generic choice objects\n            message_content = getattr(choice, \"message\", {}).get(\"content\", \"\") or getattr(choice, \"delta\", {}).get(\n                \"content\", \"\"\n            )\n            parts = [{\"text\": message_content}] if message_content else []\n\n        # Create Google GenAI format response\n        generate_content_response: Final[dict[str, object]] = {\n            \"candidates\": [\n                {\n                    \"content\": {\"parts\": parts, \"role\": \"model\"},\n                    \"finishReason\": self._map_finish_reason(getattr(choice, \"finish_reason\", None)),\n                    \"index\": 0,\n                    \"safetyRatings\": [],\n                }\n            ],","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/google_genai/adapters/transformation.py#L480-L516","documentation":"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.","triggerScenarios":"Thrown at litellm/google_genai/adapters/transformation.py:498 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The completion response choice contained no message; retry the request or check the provider response.","Verify the model supports the requested generation and returns a message payload."],"exampleFix":null,"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-23T08:17:48.524Z"}