mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-05 09:25:14 +03:00
fix(core): handle v1 base model validation in async path (#39576)
This commit is contained in:
1 parent
7fb045b744
commit
13b2f8d727
2 files changed
+25
-1
No files matched your search
@@ -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:
|
||||
|
||||
@@ -1148,6 +1148,30 @@ async def test_async_validation_error_handling_callable() -> None:
|
||||
assert expected == actual
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
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",
|
||||
[
|
||||
|
||||
Reference in new issue
Block a user