{"id":7375,"library":"llama-index-llms-langchain","title":"LlamaIndex LangChain LLMs Integration","description":"The `llama-index-llms-langchain` library provides a seamless integration layer, allowing users to leverage LangChain's extensive collection of Large Language Models (LLMs) within the LlamaIndex framework. It acts as a bridge, enabling LangChain LLM instances to conform to LlamaIndex's LLM interface. The current version is `0.8.0`, and it receives regular updates aligned with LlamaIndex core releases.","status":"active","version":"0.8.0","language":"en","source_language":"en","source_url":"https://github.com/run-llama/llama-index/tree/main/llama-index-integrations/llms/llama-index-llms-langchain","tags":["llama-index","langchain","llm","integration","ai","rag"],"install":[{"cmd":"pip install llama-index-llms-langchain llama-index-core","lang":"bash","label":"Basic Install"},{"cmd":"pip install llama-index-llms-langchain llama-index-core langchain-openai","lang":"bash","label":"Install with OpenAI (LangChain provider)"}],"dependencies":[{"reason":"Required for core LlamaIndex functionalities.","package":"llama-index-core","optional":false},{"reason":"Core LangChain dependencies, specifically >=0.2.0, <0.3.0.","package":"langchain-core","optional":false},{"reason":"Core LangChain library, specifically >=0.1.0, <0.2.0.","package":"langchain","optional":false},{"reason":"Example LangChain LLM provider. Users must install their desired LangChain LLM provider (e.g., langchain-anthropic, langchain-community).","package":"langchain-openai","optional":true}],"imports":[{"note":"Import path changed with LlamaIndex v0.10+ package restructuring. Older versions used the `integrations` namespace.","wrong":"from llama_index.integrations.llms.langchain import LangChainLLM","symbol":"LangChainLLM","correct":"from llama_index.llms.langchain import LangChainLLM"}],"quickstart":{"code":"import os\nfrom langchain_openai import ChatOpenAI\nfrom llama_index.llms.langchain import LangChainLLM\nfrom llama_index.core import Settings\n\n# 1. Initialize a LangChain LLM instance\n# Make sure to install 'langchain-openai' (pip install langchain-openai)\n# and set your OPENAI_API_KEY environment variable.\n# Using os.environ.get for safe execution in environments without the key.\nlc_llm = ChatOpenAI(temperature=0.0, model=\"gpt-3.5-turbo\", api_key=os.environ.get(\"OPENAI_API_KEY\", \"test_key\"))\n\n# 2. Wrap the LangChain LLM with LlamaIndex's LangChainLLM wrapper\nllm = LangChainLLM(llm=lc_llm)\n\n# 3. Use the wrapped LLM with LlamaIndex\n# You can either set it globally or pass it directly to components.\nSettings.llm = llm\n\n# Example: Generate a completion\nresponse = Settings.llm.complete(\"Tell me a short story about a magical cat.\")\nprint(response.text)\n\n# Example: Generate a chat response\nfrom llama_index.core.llms import ChatMessage, MessageRole\nchat_response = Settings.llm.chat([\n    ChatMessage(role=MessageRole.USER, content=\"What is the capital of France?\")\n])\nprint(chat_response.message.content)\n","lang":"python","description":"This quickstart demonstrates how to instantiate a LangChain LLM (using `ChatOpenAI` as an example), wrap it using `LangChainLLM` from `llama-index-llms-langchain`, and then configure it as the default LLM within LlamaIndex's `Settings`. It shows both completion and chat interactions."},"warnings":[{"fix":"Update import statements. For `LangChainLLM`, change `from llama_index.integrations.llms.langchain import LangChainLLM` to `from llama_index.llms.langchain import LangChainLLM`.","message":"LlamaIndex v0.10+ introduced a significant package restructuring. Integration packages like `llama-index-llms-langchain` moved from the `llama_index.integrations` namespace to dedicated namespaces like `llama_index.llms` or `llama_index.embeddings`.","severity":"breaking","affected_versions":"LlamaIndex < 0.10"},{"fix":"After installing `llama-index-llms-langchain`, run `pip install langchain-<provider>` for your chosen LLM provider (e.g., `pip install langchain-openai`).","message":"This package (`llama-index-llms-langchain`) only provides the wrapper. You still need to install the specific LangChain provider packages (e.g., `langchain-openai`, `langchain-anthropic`, `langchain-google-genai`) for the LLMs you intend to use.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the `pyproject.toml` or `setup.py` of `llama-index-llms-langchain` on GitHub for exact dependency version constraints, or update all related packages: `pip install -U llama-index-llms-langchain llama-index-core langchain langchain-core langchain-openai`.","message":"Ensure compatible versions of `llama-index-core` and `langchain` (and its sub-packages like `langchain-core`, `langchain-openai`). Version mismatches can lead to `ImportError` or `AttributeError`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the package: `pip install llama-index-llms-langchain`. If installed, verify the import path is `from llama_index.llms.langchain import LangChainLLM`.","cause":"The `llama-index-llms-langchain` package is not installed or the import path is incorrect.","error":"ModuleNotFoundError: No module named 'llama_index.llms.langchain'"},{"fix":"Update your import statement to `from llama_index.llms.langchain import LangChainLLM`.","cause":"Using an outdated import path for LlamaIndex versions v0.10 and later.","error":"ImportError: cannot import name 'LangChainLLM' from 'llama_index.integrations.llms.langchain'"},{"fix":"You must wrap the LangChain LLM instance with `LangChainLLM` before passing it to LlamaIndex components. Example: `lc_llm = ChatOpenAI(...); llm = LangChainLLM(llm=lc_llm)`.","cause":"A raw LangChain LLM object is being used where LlamaIndex expects its own `LLM` interface. The `LangChainLLM` wrapper was not applied.","error":"AttributeError: 'ChatOpenAI' object has no attribute 'complete' (or 'chat')"}]}