{"record":{"id":"499bbb7fe04f2a53","repo":"run-llama/llama_index","slug":"llama-index-llms-langchain-package-not-found-pl","errorCode":null,"errorMessage":"`llama-index-llms-langchain` package not found, please run `pip install llama-index-llms-langchain`","messagePattern":"`llama-index-llms-langchain` package not found, please run `pip install llama-index-llms-langchain`","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/llms/utils.py","lineNumber":108,"sourceCode":"                model_path=model_path,\n                messages_to_prompt=messages_to_prompt,\n                completion_to_prompt=completion_to_prompt,\n                model_kwargs={\"n_gpu_layers\": 1},\n            )\n        except ImportError:\n            raise ImportError(\n                \"`llama-index-llms-llama-cpp` package not found, \"\n                \"please run `pip install llama-index-llms-llama-cpp`\"\n            )\n\n    elif BaseLanguageModel is not None and isinstance(llm, BaseLanguageModel):\n        # NOTE: if it's a langchain model, wrap it in a LangChainLLM\n        try:\n            from llama_index.llms.langchain import LangChainLLM  # pants: no-infer-dep\n\n            llm = LangChainLLM(llm=llm)\n        except ImportError:\n            raise ImportError(\n                \"`llama-index-llms-langchain` package not found, \"\n                \"please run `pip install llama-index-llms-langchain`\"\n            )\n    elif llm is None:\n        from llama_index.core.llms.mock import MockLLM\n\n        print(\"LLM is explicitly disabled. Using MockLLM.\")\n        llm = MockLLM()\n\n    assert isinstance(llm, LLM)\n\n    llm.callback_manager = (\n        callback_manager or llm.callback_manager or Settings.callback_manager\n    )\n\n    return llm\n\n","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/llms/utils.py#L90-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["pip install llama-index-llms-langchain.","Alternatively use the provider's native LlamaIndex LLM (e.g. llama_index.llms.openai.OpenAI) instead of wrapping a LangChain object.","After installing, ensure langchain-core is also present at a compatible version (the integration pulls it in)."],"exampleFix":"# before\nfrom langchain_openai import ChatOpenAI\nSettings.llm = ChatOpenAI()  # -> ImportError\n# after\npip install llama-index-llms-langchain\nfrom llama_index.llms.langchain import LangChainLLM\nSettings.llm = LangChainLLM(llm=ChatOpenAI())","handlingStrategy":"validation","validationCode":"def has_langchain_integration() -> bool:\n    try:\n        import llama_index.llms.langchain  # noqa: F401\n        return True\n    except ImportError:\n        return False","typeGuard":"from llama_index.core.llms.utils import BaseLanguageModel\n\ndef is_langchain_model(llm) -> bool:\n    return BaseLanguageModel is not None and isinstance(llm, BaseLanguageModel)","tryCatchPattern":"try:\n    Settings.llm = resolve_llm(langchain_llm)\nexcept ImportError as e:\n    if \"llama-index-llms-langchain\" in str(e):\n        raise SystemExit(\"pip install llama-index-llms-langchain\") from e\n    raise","preventionTips":["Install llama-index-llms-langchain whenever LangChain LLM objects cross into LlamaIndex.","Consider using the provider's native LlamaIndex LLM class instead of wrapping.","Smoke-test the wrap in CI to catch missing extras early."],"tags":["llama-index","langchain","install","integration","import-error"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}