LangChain warns that importing document loaders from langchain is deprecated
LangChainDeprecationWarning: Importing document loaders from langchain is deprecated.Short answer
Document loaders are no longer imported from the langchain package. The community ones live in langchain-community, so install it and import from langchain_community.document_loaders. The docs also say the community TextLoader and PDF loaders are no longer maintained, so new work should use a partner package such as langchain-pymupdf4llm or langchain-unstructured.
Fix it fast
1Find out which cause you have
Find every loader import in the project so you know how many lines need to change.
grep -rn "document_loaders" --include=*.py .2Match what you see, then jump to its fix
What does the error look like?
LangChainDeprecationWarning: Importing document loaders from langchain is deprecated.
Cause 1 of 2
The loader import still points at the langchain package
1Check
The warning appears at the line that does the old import; the loader class itself is fine.
python -W error -c "import your_module"2Fix
Install the community package and import the same class from its module.
pip install langchain-community
# in Python
from langchain_community.document_loaders import TextLoader
docs = TextLoader("notes.txt").load()3Verify
The script runs without the deprecation warning.
python -W error::DeprecationWarning your_script.pyConfirmed by pypi.org
Cause 2 of 2
The community loader itself is unmaintained
1Check
The integrations page says the classic PDF loaders in langchain-community are unmaintained, and that TextLoader and JSONLoader from langchain_community should no longer be used.
python -m pip show langchain-community2Fix
For new work, pick a partner loader from the integrations list, for example langchain-pymupdf4llm (PyMuPDF4LLMLoader) for PDFs or langchain-unstructured (UnstructuredLoader) for many file types. Install it and follow its page for the import and arguments.
pip install langchain-pymupdf4llm3Verify
Load a sample file and check the returned Document objects.
print(len(docs), docs[0].page_content[:200])Confirmed by docs.langchain.com
How do I stop it coming back?
- Treat deprecation warnings as errors in CI so old imports are caught early.
- Choose loaders from the integrations page, not from older tutorials.
- Install each integration as its own package and list it in requirements.txt.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
AI
TextLoader fails on a text file with an encoding error
UnicodeDecodeError: codec can't decode byte
TextLoader opens the file with the encoding you give it, or the system default if you give none.
3 causes, each with a fixAI
Azure OpenAI says the API deployment for this resource does not exist
The API deployment for this resource does not exist
Azure OpenAI does not take a model name in the model field.
2 causes, each with a fixAI
Azure OpenAI fails with an SSL certificate verification error
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]
The client checks the endpoint's certificate against its CA bundle, which is certifi by default.
2 causes, each with a fixAI
LangChain says it could not import the chromadb package
ImportError: Could not import chromadb python package. Please install it with `pip install chromadb`.
The message comes from LangChain's old Chroma class, which cannot import chromadb in the Python that runs your code.
2 causes, each with a fixAI
Gemini API returns 429 RESOURCE_EXHAUSTED on the free tier
429 RESOURCE_EXHAUSTED
Gemini limits are applied per Google Cloud project, not per API key, so a new key in the same project does not reset anything.
3 causes, each with a fixAI
ChatPromptTemplate is missing the variable agent_scratchpad
Expected: ['agent_scratchpad', 'input']
A tool-calling agent keeps its tool calls and tool results in a prompt slot named agent_scratchpad.
2 causes, each with a fix