From a565cf85eb6792d8d0848224a2a2c3d5bdf97eee Mon Sep 17 00:00:00 2001 From: KarthikRed2000 Date: Tue, 17 Feb 2026 16:47:17 -0600 Subject: [PATCH] fix(core): prevent recursion error when args_schema is dict (#35260) --- libs/core/langchain_core/tools/base.py | 3 ++- libs/core/tests/unit_tests/test_tools.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/core/langchain_core/tools/base.py b/libs/core/langchain_core/tools/base.py index fa3df6d3970..7026a2e8fb1 100644 --- a/libs/core/langchain_core/tools/base.py +++ b/libs/core/langchain_core/tools/base.py @@ -819,7 +819,8 @@ class ChildTool(BaseTool): filtered_keys.update(self._injected_args_keys) # If we have an args_schema, use it to identify injected args - if self.args_schema is not None: + # Skip if args_schema is a dict (JSON Schema) as it's not a Pydantic model + if self.args_schema is not None and not isinstance(self.args_schema, dict): try: annotations = get_all_basemodel_annotations(self.args_schema) for field_name, field_type in annotations.items(): diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.py index 5c1144ac221..1067ecfa690 100644 --- a/libs/core/tests/unit_tests/test_tools.py +++ b/libs/core/tests/unit_tests/test_tools.py @@ -2,6 +2,7 @@ import inspect import json +import logging import sys import textwrap import threading @@ -2632,7 +2633,8 @@ def test_tool_mutate_input() -> None: assert my_input == {"x": "hi"} -def test_structured_tool_args_schema_dict() -> None: +def test_structured_tool_args_schema_dict(caplog: pytest.LogCaptureFixture) -> None: + caplog.set_level(logging.DEBUG) args_schema = { "properties": { "a": {"title": "A", "type": "integer"}, @@ -2666,6 +2668,8 @@ def test_structured_tool_args_schema_dict() -> None: "a": {"title": "A", "type": "integer"}, "b": {"title": "B", "type": "integer"}, } + # test that we didn't log an error about failing to get args_schema annotations + assert "Failed to get args_schema annotations for filtering" not in caplog.text def test_simple_tool_args_schema_dict() -> None: