Skip to content

Commit 4e41f61

Browse files
fix(openai): Check response text is present to avoid AttributeError
1 parent 2f966c6 commit 4e41f61

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sentry_sdk/integrations/openai.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ def _set_output_data(span, response, kwargs, integration, finish_span=True):
243243

244244
if hasattr(response, "choices"):
245245
if should_send_default_pii() and integration.include_prompts:
246-
response_text = [choice.message.model_dump() for choice in response.choices]
246+
response_text = [
247+
choice.message.model_dump()
248+
for choice in response.choices
249+
if choice.message is not None
250+
]
247251
if len(response_text) > 0:
248252
set_data_normalized(span, SPANDATA.GEN_AI_RESPONSE_TEXT, response_text)
249253

0 commit comments

Comments
 (0)