fix(core): preserve injected arguments when args_schema is BaseModel #33649
+9
−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
Fixes #33646
When using the
@tooldecorator withargs_schemaset to a Pydantic BaseModel, injected parameters likeToolRuntimewere being filtered out during input parsing, causing aTypeError: missing 1 required positional argument: 'runtime'.Problem
The
_parse_input()method inbase.pywas only returning fields that were both:This caused injected arguments like
ToolRuntimeto be discarded, even though they were needed by the tool function.Solution
Modified
_parse_input()to preserve all fields from the originaltool_input, not just those defined in the schema. After validating schema-defined fields, the method now adds back any additional fields that were in the original input. This ensures injected arguments are passed through to the tool function.Before (Broken):
After (Fixed):
Changes
langchain_core/tools/base.py_parse_input()method (lines 97-106)Testing
Manual testing performed with the following scenarios:
✅ Tool with BaseModel + ToolRuntime (previously failed, now works)
ToolRuntimeis correctly passed to the function✅ Tool without BaseModel + ToolRuntime (regression test - still works)
Annotatedtypes✅ Tool with BaseModel but no injected arguments*(regression test - still works)
All tests pass successfully with the fix applied.
Issue
Fixes #33646
Dependencies
None - this is a bug fix using existing functionality.