Commit 08ab62b9

Rohit Joshi <891456+rjoshi@users.noreply.github.com>
2025-01-16 20:46:22
fix(structured outputs): avoid parsing empty empty content (#2023)
Fixing https://github.com/openai/openai-python/issues/1763 where parsing often fails when content is empty string instead of None.
1 parent bf5bebb
Changed files (1)
src
openai
lib
src/openai/lib/_parsing/_completions.py
@@ -157,7 +157,7 @@ def maybe_parse_content(
     response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
     message: ChatCompletionMessage | ParsedChatCompletionMessage[object],
 ) -> ResponseFormatT | None:
-    if has_rich_response_format(response_format) and message.content is not None and not message.refusal:
+    if has_rich_response_format(response_format) and message.content and not message.refusal:
         return _parse_content(response_format, message.content)
 
     return None