{"id":5288,"library":"langchainhub","title":"LangChain Hub Client","description":"LangChain Hub (pypi-slug: `langchainhub`) is an API client for the LangChain Hub, a centralized platform for sharing and discovering high-quality artifacts like prompts, chains, and agents for building LLM applications. It allows users to upload, browse, retrieve, and manage these components. The current version is 0.1.21. It's actively developed as part of the broader LangChain ecosystem, with releases typically tied to LangChain updates.","status":"active","version":"0.1.21","language":"en","source_language":"en","source_url":"https://github.com/hwchase17/langchain-hub","tags":["LangChain","LLM","Prompts","Agents","Chains","AI","MLOps","Hub"],"install":[{"cmd":"pip install langchainhub langchain","lang":"bash","label":"Install `langchainhub` and `langchain`"}],"dependencies":[{"reason":"Provides core LangChain primitives and the `hub` module for interaction.","package":"langchain","optional":false}],"imports":[{"note":"The primary interface for LangChain Hub is exposed through the `langchain` package, not directly from `langchainhub`. This changed in LangChain v0.3 where the 'hub' module (for managing prompts programmatically) was moved to `langchain-classic` or accessed via the `langchain` package itself.","wrong":"from langchainhub import hub","symbol":"hub","correct":"from langchain import hub"},{"note":"While `hub.pull` is used to retrieve content, `load_prompt` for local file loading is part of `langchain.prompts`.","wrong":"from langchain.hub import load_prompt","symbol":"load_prompt","correct":"from langchain.prompts import load_prompt"}],"quickstart":{"code":"import os\nfrom langchain import hub\nfrom langchain_openai import ChatOpenAI\n\n# Set your API key as an environment variable (or replace with your actual key for testing)\n# os.environ[\"OPENAI_API_KEY\"] = os.environ.get(\"OPENAI_API_KEY\", \"YOUR_API_KEY\")\n\n# Pull a prompt from the LangChain Hub\nprompt = hub.pull(\"hwchase17/q-and-a-prompt\")\n\n# Initialize a chat model (requires langchain-openai to be installed)\nllm = ChatOpenAI(openai_api_key=os.environ.get(\"OPENAI_API_KEY\", \"\"))\n\n# Create a simple chain\nchain = prompt | llm\n\n# Invoke the chain\nresponse = chain.invoke({\"question\": \"What is the capital of France?\", \"context\": \"Paris is the capital of France.\"})\nprint(response.content)","lang":"python","description":"This quickstart demonstrates how to pull a prompt from the LangChain Hub and use it with a LangChain LLM (ChatOpenAI) to form a simple question-answering chain. It assumes an OpenAI API key is available, preferably as an environment variable."},"warnings":[{"fix":"Ensure you are importing `hub` from `langchain` (e.g., `from langchain import hub`). If migrating from very old code, you might need to install `langchain-classic` and adjust imports, though current best practice is to use the `langchain` package directly for hub interactions.","message":"With LangChain v0.3+, the 'hub' module for programmatic prompt management has been refactored. Direct imports like `from langchain import hub` or `from langchain.prompts import load_prompt` should be used, or `langchain-classic` may be required for older patterns.","severity":"breaking","affected_versions":"LangChain >= 0.3.0"},{"fix":"Replace calls to `initialize_agent()` with specific agent factory functions, for example, `create_react_agent` for React-style agents. Refer to the LangChain documentation for the appropriate factory function for your agent type.","message":"The `initialize_agent()` function has been removed in LangChain v0.3. When loading agents from LangChain Hub, you should now use factory helpers like `create_react_agent` or other specific agent constructors.","severity":"breaking","affected_versions":"LangChain >= 0.3.0"},{"fix":"Always verify the 'lc://' URI for the specific artifact on the LangChain Hub. The format is typically `lc://<user_or_org>/<artifact_type>/<artifact_name>`.","message":"LangChain Hub artifacts (prompts, chains, agents) are referenced using 'lc://' URIs. Misspellings or incorrect paths in these URIs will result in loading errors.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}