From 94c2db996a6807e0a1e133de7b26a88159b5cafc Mon Sep 17 00:00:00 2001 From: prophet_system_team Date: Mon, 23 Mar 2026 23:55:12 +0530 Subject: [PATCH] fix(vertex_ai): narrow field transformation to contents and systemInstruction - Restrict recursive camelCase transformation to 'contents' and 'system_instruction' chunks to avoid breaking existing snake_case top-level fields (e.g. in generationConfig or extra_body). - Rename 'system_instruction' to 'systemInstruction' for Vertex AI REST API compliance. - Update context caching transformation with the same narrowed logic. --- .../vertex_ai/context_caching/transformation.py | 13 ++++++++++--- litellm/llms/vertex_ai/gemini/transformation.py | 11 ++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/litellm/llms/vertex_ai/context_caching/transformation.py b/litellm/llms/vertex_ai/context_caching/transformation.py index c315643ac72..bbc96522e59 100644 --- a/litellm/llms/vertex_ai/context_caching/transformation.py +++ b/litellm/llms/vertex_ai/context_caching/transformation.py @@ -14,6 +14,7 @@ from litellm.utils import is_cached_message from ..common_utils import get_supports_system_message from ..gemini.transformation import ( _gemini_convert_messages_with_history, + _transform_part_to_httpx_format, _transform_system_message, ) @@ -198,8 +199,14 @@ def transform_openai_messages_to_gemini_context_caching( data["system_instruction"] = transformed_system_messages if is_vertex_ai: - from ..gemini.transformation import _transform_part_to_httpx_format - - return _transform_part_to_httpx_format(data) # type: ignore + if "contents" in data: + data["contents"] = _transform_part_to_httpx_format( + {"contents": data["contents"]}, parent_key=None + )["contents"] + if "system_instruction" in data: + data["systemInstruction"] = _transform_part_to_httpx_format( + {"system_instruction": data["system_instruction"]}, parent_key=None + )["systemInstruction"] + del data["system_instruction"] return data diff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.py index c32ac29e9cd..db1024a6751 100644 --- a/litellm/llms/vertex_ai/gemini/transformation.py +++ b/litellm/llms/vertex_ai/gemini/transformation.py @@ -827,7 +827,16 @@ def _transform_request_body( # noqa: PLR0915 raise e if custom_llm_provider in ["vertex_ai", "vertex_ai_beta"]: - return _transform_part_to_httpx_format(data) # type: ignore + if "contents" in data: + data["contents"] = _transform_part_to_httpx_format( + {"contents": data["contents"]}, parent_key=None + )["contents"] + if "system_instruction" in data: + data["systemInstruction"] = _transform_part_to_httpx_format( + {"system_instruction": data["system_instruction"]}, parent_key=None + )["systemInstruction"] + del data["system_instruction"] + return data