From 7e54b252166701cd9498fc85544bfa8961078b6c Mon Sep 17 00:00:00 2001 From: Jonathan Hill Date: Mon, 18 May 2026 04:05:41 -0500 Subject: [PATCH] fix: guard against empty/filtered LLM responses in OpenAI client An empty choices list raises IndexError; a None message raises AttributeError. Add a null check before accessing choices[0].message. --- ufo/llm/openai.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ufo/llm/openai.py b/ufo/llm/openai.py index 613ee7b4..982d86d5 100644 --- a/ufo/llm/openai.py +++ b/ufo/llm/openai.py @@ -204,6 +204,8 @@ def _chat_completion( completion_tokens, ) + if not response.choices or response.choices[0].message is None: + raise ValueError("LLM returned empty or filtered response") return [response.choices[0].message.content], cost except openai.APITimeoutError as e: