From fecbef01400c632ddf338b92bcec5e1cc85e2d53 Mon Sep 17 00:00:00 2001 From: Jonathan Hill Date: Mon, 18 May 2026 03:42:26 -0500 Subject: [PATCH] fix: guard against None message before accessing .content The existing guards check response.choices[0].message.content but if message itself is None (returned by some providers on content-filtered responses with HTTP 200), this crashes with AttributeError before the guard can fire. Extend both guard conditions to check message is None first. --- app/llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/llm.py b/app/llm.py index 82ebe8857..726bdc309 100644 --- a/app/llm.py +++ b/app/llm.py @@ -422,7 +422,7 @@ async def ask( **params, stream=False ) - if not response.choices or not response.choices[0].message.content: + if not response.choices or response.choices[0].message is None or not response.choices[0].message.content: raise ValueError("Empty or invalid response from LLM") # Update token counts @@ -592,7 +592,7 @@ async def ask_with_images( if not stream: response = await self.client.chat.completions.create(**params) - if not response.choices or not response.choices[0].message.content: + if not response.choices or response.choices[0].message is None or not response.choices[0].message.content: raise ValueError("Empty or invalid response from LLM") self.update_token_count(response.usage.prompt_tokens)