Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

LangChain warns that importing document loaders from langchain is deprecated

ErrorLangChainDeprecationWarning: 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.

  • Applies to Python 3.12, langchain 1.x, langchain-community
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 .
  2. 2Match what you see, then jump to its fix

    1. 1Imports read from langchain.document_loaders import ...The loader import still points at the langchain packageFix
    2. 2The import is already correct, yet the loader is PyPDFLoader, TextLoader or JSONLoader from langchain_communityThe community loader itself is unmaintainedFix

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.py

Confirmed by pypi.org

Did this fix it?

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-community

2Fix

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-pymupdf4llm

3Verify

Load a sample file and check the returned Document objects.

print(len(docs), docs[0].page_content[:200])

Confirmed by docs.langchain.com

Did this fix it?

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:

Related fixes

AI

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.