Skip to content

Validate tool names returned by model against allowed tools#34

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

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

Conversation

@PiotrCzapla
Copy link

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

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
@gitnotebooks
Copy link

gitnotebooks bot commented Dec 17, 2025

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

- We use the same approach as claudette that uses limit_ns and relies on toolslm.func_call to throw KeyError
- Improved mk_tool_choice let user select "none", and if None is provided returns NOT_GIVEN istead of None.
This fixes with openrouter that gives 400 when tool_choice is null.
- Test were failing as we use `models[1]` to get the model name, which become `gpt-5.2-pro`.
@jph00
Copy link
Contributor

jph00 commented Dec 19, 2025

Super!

@jph00 jph00 merged commit ff9c5b9 into AnswerDotAI:main Dec 19, 2025
@jph00 jph00 added the enhancement New feature or request label Dec 19, 2025
@jph00
Copy link
Contributor

jph00 commented Dec 19, 2025

BTW @PiotrCzapla add enhancement or bug label to PRs to ensure they end up in release notes. (I've added them now.)

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.

2 participants