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)