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
This commit is contained in:
Alvin Tang 2026-03-24 13:35:04 +08:00
parent 25ee2fb3f9
commit bfb7878cec

View file

@ -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: