From edf4b885ba5148397540bbe8ae9abd20b2dfadfd Mon Sep 17 00:00:00 2001 From: Rishab Motgi Date: Mon, 18 May 2026 14:09:43 -0700 Subject: [PATCH] fix(streaming): guard raise_on_model_repetition against empty choices chunks Vertex Gemini Flash/Flash Lite with web_search_options emits metadata-only chunks that have choices=[]. These are appended to self.chunks normally, but raise_on_model_repetition unconditionally accesses choices[0] on the last two chunks, raising IndexError on any such metadata chunk. Add an early return when either of the two compared chunks has no choices. The repetition check is meaningless for content-less chunks anyway. --- litellm/litellm_core_utils/streaming_handler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.py index fa7faf3035d..2956db122d5 100644 --- a/litellm/litellm_core_utils/streaming_handler.py +++ b/litellm/litellm_core_utils/streaming_handler.py @@ -269,6 +269,9 @@ class CustomStreamWrapper: if len(self.chunks) < 2: return + if not self.chunks[-1].choices or not self.chunks[-2].choices: + return + last_content = self.chunks[-1].choices[0].delta.content if (