From b990045a40bc16be82bbcda07f97791739b6142c Mon Sep 17 00:00:00 2001 From: Jonathan Hill Date: Mon, 18 May 2026 04:15:54 -0500 Subject: [PATCH] fix: guard against empty/filtered LLM responses in eval_function An empty choices list raises IndexError; a None message raises AttributeError. Add a null check before accessing choices[0].message. --- examples/customer_service_streaming/src/evals/eval_function.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/customer_service_streaming/src/evals/eval_function.py b/examples/customer_service_streaming/src/evals/eval_function.py index 1149a18c7..fa750ec9b 100644 --- a/examples/customer_service_streaming/src/evals/eval_function.py +++ b/examples/customer_service_streaming/src/evals/eval_function.py @@ -52,6 +52,8 @@ def name(self): }, {"role": "user", "content": f"SENTENCE:\n{response}"}] ) + if not completion_result.choices or completion_result.choices[0].message is None: + raise ValueError("LLM returned empty or filtered response") name_extract = completion_result.choices[0].message.content print(f"Name extracted: {name_extract}") try: