Skip to content

Cut generation at stop sequence post generation - #1802

Merged
aymeric-roucher merged 8 commits into
mainfrom
cut-generation-at-stop-sequence-a-posteriori
Oct 13, 2025
Merged

aymeric-roucher merged 8 commits into
mainfrom
cut-generation-at-stop-sequence-a-posteriori

Conversation

@aymeric-roucher

@aymeric-roucher aymeric-roucher commented Oct 9, 2025 •

Copy link
Copy Markdown
Collaborator

When models don't support stop sequences, we currently just omit passing them a parameter stop sequence.
For tool calling mode, this generally isn't a problem because models are trained to end generation after generating their tool call.

But for code mode, this creates an issue where the model generates the stop sequence like </code>, and then keeps generating nonsense, eventually hallucinating its way into failure to solve the user task.

This PR fixes this for the .generate() method by removing anything after a stop sequence post-generation.

@albertvillanova albertvillanova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Just some suggested improvements below.

Comment thread src/smolagents/models.py Resolved
Comment thread src/smolagents/models.py Resolved
@aymeric-roucher
aymeric-roucher merged commit 67b15ae into main Oct 13, 2025
4 checks passed
maxwellfet928 pushed a commit to maxwellfet928/smolagents that referenced this pull request Jun 8, 2026
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.

2 participants