Skip to content

The agent engineering platform.

fix(core): handle v1 base model validation in async path (#39576)

Hunter Lovell13b2f8d727f6
diff --git a/libs/core/langchain_core/tools/base.py b/libs/core/langchain_core/tools/base.py
index 56ea214518..89fe3c4509 100644
--- a/libs/core/langchain_core/tools/base.py
+++ b/libs/core/langchain_core/tools/base.py
@@ -1238,7 +1238,7 @@ class ChildTool(BaseTool):
error_to_raise = ValueError(msg)
else:
content = response
- except ValidationError as e:
+ except (ValidationError, ValidationErrorV1) as e:
if not self.handle_validation_error:
error_to_raise = e
else:
diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.py
index 28ec11af51..2aaf509c5a 100644
--- a/libs/core/tests/unit_tests/test_tools.py
+++ b/libs/core/tests/unit_tests/test_tools.py
@@ -1148,6 +1148,30 @@ async def test_async_validation_error_handling_callable() -> None:
assert expected == actual
+ sys.version_info >= (3, 14),
+ reason="pydantic.v1 namespace not supported with Python 3.14+",
+)
+async def test_async_validation_error_handling_pydantic_v1_schema() -> None:
+ """Test async validation error handling for Pydantic V1 schemas."""
+
+ class Args(BaseModelV1):
+ x: int
+
+ def foo(x: int) -> str:
+ """Return x as text."""
+ return str(x)
+
+ tool_ = StructuredTool.from_function(
+ foo,
+ args_schema=cast("ArgsSchema", Args),
+ handle_validation_error=True,
+ )
+
+ assert tool_.run({"x": "not-an-integer"}) == "Tool input validation error"
+ assert await tool_.arun({"x": "not-an-integer"}) == "Tool input validation error"
+
+
@pytest.mark.parametrize(
"handler",
[