Skip to content

Conversation

chahn
Copy link
Contributor

@chahn chahn commented Oct 17, 2025

Prevent stop-sequence trimming from crashing on tool-only GPT-5 outputs

Linked Issue

Fixes Bug #1825

Summary

  • Prevent remove_content_after_stop_sequences from crashing when a provider returns content=None (e.g. gpt-5 tool-only turns).
  • Ignore empty stop strings and tolerate a None stop list to avoid accidental truncation.

Details

  • Treat content=None and stop_sequences=None as no-op cases so we only trim when actual text is present.
  • Skip zero-length stop strings to keep the full generation intact when upstream configuration leaves empty entries.
  • This is enough to unblock the agent and any other flows relying on gpt-5 tool-calling without changing behavior for normal string outputs.

Tests

  • tests/test_models.py::test_remove_content_after_stop_sequences_handles_none – confirms the helper returns None when the provider emits tool-only output, mirroring the bug scenario.
  • tests/test_models.py::test_remove_content_after_stop_sequences_ignores_empty_stop_sequences – ensures harmless empty stop strings do not strip valid text.
  • tests/test_models.py::test_remove_content_after_stop_sequences_with_none_stop_sequences – protects the default code path where stop_sequences is None, preserving existing behavior.

Thanks a lot for feedback and support!

return content

for stop_seq in stop_sequences:
if not stop_seq:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why support having one of the stop sequences being None?
Apart from that I agree with the other introduced changes!

Copy link
Contributor Author

@chahn chahn Oct 23, 2025

Choose a reason for hiding this comment

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

Thanks for spotting that @aymeric-roucher! You’re right, we don’t expect providers to return None inside stop_sequences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: OpenAIModel raises AttributeError when gpt-5 returns tool-only response

2 participants