fix(core): prevent inherited docstrings for class-based tools #33540
+44
−25
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
This PR prevents class-based tools from inheriting the docstring of their parent class. When a child tool class does not have its own docstring, it was incorrectly using the parent's, leading to an inaccurate description for the tool.
This holistic fix modifies two files:
langchain_core/tools/base.py
: The_infer_arg_descriptions
function now correctly identifies an inherited docstring and returnsNone
to signal that it should be ignored.langchain_core/tools/structured.py
: TheStructuredTool.from_function
method now correctly handles thisNone
signal. It creates the tool with an empty string""
for its description, while still correctly raising an error for regular functions that are missing a docstring.This ensures that tools have accurate descriptions and that the developer experience is intuitive.
Issue
Fixes #32066
Dependencies
N/A