run-llama/llama_index · error · ImportError

`llama-index-llms-langchain` package not found, please run `

Error message

`llama-index-llms-langchain` package not found, please run `pip install llama-index-llms-langchain`

What it means

When resolve_llm receives a LangChain BaseLanguageModel instance, core wraps it in LangChainLLM from the optional llama-index-llms-langchain integration. If that package is missing, the ImportError gives the exact install command; core itself does not depend on LangChain.

Source

Thrown at llama-index-core/llama_index/core/llms/utils.py:108

                model_path=model_path,
                messages_to_prompt=messages_to_prompt,
                completion_to_prompt=completion_to_prompt,
                model_kwargs={"n_gpu_layers": 1},
            )
        except ImportError:
            raise ImportError(
                "`llama-index-llms-llama-cpp` package not found, "
                "please run `pip install llama-index-llms-llama-cpp`"
            )

    elif BaseLanguageModel is not None and isinstance(llm, BaseLanguageModel):
        # NOTE: if it's a langchain model, wrap it in a LangChainLLM
        try:
            from llama_index.llms.langchain import LangChainLLM  # pants: no-infer-dep

            llm = LangChainLLM(llm=llm)
        except ImportError:
            raise ImportError(
                "`llama-index-llms-langchain` package not found, "
                "please run `pip install llama-index-llms-langchain`"
            )
    elif llm is None:
        from llama_index.core.llms.mock import MockLLM

        print("LLM is explicitly disabled. Using MockLLM.")
        llm = MockLLM()

    assert isinstance(llm, LLM)

    llm.callback_manager = (
        callback_manager or llm.callback_manager or Settings.callback_manager
    )

    return llm

View on GitHub (pinned to afd0fef371)

Solutions

  1. pip install llama-index-llms-langchain.
  2. Alternatively use the provider's native LlamaIndex LLM (e.g. llama_index.llms.openai.OpenAI) instead of wrapping a LangChain object.
  3. After installing, ensure langchain-core is also present at a compatible version (the integration pulls it in).

Example fix

# before
from langchain_openai import ChatOpenAI
Settings.llm = ChatOpenAI()  # -> ImportError
# after
pip install llama-index-llms-langchain
from llama_index.llms.langchain import LangChainLLM
Settings.llm = LangChainLLM(llm=ChatOpenAI())
Defensive patterns

Strategy: validation

Validate before calling

def has_langchain_integration() -> bool:
    try:
        import llama_index.llms.langchain  # noqa: F401
        return True
    except ImportError:
        return False

Type guard

from llama_index.core.llms.utils import BaseLanguageModel

def is_langchain_model(llm) -> bool:
    return BaseLanguageModel is not None and isinstance(llm, BaseLanguageModel)

Try / catch

try:
    Settings.llm = resolve_llm(langchain_llm)
except ImportError as e:
    if "llama-index-llms-langchain" in str(e):
        raise SystemExit("pip install llama-index-llms-langchain") from e
    raise

Prevention

When it happens

Trigger: Passing a LangChain model (e.g. ChatOpenAI from langchain) as Settings.llm or as the llm= argument to any LlamaIndex component without llama-index-llms-langchain installed.

Common situations: Mixing LangChain and LlamaIndex in one app but only installing LangChain's own packages; adding LlamaIndex to an existing LangChain codebase and reusing its LLM objects.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/499bbb7fe04f2a53. Report an issue: GitHub.