Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libs/core/langchain_core/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Preview

Copilot AI Aug 12, 2025

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BaseModelV1 is imported.

json_schema = self.args_schema.schema()
else:
input_schema = self.get_input_schema()
json_schema = input_schema.model_json_schema()
Expand Down
6 changes: 1 addition & 5 deletions libs/core/langchain_core/tools/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ def args(self) -> dict:
The input arguments for the tool.
"""
if self.args_schema is not None:
if isinstance(self.args_schema, dict):
json_schema = self.args_schema
else:
json_schema = self.args_schema.model_json_schema()
return json_schema["properties"]
return super().args
# For backwards compatibility, if the function signature is ambiguous,
# assume it takes a single string input.
return {"tool_input": {"type": "string"}}
Expand Down
10 changes: 0 additions & 10 deletions libs/core/langchain_core/tools/structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ async def ainvoke(

# --- Tool ---

@property
def args(self) -> dict:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as parent class.

"""The tool's input arguments."""
if isinstance(self.args_schema, dict):
json_schema = self.args_schema
else:
input_schema = self.get_input_schema()
json_schema = input_schema.model_json_schema()
return json_schema["properties"]

def _run(
self,
*args: Any,
Expand Down
5 changes: 5 additions & 0 deletions libs/core/tests/unit_tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == {
Copy link
Collaborator Author

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

"a": {"title": "A", "type": "integer"},
"b": {"title": "B", "type": "string"},
}

input_schema = tool.get_input_schema()
if issubclass(input_schema, BaseModel):
input_json_schema = input_schema.model_json_schema()
Expand Down