litellm/tests/unit/llms/vertex_ai/gemini
ryan-crabbe-berri b86683679b
fix(vertex_ai): fail Gemini malformed replies with no output so retries and fallbacks run (#53231)
* test(vertex_ai): cover Gemini malformed replies with no output

A non-streaming Gemini reply that ends in MALFORMED_FUNCTION_CALL or MALFORMED_RESPONSE with no output comes back as a 200 stop with empty content, so retries and fallbacks never run. These tests expect a retriable 500 on chat completions, messages and responses, a fallback to the backup model, and billed tokens on the failure log, while replies with any output keep their 200.

* fix(vertex_ai): fail Gemini malformed replies with no output so retries run

When every Gemini candidate ends in MALFORMED_FUNCTION_CALL or MALFORMED_RESPONSE with no text, tool call, image or audio, raise a 500 that names the finish reason instead of returning a 200 stop with empty content. The failure log keeps the tokens Google billed. Replies with any output keep today's shape.

* fix(vertex_ai): keep Gemini pass-through spend logs and bill the failed attempt like other 200 errors

The malformed check now runs only on the live completion path, so the Gemini and Vertex pass-through loggers still bill a malformed reply instead of failing to log it. The failed attempt is recorded the same way OpenRouter records an error inside a 200, so a later retry or fallback can carry it. Tests now cover image, audio and legacy function-call output, the pass-through spend, and a smaller integration matrix on gemini-4-carbon.

* fix(vertex_ai): type the native finish reason read in the Gemini malformed check

* refactor(vertex_ai): return the Gemini malformed failure as a value and raise it at the request boundary

* fix(vertex_ai): keep token counts out of the Gemini malformed error so it is never remapped to a client error

The Vertex error mapper reads a bare 403 in the message as a permission error, so a reply that billed exactly 403 tokens would have skipped retries. The billed tokens stay on the spend log.
2026-11-21 09:49:27 -08:00
..
__init__.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_context_circulation.py refactor(llms): expose public names for private provider helpers (#45037) 2026-10-07 08:49:25 -07:00
test_function_call_args_serialization.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_gemini_image_url_missing_field.py refactor(llms): expose public names for private provider helpers (#45037) 2026-10-07 08:49:25 -07:00
test_gemini_streaming_tool_call_finish_reason.py fix(vertex_ai): fail a Gemini stream cut before its finish reason (#53187) 2026-11-20 16:25:15 -08:00
test_grounding_requests.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_long_decode.py fix(gemini): keep Google's reason on streamed chunks and the assembled response (#52242) 2026-11-17 16:01:46 -08:00
test_rejected_thought_signature_retry.py fix(gemini): resend once with the placeholder signature when the other backend rejects a replayed thought signature (#49697) 2026-11-03 01:24:55 +00:00
test_thought_signature_in_tool_call_id.py fix(gemini): stop replaying a client-mangled thought signature from a tool call id (#52207) 2026-11-16 21:39:16 -08:00
test_tool_call_followed_by_text_assistant.py refactor(llms): expose public names for private provider helpers (#45037) 2026-10-07 08:49:25 -07:00
test_transformation.py fix(gemini): match tool results to calls split across assistant turns (#52960) 2026-11-20 11:18:15 -08:00
test_vertex_ai_gemini_transformation.py fix(gemini): preserve distinct parallel tool calls with identical arguments (#53233) 2026-11-20 17:01:46 -08:00
test_vertex_and_google_ai_studio_gemini.py fix(vertex_ai): fail Gemini malformed replies with no output so retries and fallbacks run (#53231) 2026-11-21 09:49:27 -08:00
test_vertex_gemini_unbound_local_error.py refactor(llms): expose public names for private provider helpers (#45037) 2026-10-07 08:49:25 -07:00