-
Notifications
You must be signed in to change notification settings - Fork 18.9k
fix(core): fix support of Pydantic v1 models in BaseTool.args #32487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. |
@@ -1861,6 +1861,11 @@ def _run(self, *args: Any, **kwargs: Any) -> str: | |||
name="some_tool", description="some description", args_schema=pydantic_model | |||
) | |||
|
|||
assert tool.args == { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the fix in BaseTool.args
this fails
@@ -67,16 +67,6 @@ async def ainvoke( | |||
|
|||
# --- Tool --- | |||
|
|||
@property | |||
def args(self) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as parent class.
CodSpeed WallTime Performance ReportMerging #32487 will not alter performanceComparing
|
CodSpeed Instrumentation Performance ReportMerging #32487 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! This fix is important for maintaining compatibility with Pydantic v1. The code simplification in the subclasses is also a nice improvement. Thanks for the contribution!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes support for Pydantic v1 models in the BaseTool.args
property. The issue was that the property wasn't properly handling the schema generation for Pydantic v1 models, which use .schema()
instead of .model_json_schema()
.
Key Changes:
- Consolidates
args
property implementation in the baseBaseTool
class - Adds explicit handling for Pydantic v1 models using
BaseModelV1
type check - Removes duplicate implementations from child classes to use the unified base implementation
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
libs/core/langchain_core/tools/base.py |
Adds Pydantic v1 model support using BaseModelV1 check and .schema() method |
libs/core/langchain_core/tools/simple.py |
Removes duplicate args property logic, delegates to parent class |
libs/core/langchain_core/tools/structured.py |
Removes duplicate args property implementation entirely |
libs/core/tests/unit_tests/test_tools.py |
Adds test assertion to verify the args property returns expected schema |
@@ -543,6 +543,8 @@ def args(self) -> dict: | |||
""" | |||
if isinstance(self.args_schema, dict): | |||
json_schema = self.args_schema | |||
elif self.args_schema and issubclass(self.args_schema, BaseModelV1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BaseModelV1
type is referenced but not imported. This will cause a NameError at runtime when a Pydantic v1 model is used.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BaseModelV1 is imported.
Thank you @cbornet |
No description provided.