fix(ai): skip validation for provider-executed dynamic tools in v5 #10890
+38
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Backport of #10734 to the v5.0 release branch.
Problem
Provider-executed dynamic tools (like Claude Code's built-in Bash tool) are being incorrectly validated in
parseToolCall, causing them to be marked asinvalid: trueeven though they execute successfully on the provider side.This results in error messages being sent back to the model:
The model then gets confused and apologizes for tools it just successfully used.
Root Cause
The
parseToolCallfunction validates ALL tool calls against the user's tools map, without checking if the tool hasproviderExecuted: true. Provider-executed tools aren't in the user's tools map because they're managed by the provider, not the application.Solution
Add checks for
toolCall.providerExecuted && toolCall.dynamicbefore attempting validation in two places:tools == null(line 31-33)If both flags are true, call
parseProviderExecutedDynamicToolCallto handle the tool call without validation.Testing
Tested with ai-sdk-provider-claude-code v2.2.3. Before fix:
invalid: trueAfter fix:
providerExecuted: trueRelated Issues
Checklist
parseProviderExecutedDynamicToolCallhelper functionDynamicToolCalltype