fix: prevent FinalAnswerException from being caught by except Exception by majiayu000 · Pull Request #1914 · huggingface/smolagents (original) (raw)

Skip to content

Sign in

Appearance settings

View all features

View all solutions

View all resources

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Sign in

Sign up

Appearance settings

huggingface / smolagents Public

Additional navigation options

Merged

aymeric-roucher merged 1 commit intohuggingface:mainfrom

majiayu000:fix/final-answer-exception-inheritance

Dec 23, 2025

ConversationCommits (1)ChecksFiles changed

Merged

fix: prevent FinalAnswerException from being caught by except Exception#1914

aymeric-roucher merged 1 commit intohuggingface:mainfrom

majiayu000:fix/final-answer-exception-inheritance

Conversation

@majiayu000

Copy link Copy Markdown

Contributor

@majiayu000 majiayu000 commented

Dec 23, 2025

Summary

Test plan

Fixes #1905

aymeric-roucher reacted with heart emoji

@majiayu000

`` [fix: prevent FinalAnswerException from being caught by except Exception](/huggingface/smolagents/pull/1914/commits/fac55deb022edbfca75ccb2e261cc2b41224ce8d "fix: prevent FinalAnswerException from being caught by except Exception

FinalAnswerException now inherits from BaseException instead of Exception to prevent agent-generated code with try/except Exception blocks from incorrectly catching the exception when final_answer() is called.

Fixes #1905") ``

[fac55de](/huggingface/smolagents/pull/1914/commits/fac55deb022edbfca75ccb2e261cc2b41224ce8d)

FinalAnswerException now inherits from BaseException instead of Exception to prevent agent-generated code with try/except Exception blocks from incorrectly catching the exception when final_answer() is called.

Fixes huggingface#1905

aymeric-roucher

aymeric-roucher approved these changes Dec 23, 2025

View reviewed changes

Copy link Copy Markdown

Collaborator

@aymeric-roucher aymeric-roucher left a comment

Choose a reason for hiding this comment

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

Thank you!

@aymeric-roucher aymeric-roucher merged commit 1af0799 into huggingface:main

Dec 23, 2025

3 checks passed

@majiayu000

Copy link Copy Markdown

Contributor Author

majiayu000 commented

Dec 23, 2025

Happy to help!

aymeric-roucher reacted with hooray emoji

@majiayu000 majiayu000 deleted the fix/final-answer-exception-inheritance branch

December 23, 2025 09:56

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

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

Reviewers

@aymeric-roucher aymeric-roucher aymeric-roucher approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

BUG: Agent code should not be able to catch FinalAnswerException

2 participants

@majiayu000 @aymeric-roucher