From bfb7878cec12dd0e4cefbb0cb890773a17bd9fa4 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Tue, 24 Mar 2026 13:35:04 +0800 Subject: [PATCH] fix: guard against None text in Gemini image generation response parts When Gemini returns image generation responses, the parts array can contain a 'text' key whose value is null (JSON null). The code checked for key existence with 'if "text" in part' but did not guard against a null value, causing AttributeError: 'NoneType' object has no attribute 'startswith'. Add an explicit 'if text_content is None: continue' guard in both get_assistant_content_message() and _extract_audio_response_from_parts() immediately after reading part['text']. Fixes BerriAI/litellm#24385 --- .../vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py index 3f1bccaccfc..331cb8e16f4 100644 --- a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py +++ b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py @@ -1281,6 +1281,8 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): _content_str = "" if "text" in part: text_content = part["text"] + if text_content is None: + continue # Check if text content is audio data URI - if so, exclude from text content if text_content.startswith("data:audio") and ";base64," in text_content: try: @@ -1389,6 +1391,8 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): for part in parts: if "text" in part: text_content = part["text"] + if text_content is None: + continue # Check if text content contains audio data URI if text_content.startswith("data:audio") and ";base64," in text_content: try: