Skip to content

Pydantic model as FinalAnswer #1397

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

Closed
wants to merge 2 commits into from

Conversation

maxenceleguery
Copy link

Provide the possibility to specify a Pydantic model to constrain the final answer format.

Linked to issues #153 and #304

Tests :
Similar to the ones for FinalAnswerTool

NB : I added pydantic>=2.11.5 in the base dependencies in the pyproject.toml, maybe it is not the right place.

@maxenceleguery maxenceleguery marked this pull request as draft May 30, 2025 06:54
@maxenceleguery maxenceleguery marked this pull request as ready for review May 30, 2025 15:00
@albertvillanova
Copy link
Member

Hi @maxenceleguery,

If you just want to validate your final_answer, please note that we already have in place the final_answer_checks parameter: https://huggingface.co/docs/smolagents/reference/agents#smolagents.MultiStepAgent.final_answer_checks

final_answer_checks (`list`, *optional*): List of Callables to run before returning a final answer for checking validity.

If additionally, you would like to have an instance of BaseModel as final_answer, you can override the FinalAnswerTool and/or pass a custom final_answer tool to your model.

Please, let me know if you need some help in implementing any suggestions above.

@maxenceleguery
Copy link
Author

Oh, yes, you are right. I did not see I can achieve that with this parameter. Thanks for your answer !

@albertvillanova
Copy link
Member

I opened a PR to document better this parameter. 😉

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