fix: validate tool args_schema before execution in native mode (#4495)#4507
fix: validate tool args_schema before execution in native mode (#4495)#4507amabito wants to merge 1 commit intocrewAIInc:mainfrom
Conversation
…IInc#4495) Native tool calling bypasses CrewStructuredTool.invoke()/_parse_args() and calls BaseTool.run() directly. When required arguments are missing, a raw TypeError is raised that the LLM cannot self-correct, causing deterministic retry loops. Add args_schema.model_validate() + model_dump() before tool_func() in _handle_native_tool_calls(). ValidationError now propagates to the existing outer exception handler, surfacing actionable feedback to the LLM. No new imports, no signature changes.
|
@jonas-cohen-verbit FYI — PR is up. If you can test this branch against your setup, that would be super helpful. It validates |
|
Closing this in favor of #4518, which fixes the actual root cause at L722. The The Pydantic validation approach in this PR (filling schema defaults, normalizing args) is a reasonable defensive improvement in its own right — happy to reopen or submit a separate PR for it if the team finds it useful. Thanks for the patience while we narrowed down the root cause. |
Summary
Native tool calling mode bypasses
CrewStructuredTool.invoke()/_parse_args()and callsBaseTool.run()directly viaavailable_functions. When required arguments are missing, this produces a rawTypeErrorthat can trigger deterministic retry loops.Fix
Validate
args_dictagainst the matched tool'sargs_schemabefore execution in_handle_native_tool_calls().Missing or invalid arguments now raise
ValidationError, which is handled by the existing outer exception block.Native mode now normalizes arguments via Pydantic (including filling schema defaults), which aligns behavior with the ReAct path.
Scope
Tests
Closes #4495
Note
Low Risk
Small, localized change to the native tool execution path with added tests; main risk is minor behavior change in how invalid tool args are surfaced.
Overview
Native tool calling now validates the parsed
args_dictagainst the matched tool’s Pydanticargs_schemabefore invoking the tool function, normalizing defaults and turning missing/invalid args into handled validation errors instead of rawTypeErrors.Adds regression tests that reproduce the missing-required-arg scenario in native mode (ensuring
_runis not called and a validation-style error is returned) and a sanity check that valid arguments still execute successfully.Written by Cursor Bugbot for commit cc3ffb6. This will update automatically on new commits. Configure here.