How to fix LangChain deprecated import langchain.tools
Quick answer
The
langchain.tools import is deprecated due to LangChain's modular restructuring. Replace from langchain.tools import X with the new explicit imports like from langchain.tools.base import X or the specific submodule path to fix import errors. ERROR TYPE
code_error ⚡ QUICK FIX
Update your imports to use explicit submodule paths such as
from langchain.tools.base import Tool instead of the deprecated from langchain.tools import Tool.Why this happens
LangChain has restructured its package layout to improve modularity and reduce import bloat. The previous import style from langchain.tools import Tool is deprecated and triggers import errors or warnings. For example, code like:
from langchain.tools import Tool
my_tool = Tool()now raises ImportError or deprecation warnings because langchain.tools is no longer a flat namespace but split into submodules.
from langchain.tools import Tool
my_tool = Tool() output
ImportError: cannot import name 'Tool' from 'langchain.tools'
The fix
Use explicit imports from the new submodules under langchain.tools. For example, import Tool from langchain.tools.base:
from langchain.tools.base import Tool
my_tool = Tool() output
No import errors; Tool instance created successfully
Preventing it in production
Keep your LangChain dependencies updated and monitor the official changelog for breaking changes. Use static type checking and automated tests to catch import errors early. Consider pinning LangChain versions and testing upgrades in staging before production rollout.
Key Takeaways
- LangChain deprecated flat imports from langchain.tools; use explicit submodule imports.
- Update your code to import tools from their specific submodules like langchain.tools.base.
- Regularly update LangChain and test imports to avoid breaking changes in production.