Skip to content

Conversation

cbornet
Copy link
Collaborator

@cbornet cbornet commented Aug 10, 2025

No description provided.

@cbornet cbornet requested a review from eyurtsev as a code owner August 10, 2025 14:12
Copy link

vercel bot commented Aug 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain Ignored Ignored Preview Sep 11, 2025 7:26pm

@@ -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

@@ -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.

Copy link

codspeed-hq bot commented Aug 10, 2025

CodSpeed WallTime Performance Report

Merging #32487 will not alter performance

Comparing cbornet:basetool-args (007162f) with master (c687965)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched

Copy link

codspeed-hq bot commented Aug 10, 2025

CodSpeed Instrumentation Performance Report

Merging #32487 will not alter performance

Comparing cbornet:basetool-args (007162f) with master (c687965)

Summary

✅ 14 untouched

@mdrxy mdrxy added the core Related to the package `langchain-core` label Aug 11, 2025
Copy link

@mishra-krishna mishra-krishna left a 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!

@cbornet cbornet requested a review from Copilot August 12, 2025 09:26
Copy link
Contributor

@Copilot Copilot AI left a 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 base BaseTool 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):
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.

@eyurtsev eyurtsev self-assigned this Sep 11, 2025
@eyurtsev eyurtsev merged commit 5fd7962 into langchain-ai:master Sep 11, 2025
266 of 273 checks passed
@eyurtsev
Copy link
Collaborator

Thank you @cbornet

@cbornet cbornet deleted the basetool-args branch September 11, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to the package `langchain-core`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants