From 4e41f61b094019f992d21d762b8a0fa4d4806225 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Fri, 7 Nov 2025 12:35:01 +0100 Subject: [PATCH] fix(openai): Check response text is present to avoid AttributeError --- sentry_sdk/integrations/openai.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index bb93341f35..549b3504a6 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -243,7 +243,11 @@ def _set_output_data(span, response, kwargs, integration, finish_span=True): if hasattr(response, "choices"): if should_send_default_pii() and integration.include_prompts: - response_text = [choice.message.model_dump() for choice in response.choices] + response_text = [ + choice.message.model_dump() + for choice in response.choices + if choice.message is not None + ] if len(response_text) > 0: set_data_normalized(span, SPANDATA.GEN_AI_RESPONSE_TEXT, response_text)