Skip to content

The agent engineering platform.

fix(core): allow base model annotations for empty model (#34932)

Akshaya Shanbhogue84864d77ed3b
diff --git a/libs/core/langchain_core/tools/base.py b/libs/core/langchain_core/tools/base.py
index 8eb2ba6643..b2c7b34bca 100644
--- a/libs/core/langchain_core/tools/base.py
+++ b/libs/core/langchain_core/tools/base.py
@@ -1488,7 +1488,7 @@ def get_all_basemodel_annotations(
for name, param in inspect.signature(cls).parameters.items():
# Exclude hidden init args added by pydantic Config. For example if
# BaseModel(extra="allow") then "extra_data" will part of init sig.
- if fields and name not in fields and name not in alias_map:
+ if name not in fields and name not in alias_map:
continue
field_name = alias_map.get(name, name)
annotations[field_name] = param.annotation
diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.py
index 0c49cfbef5..76506ae2a4 100644
--- a/libs/core/tests/unit_tests/test_tools.py
+++ b/libs/core/tests/unit_tests/test_tools.py
@@ -2150,12 +2150,17 @@ def test__get_all_basemodel_annotations_v2(*, use_v1_namespace: bool) -> None:
class ModelA(BaseModelV1, Generic[A], extra="allow"):
a: A
+ class EmptyModel(BaseModelV1, Generic[A], extra="allow"):
+ pass
else:
class ModelA(BaseModel, Generic[A]): # type: ignore[no-redef]
a: A
model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
+ class EmptyModel(BaseModel, Generic[A]): # type: ignore[no-redef]
+ model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
+
class ModelB(ModelA[str]):
b: Annotated[ModelA[dict[str, Any]], "foo"]
@@ -2205,6 +2210,10 @@ def test__get_all_basemodel_annotations_v2(*, use_v1_namespace: bool) -> None:
actual = get_all_basemodel_annotations(ModelD[int])
assert actual == expected
+ expected = {}
+ actual = get_all_basemodel_annotations(EmptyModel)
+ assert actual == expected
+
def test_get_all_basemodel_annotations_aliases() -> None:
class CalculatorInput(BaseModel):