From 960108939d7bbebfb9cf56d485484cbc7c3a260d Mon Sep 17 00:00:00 2001 From: Chesars Date: Sun, 22 Mar 2026 01:01:00 -0300 Subject: [PATCH] fix: update EmbeddingInput type, validate nested sub-elements, add tests --- .../batch_embed_content_transformation.py | 7 +++++++ litellm/types/llms/openai.py | 2 +- .../test_batch_embed_content_transformation.py | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py index 5777948c4f6..66ff9ef987c 100644 --- a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py +++ b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py @@ -216,6 +216,13 @@ def transform_openai_input_gemini_content( for element in input_list: if isinstance(element, list): + if not element: + raise ValueError("Nested input list must not be empty") + for sub in element: + if not isinstance(sub, str): + raise ValueError( + f"Elements inside a nested input list must be strings, got {type(sub)}" + ) parts = [ _build_part_for_input(sub, resolved_files=resolved_files) for sub in element diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.py index 5a80b40d61f..79bfe73d12e 100644 --- a/litellm/types/llms/openai.py +++ b/litellm/types/llms/openai.py @@ -103,7 +103,7 @@ FileTypes = Union[ ] -EmbeddingInput = Union[str, List[str]] +EmbeddingInput = Union[str, List[Union[str, List[str]]]] class HttpxBinaryResponseContent(_HttpxBinaryResponseContent): diff --git a/tests/test_litellm/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_transformation.py b/tests/test_litellm/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_transformation.py index 98b2c0167af..7e757e32e0e 100644 --- a/tests/test_litellm/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_transformation.py +++ b/tests/test_litellm/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_transformation.py @@ -44,6 +44,12 @@ class TestIsMultimodalInput: def test_mixed_text_and_image(self): assert _is_multimodal_input(["hello", IMAGE_DATA_URI]) is True + def test_nested_list_is_multimodal(self): + assert _is_multimodal_input([["text_a", "text_b"]]) is True + + def test_nested_list_with_image_is_multimodal(self): + assert _is_multimodal_input([["a red shoe", IMAGE_DATA_URI]]) is True + class TestBuildPartForInput: def test_text_input(self):