{"id":5777,"library":"langchain-ibm","title":"LangChain IBM Integration","description":"langchain-ibm is an integration package that connects LangChain with IBM watsonx.ai, leveraging the ibm-watsonx-ai SDK. It provides wrappers for various IBM watsonx.ai capabilities, including chat models, large language models (LLMs), embedding models, and rerankers, enabling developers to build AI applications using IBM's foundation models within the LangChain framework. The library is actively maintained with frequent updates and releases.","status":"active","version":"1.0.6","language":"en","source_language":"en","source_url":"https://github.com/langchain-ai/langchain-ibm","tags":["LangChain","IBM","watsonx.ai","LLM","AI","Generative AI","Chatbot","Embeddings"],"install":[{"cmd":"pip install -U langchain-ibm","lang":"bash","label":"Install `langchain-ibm`"}],"dependencies":[{"reason":"Core SDK for interacting with IBM watsonx.ai services.","package":"ibm-watsonx-ai"},{"reason":"Used for repairing malformed JSON output.","package":"json-repair"},{"reason":"Provides core LangChain functionalities and base classes.","package":"langchain-core"},{"reason":"Optional dependency for the SQL database toolkit.","package":"pyarrow","optional":true}],"imports":[{"symbol":"ChatWatsonx","correct":"from langchain_ibm import ChatWatsonx"},{"symbol":"WatsonxLLM","correct":"from langchain_ibm import WatsonxLLM"},{"symbol":"WatsonxEmbeddings","correct":"from langchain_ibm import WatsonxEmbeddings"},{"symbol":"WatsonxRerank","correct":"from langchain_ibm import WatsonxRerank"},{"note":"Required for configuring ChatWatsonx models.","symbol":"TextChatParameters","correct":"from ibm_watsonx_ai.foundation_models.schema import TextChatParameters"},{"note":"Required for configuring WatsonxLLM models.","symbol":"TextGenParameters","correct":"from ibm_watsonx_ai.foundation_models.schema import TextGenParameters"}],"quickstart":{"code":"import os\nfrom getpass import getpass\nfrom langchain_ibm import ChatWatsonx\nfrom ibm_watsonx_ai.foundation_models.schema import TextChatParameters\n\n# Set environment variables (replace with your actual values or retrieve from a secure source)\nif not os.environ.get(\"WATSONX_API_KEY\"): os.environ[\"WATSONX_API_KEY\"] = getpass(\"Enter your IBM Cloud API Key: \")\nif not os.environ.get(\"WATSONX_PROJECT_ID\"): os.environ[\"WATSONX_PROJECT_ID\"] = getpass(\"Enter your IBM watsonx.ai Project ID: \")\n\n# Define model parameters\nparameters = TextChatParameters(\n    temperature=0.7,\n    max_completion_tokens=500\n)\n\n# Initialize the ChatWatsonx model\n# Replace with your actual model_id and url\nmodel = ChatWatsonx(\n    model_id=\"ibm/granite-13b-chat-v2\", \n    url=\"https://us-south.ml.cloud.ibm.com\", # Example URL, choose based on your region\n    project_id=os.environ[\"WATSONX_PROJECT_ID\"],\n    params=parameters,\n)\n\n# Invoke the model\nresponse = model.invoke(\"What is the capital of France?\")\nprint(response.content)\n","lang":"python","description":"This quickstart demonstrates how to initialize and use the `ChatWatsonx` model. It requires an IBM Cloud API key and a watsonx.ai Project ID, which should be set as environment variables for security. You also need to specify a `model_id` and the appropriate `url` for your watsonx.ai service instance."},"warnings":[{"fix":"Upgrade `langchain-core` to a compatible version (>=1.0.0 for LangChain v1) and review LangChain's official migration guides for updated import paths and API changes. Check `langchain-ibm` release notes for specific `langchain-core` version requirements.","message":"LangChain v1 introduced significant changes to package namespaces and import paths within the core LangChain library. If you are migrating from an older LangChain version, ensure your `langchain-core` dependency is compatible and update imports accordingly, as older tutorials may break.","severity":"breaking","affected_versions":"LangChain core < 1.0.0 (and dependent langchain-ibm versions)"},{"fix":"Set `WATSONX_API_KEY` and `WATSONX_PROJECT_ID` environment variables. Ensure `model_id` and `url` parameters are accurate for your chosen watsonx.ai model and region during model initialization.","message":"IBM watsonx.ai models require an API key and Project ID, which should ideally be set as environment variables (e.g., `WATSONX_API_KEY`, `WATSONX_PROJECT_ID`) rather than hardcoding. Also, the `model_id` and `url` must be correctly specified for your watsonx.ai service instance.","severity":"gotcha","affected_versions":"All"},{"fix":"Import and use the correct parameter schema class from `ibm_watsonx_ai.foundation_models.schema` corresponding to the LangChain-IBM model wrapper you are initializing.","message":"Different watsonx.ai model types (chat, LLM, reranker) require specific parameter schemas (e.g., `TextChatParameters` for `ChatWatsonx`, `TextGenParameters` for `WatsonxLLM`, `RerankParameters` for `WatsonxRerank`). Using the wrong schema will lead to errors.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade `langchain-core` to version 0.3.81 / 1.2.5 or higher. Ensure any downstream IBM products like `watsonx.data` are also updated to their latest patched versions (e.g., `watsonx.data 2.3.1` or `watsonx.data on CPD 5.3.1`).","message":"A serialization injection vulnerability (CVE-2025-68664) was found in LangChain's `dumps()` and `dumpd()` functions, allowing untrusted data with 'lc' keys to be deserialized as objects. This directly affects `langchain-core` versions and, by extension, applications using `langchain-ibm` that rely on these serialization methods.","severity":"breaking","affected_versions":"langchain-core versions prior to 0.3.81 and 1.2.5"},{"fix":"Monitor the `langchain-ibm` GitHub repository for updates and patches related to issue #83. Consider using synchronous calls or implementing workarounds if asynchronous operations are critical and exhibit this behavior.","message":"There is an open bug where `asyncio` calls may fail due to synchronous, connection-pooled HTTP clients in the underlying `ibm-watsonx-ai` SDK. This can lead to unexpected behavior or deadlocks in asynchronous applications.","severity":"gotcha","affected_versions":"All known versions, issue #83 is open on GitHub."}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}