Databricks Integration (Deprecated)
The `langchain-databricks` package was an integration library connecting LangChain with Databricks AI features, including LLMs, vector search, and MLflow. It has been superseded by `databricks-langchain` to consolidate Databricks-related LangChain components. The last published version of `langchain-databricks` is 0.1.2, and it is no longer actively maintained or receiving new features. Users should migrate to the `databricks-langchain` package for continued support and new functionality.
Common errors
-
ModuleNotFoundError: No module named 'langchain_databricks'
cause Attempting to import from the deprecated `langchain_databricks` package when it's not installed or when the new `databricks_langchain` package is expected.fixInstall the new package (`pip install databricks-langchain`) and update your import statements to use `from databricks_langchain import ...`. -
MlflowException: Failed to save runnable sequence: ... ChatDatabricks -- 1 validation error for ChatDatabricks\nendpoint\n Field required
cause The `endpoint` parameter is missing when initializing `ChatDatabricks` or `DatabricksEmbeddings` during MLflow logging or direct use.fixEnsure `endpoint` is provided, e.g., `ChatDatabricks(endpoint="your-model-serving-endpoint")`. -
MlflowException: Failed to save runnable sequence: ... trying to import ChatDatabricks from the legacy module path “langchain_databricks”
cause MLflow is attempting to serialize a `ChatDatabricks` object that still resolves to the deprecated `langchain_databricks` module, even if your current code uses `databricks_langchain` imports. This often happens if the object wasn't fully re-instantiated after migration.fixRebuild your LangChain chain components to ensure all instances of Databricks classes (like `ChatDatabricks`) are explicitly re-imported and re-instantiated from `databricks_langchain`. You might also need to include `langchain-databricks` in `pip_requirements` during `mlflow.langchain.log_model` as a temporary shim if full migration isn't immediate. -
str type expected (type=type_error.str)
cause The input to the Databricks LLM endpoint is not in the expected string format, or the `transform_input_fn` is misconfigured. Some endpoints expect a dictionary or specific JSON structure, not just a raw string.fixVerify the expected input format for your specific Databricks Model Serving endpoint. Ensure your LangChain `invoke` call provides the prompt in the correct format (e.g., as a `HumanMessage` in a list for chat models). If custom transformation is used, check `transform_input_fn` parameters.
Warnings
- breaking The `langchain-databricks` package is deprecated. All features have been consolidated into the new `databricks-langchain` package. Future updates and new features will be released exclusively in `databricks-langchain`.
- gotcha When running outside a Databricks workspace, you must explicitly set Databricks authentication credentials (hostname and personal access token).
- gotcha Model serving endpoint name mismatches or incorrect API key/configuration are common causes for invocation failures.
- gotcha When logging LangChain models with MLflow, ensure the model name adheres to the three-level Unity Catalog path (`<catalog>.<schema>.<model>`) and that `chain_type` is passed in `model_config` for proper reconstruction.
Install
-
pip install langchain-databricks -
pip install databricks-langchain
Imports
- ChatDatabricks
from langchain_databricks import ChatDatabricks
from databricks_langchain import ChatDatabricks
- DatabricksEmbeddings
from langchain_databricks import DatabricksEmbeddings
from databricks_langchain import DatabricksEmbeddings
- DatabricksVectorSearch
from langchain_databricks import DatabricksVectorSearch
from databricks_langchain import DatabricksVectorSearch
Quickstart
import os
from databricks_langchain import ChatDatabricks
from langchain_core.messages import HumanMessage
# --- IMPORTANT: FOR RUNNING OUTSIDE DATABRICKS WORKSPACE ---
# Set these environment variables or pass them directly to the ChatDatabricks constructor.
# os.environ["DATABRICKS_HOST"] = os.environ.get("DATABRICKS_HOST", "https://your-databricks-workspace.cloud.databricks.com")
# os.environ["DATABRICKS_TOKEN"] = os.environ.get("DATABRICKS_TOKEN", "dapi********************************")
# Instantiate the chat model using a Databricks Model Serving endpoint
# Replace 'databricks-meta-llama-3-70b-instruct' with your actual endpoint name.
# Ensure DATABRICKS_HOST and DATABRICKS_TOKEN are set if running outside Databricks workspace.
chat_model = ChatDatabricks(
endpoint="databricks-meta-llama-3-70b-instruct",
temperature=0.1,
max_tokens=256
)
# Invoke the model
response = chat_model.invoke([HumanMessage(content="What is MLflow?")])
print(response.content)
# --- DEPRECATED PACKAGE USAGE (for context, prefer databricks-langchain) ---
# from langchain_databricks import ChatDatabricks
# deprecated_chat_model = ChatDatabricks(endpoint="your-deprecated-endpoint")
# print("WARNING: Using deprecated langchain-databricks package.")