Skip to content

The agent engineering platform.

Conditionally add pydantic v1 to namespace (#9202)

Eugene Yurtsev04bc5f3b1807
diff --git a/libs/langchain/langchain/__init__.py b/libs/langchain/langchain/__init__.py
index fe82bc343f..04f7e4cae9 100644
--- a/libs/langchain/langchain/__init__.py
+++ b/libs/langchain/langchain/__init__.py
@@ -21,7 +21,11 @@ try:
except ImportError:
pydantic_v1 = importlib.import_module("pydantic")
-sys.modules["pydantic_v1"] = pydantic_v1
+if "pydantic_v1" not in sys.modules:
+ # Use a conditional because langchain experimental
+ # will use the same strategy to add pydantic_v1 to sys.modules
+ # and may run prior to langchain core package.
+ sys.modules["pydantic_v1"] = pydantic_v1
from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain
from langchain.cache import BaseCache