Fixed InjectedToolArg filtering bypassed when filter_args provided#36064
Closed
Tim Ren (xr843) wants to merge 1 commit intolangchain-ai:masterfrom
Closed
Fixed InjectedToolArg filtering bypassed when filter_args provided#36064Tim Ren (xr843) wants to merge 1 commit intolangchain-ai:masterfrom
Tim Ren (xr843) wants to merge 1 commit intolangchain-ai:masterfrom
Conversation
The injected-arg filtering logic was nested inside the `else` branch of `if filter_args:`, so providing filter_args alongside include_injected=False caused InjectedToolArg-annotated parameters to leak into the generated JSON schema. This moves the filtering outside the if/else so it always runs, and copies filter_args to a local list to avoid mutating the caller's sequence. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
This PR has been automatically closed because you are not assigned to the linked issue. External contributors must be assigned to an issue before opening a PR for it. Please:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #35831
filter_argsis provided alongsideinclude_injected=Falseincreate_schema_from_function, theInjectedToolArg-annotated parameter filtering is skipped entirely. This causes parameters meant to be hidden from the LLM (e.g., API keys, internal state) to leak into the generated JSON schema.elsebranch ofif filter_args:, so it only ran whenfilter_argswas not provided.InjectedToolArgfiltering outside theif/elseblock so it always runs regardless of whetherfilter_argswas provided. Also copiesfilter_argsto a local list to avoid mutating the caller's sequence.Security implications
This is a security-relevant fix.
InjectedToolArgis commonly used to annotate sensitive parameters (API keys, tokens, internal state) that should never be exposed in the tool schema sent to an LLM. The bug caused these parameters to leak into the schema whenfilter_argswas explicitly provided.Test plan
test_create_schema_injected_arg_filtered_with_filter_argsthat verifies:InjectedToolArg-annotated parameters are excluded from the schema even whenfilter_argsis providedfilter_argssequence is not mutated🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com