Skip to content

Validate tool names returned by model against allowed tools#103

Merged
jph00 merged 5 commits intoAnswerDotAI:mainfrom
PiotrCzapla:main
Dec 19, 2025
Merged

Validate tool names returned by model against allowed tools#103
jph00 merged 5 commits intoAnswerDotAI:mainfrom
PiotrCzapla:main

Conversation

@PiotrCzapla
Copy link

@PiotrCzapla PiotrCzapla commented Dec 17, 2025

similar PR to AnswerDotAI/cosette#34

@gitnotebooks
Copy link

gitnotebooks bot commented Dec 17, 2025

Found 1 changed notebook. Review the changes at https://app.gitnotebooks.com/AnswerDotAI/claudette/pull/103

Adds safety mechanism to ensure only explicitly allowed tools can be executed. When a model attempts to call a tool not in the allowed set (via tools parameter or tool_choice), the call fails with an error message rather than executing arbitrary code.

Implements allowed_tools() to extract valid tool names from specs
Updates mk_toolres() to accept limit_to parameter for filtering
Modifies Chat.__call__() to validate tool calls automatically
@PiotrCzapla PiotrCzapla changed the title Protect against tool hallucination Validate tool names returned by model against allowed tools Dec 17, 2025
@PiotrCzapla PiotrCzapla marked this pull request as ready for review December 17, 2025 18:35
@RensDimmendaal
Copy link

RensDimmendaal commented Dec 18, 2025

Thanks @PiotrCzapla!

I like how you're returning the tool not found msg to the LLM so it can retry.

One thing, the nb does not run end2end for me. I think the case of no defined tools and no tools called is not handled?

image

@PiotrCzapla
Copy link
Author

@RensDimmendaal Thank you for noticing that! I've fixed the issue and added support to async, and cleaned toolloop notebook as it was throwing errors when run under nbdev_tests. Moreover I've noticed that my notebook get changes in many places when I run them in solve it, is it normal?

@PiotrCzapla
Copy link
Author

This PR is almost identical code to the one in Cosette, what would you think about moving allowed_tools and limit_ns to toolslm? I claudette, cosette and lisette?

@jph00
Copy link
Contributor

jph00 commented Dec 19, 2025

Thanks! :)

@jph00 jph00 merged commit 2b3af74 into AnswerDotAI:main Dec 19, 2025
@jph00 jph00 added the enhancement New feature or request label Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants