Skip to content

Comments

fix: validate tool args_schema before execution in native mode (#4495)#4507

Closed
amabito wants to merge 1 commit intocrewAIInc:mainfrom
amabito:fix/native-args-schema-validation-4495
Closed

fix: validate tool args_schema before execution in native mode (#4495)#4507
amabito wants to merge 1 commit intocrewAIInc:mainfrom
amabito:fix/native-args-schema-validation-4495

Conversation

@amabito
Copy link

@amabito amabito commented Feb 17, 2026

Summary

Native tool calling mode bypasses CrewStructuredTool.invoke() / _parse_args() and calls BaseTool.run() directly via available_functions. When required arguments are missing, this produces a raw TypeError that can trigger deterministic retry loops.

Fix

Validate args_dict against the matched tool's args_schema before execution in _handle_native_tool_calls().

if original_tool and getattr(original_tool, "args_schema", None):
    validated = original_tool.args_schema.model_validate(args_dict)
    args_dict = validated.model_dump()

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

  • Minimal change limited to native tool-calling path
  • No changes to ReAct path
  • No signature changes
  • No new imports
  • Backward compatible

Tests

  • Added regression tests covering missing required args
  • Verified valid args still execute correctly

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_dict against the matched tool’s Pydantic args_schema before invoking the tool function, normalizing defaults and turning missing/invalid args into handled validation errors instead of raw TypeErrors.

Adds regression tests that reproduce the missing-required-arg scenario in native mode (ensuring _run is 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.

…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.
@amabito
Copy link
Author

amabito commented Feb 17, 2026

@jonas-cohen-verbit FYI — PR is up. If you can test this branch against your setup, that would be super helpful.

It validates args_dict against args_schema in native tool calling before executing tool.run(), which prevents missing-required-arg TypeErrors and aligns native behavior with the structured/ReAct path.

@amabito
Copy link
Author

amabito commented Feb 20, 2026

Closing this in favor of #4518, which fixes the actual root cause at L722.

The args_dict being empty was not due to missing validation, but because func_info.get("arguments", "{}") or tool_call.get("input", {}) short-circuits on the truthy default "{}", so Bedrock's input key is never evaluated. #4518 addresses that directly with a one-line fix.

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.

@amabito amabito closed this Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant