Skip to content

Fix docstring formatting and add safe check for empty message content #1360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2025

Conversation

mshsheikh
Copy link
Contributor

Improved clarity in a multiline docstring in RunItemBase by correcting misplaced parentheses.

Also added guards in ItemHelpers.extract_last_content and extract_last_text to handle empty message.content safely and prevent potential IndexError.

Improved clarity in a multiline docstring in `RunItemBase` by correcting misplaced parentheses.

Also added guards in `ItemHelpers.extract_last_content` and `extract_last_text` to handle empty `message.content` safely and prevent potential `IndexError`.
@seratch
Copy link
Member

seratch commented Aug 3, 2025

handle empty message.content

Have you observed this pattern in real use case?

@seratch seratch added documentation Improvements or additions to documentation feature:core labels Aug 3, 2025
@mshsheikh
Copy link
Contributor Author

handle empty message.content

Have you observed this pattern in real use case?

Yes @seratch , sometimes the model returns a control item with no text, so message.content can be completely empty and message.content[-1] would crash without the guard. This often happens in streaming mode when you’re piping partial results to a UI and no tokens have arrived yet.
It can also occur if the LLM makes a tool-only response or hands off right away without producing a normal message.

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this one should be safe to have plus it resolves potential runtime errors

@seratch seratch merged commit 907533a into openai:main Aug 3, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature:core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants