<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unable to log MLFlow run for LangChain chain while using databricks-langchain library in Generative AI</title>
    <link>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/138472#M1375</link>
    <description>&lt;P class="qt3gz91 paragraph"&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/148457"&gt;@heramb13&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P class="qt3gz91 paragraph"&gt;Your chain is being serialized by MLflow; during that process MLflow re-imports each runnable by its module path. The error shows MLflow is trying to import ChatDatabricks from the legacy module path “langchain_databricks”, which isn’t installed in the environment that’s saving the chain. This exact failure has been reported and typically occurs when the ChatDatabricks object (or its alias) resolves to the old path even if your source import line uses databricks_langchain. The fix is to either rebuild the chain so the class resolves to the new module path, or include the legacy shim as a dependency at log time.&lt;/P&gt;
&lt;H3 class="_7uu25p0 qt3gz9c _7pq7t612 heading3 _7uu25p1"&gt;Quick checks&lt;/H3&gt;
&lt;P&gt;Confirm ChatDatabricks resolves to the new module path with print(ChatDatabricks.&lt;U&gt;module&lt;/U&gt;)&lt;/P&gt;
&lt;UL class="qt3gz97 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;Ensure your input_example shape matches the first runnable in the chain (dict with “messages”, not a raw string)&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;Always pass pip_requirements with databricks-langchain (and optionally langchain-databricks if the legacy path appears)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P class="qt3gz91 paragraph"&gt;References that should help:&lt;/P&gt;
&lt;UL&gt;
&lt;LI class="qt3gz91 paragraph"&gt;&lt;A href="https://docs.databricks.com/aws/en/generative-ai/agent-framework/langchain-uc-integration" target="_blank"&gt;https://docs.databricks.com/aws/en/generative-ai/agent-framework/langchain-uc-integration&lt;/A&gt;&lt;/LI&gt;
&lt;LI class="qt3gz91 paragraph"&gt;&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/generative-ai/tutorials/agent-framework-notebook" target="_blank"&gt;https://learn.microsoft.com/en-us/azure/databricks/generative-ai/tutorials/agent-framework-notebook&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P class="qt3gz91 paragraph"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Nov 2025 20:33:32 GMT</pubDate>
    <dc:creator>stbjelcevic</dc:creator>
    <dc:date>2025-11-10T20:33:32Z</dc:date>
    <item>
      <title>Unable to log MLFlow run for LangChain chain while using databricks-langchain library</title>
      <link>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/109550#M761</link>
      <description>&lt;P&gt;Whenever I try to log my run it throws me the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;MlflowException: Failed to save runnable sequence: {'0': 'RunnableParallel&amp;lt;query,context&amp;gt; -- Failed to save runnable sequence: {\'context\': "RunnableSequence -- Failed to save runnable sequence: {\'2\': \'VectorStoreRetriever -- The `loader_fn` must be a function that returns a retriever.\'}."}.', '2': "ChatDatabricks -- 1 validation error for ChatDatabricks\nendpoint\n  Field required [type=missing, input_value={'extra_params': {}, 'max...ks', 'temperature': 0.0}, input_type=dict]\n    For further information visit https://errors.pydantic.dev/2.10/v/missing"}.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure what exactly is missing here. Initially I was using parameters such as temperature, max_tokens but decided to remove those as well. Yet the error was there.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;my_retriever is basically retriever using DatabricksVectorSearch.&lt;/LI&gt;&lt;LI&gt;There are no additional parameters to ChatDatabricks.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I am not sure how do I fix this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me with this?&lt;/P&gt;&lt;P&gt;Here is my simple code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from databricks_langchain import DatabricksVectorSearch, ChatDatabricks
# excluding all langchain imports

my_index = DatabricksVectorSearch(
    endpoint=vs_endpoint,
    index_name=my_index_name,
    columns=["ID", "TEXT"]
    )
my_retriever = my_index.as_retriever(search_kwargs={"k": 3, "query_type": "HYBRID"})

prompt = PromptTemplate.from_template(
    template="""Some template: {query} and {context} """
)
def format_context(text):
    return modified(text)
llm_endpoint = ChatDatabricks(endpoint="databricks-meta-llama-3-3-70b-instruct")

chain = (
    RunnableMap({
        "query": RunnableLambda(itemgetter("messages")),
        "context": RunnableLambda(itemgetter("messages")) | my_retriever | RunnableLambda(format_context),
    })
    | prompt
    | llm_endpoint
    | StrOutputParser()
)


from mlflow.models import infer_signature
import mlflow

model_name = f"some_model_name"
input_example = "input_example"
resp = chain.invoke(input_example)

with mlflow.start_run(run_name="run_name") as run:
    signature = infer_signature(input_example, resp)
    model_info = mlflow.langchain.log_model(
        chain,
        loader_fn=my_retriever, 
        artifact_path="path_to_artifact",
        registered_model_name=model_name,
        input_example=input_example,
        signature=signature
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Feb 2025 21:50:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/109550#M761</guid>
      <dc:creator>heramb13</dc:creator>
      <dc:date>2025-02-09T21:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to log MLFlow run for LangChain chain while using databricks-langchain library</title>
      <link>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/109608#M762</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/148457"&gt;@heramb13&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Can you try using this revised version of you code?&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;from databricks_langchain import DatabricksVectorSearch, ChatDatabricks
from langchain.prompts import PromptTemplate
from langchain.schema.runnable import RunnableMap, RunnableLambda
from langchain.schema.output_parser import StrOutputParser
from operator import itemgetter
import mlflow

vs_endpoint = "your_vector_search_endpoint"
my_index_name = "your_index_name"

def retriever_loader():
    my_index = DatabricksVectorSearch(
        endpoint=vs_endpoint,
        index_name=my_index_name,
        columns=["ID", "TEXT"]
    )
    return my_index.as_retriever(search_kwargs={"k": 3, "query_type": "HYBRID"})

my_retriever = retriever_loader()

prompt = PromptTemplate.from_template(
    template="""Some template: {query} and {context} """
)

def format_context(text):
    return modified(text)  # Ensure this function is defined

llm_endpoint = ChatDatabricks(endpoint="databricks-meta-llama-3-3-70b-instruct")

chain = (
    RunnableMap({
        "query": RunnableLambda(itemgetter("messages")),
        "context": RunnableLambda(itemgetter("messages")) | my_retriever | RunnableLambda(format_context),
    })
    | prompt
    | llm_endpoint
    | StrOutputParser()
)

model_name = "some_model_name"
input_example = {"messages": "Your example query here"}
resp = chain.invoke(input_example)

with mlflow.start_run(run_name="run_name") as run:
    model_info = mlflow.langchain.log_model(
        chain,
        loader_fn=retriever_loader,
        artifact_path="path_to_artifact",
        registered_model_name=model_name,
        input_example=input_example
    )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 12:52:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/109608#M762</guid>
      <dc:creator>Alberto_Umana</dc:creator>
      <dc:date>2025-02-10T12:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to log MLFlow run for LangChain chain while using databricks-langchain library</title>
      <link>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/109624#M763</link>
      <description>&lt;P&gt;Thank you so much for your response&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/106294"&gt;@Alberto_Umana&lt;/a&gt; !&lt;/P&gt;&lt;P&gt;The changes you mentioned about retriever worked and I don't have error with retriever anymore.&lt;/P&gt;&lt;P&gt;But I am still facing issues with llm_endpoint and the error is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;MlflowException: Failed to save runnable sequence: {'2': "ChatDatabricks -- No module named 'langchain_databricks'"}.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My code is now exactly the same as you have mentioned in the post.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 14:19:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/109624#M763</guid>
      <dc:creator>heramb13</dc:creator>
      <dc:date>2025-02-10T14:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to log MLFlow run for LangChain chain while using databricks-langchain library</title>
      <link>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/110067#M772</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/106294"&gt;@Alberto_Umana&lt;/a&gt;&amp;nbsp;or anyone?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 02:51:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/110067#M772</guid>
      <dc:creator>heramb13</dc:creator>
      <dc:date>2025-02-13T02:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to log MLFlow run for LangChain chain while using databricks-langchain library</title>
      <link>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/138472#M1375</link>
      <description>&lt;P class="qt3gz91 paragraph"&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/148457"&gt;@heramb13&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P class="qt3gz91 paragraph"&gt;Your chain is being serialized by MLflow; during that process MLflow re-imports each runnable by its module path. The error shows MLflow is trying to import ChatDatabricks from the legacy module path “langchain_databricks”, which isn’t installed in the environment that’s saving the chain. This exact failure has been reported and typically occurs when the ChatDatabricks object (or its alias) resolves to the old path even if your source import line uses databricks_langchain. The fix is to either rebuild the chain so the class resolves to the new module path, or include the legacy shim as a dependency at log time.&lt;/P&gt;
&lt;H3 class="_7uu25p0 qt3gz9c _7pq7t612 heading3 _7uu25p1"&gt;Quick checks&lt;/H3&gt;
&lt;P&gt;Confirm ChatDatabricks resolves to the new module path with print(ChatDatabricks.&lt;U&gt;module&lt;/U&gt;)&lt;/P&gt;
&lt;UL class="qt3gz97 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;Ensure your input_example shape matches the first runnable in the chain (dict with “messages”, not a raw string)&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;Always pass pip_requirements with databricks-langchain (and optionally langchain-databricks if the legacy path appears)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P class="qt3gz91 paragraph"&gt;References that should help:&lt;/P&gt;
&lt;UL&gt;
&lt;LI class="qt3gz91 paragraph"&gt;&lt;A href="https://docs.databricks.com/aws/en/generative-ai/agent-framework/langchain-uc-integration" target="_blank"&gt;https://docs.databricks.com/aws/en/generative-ai/agent-framework/langchain-uc-integration&lt;/A&gt;&lt;/LI&gt;
&lt;LI class="qt3gz91 paragraph"&gt;&lt;A href="https://learn.microsoft.com/en-us/azure/databricks/generative-ai/tutorials/agent-framework-notebook" target="_blank"&gt;https://learn.microsoft.com/en-us/azure/databricks/generative-ai/tutorials/agent-framework-notebook&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P class="qt3gz91 paragraph"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Nov 2025 20:33:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/unable-to-log-mlflow-run-for-langchain-chain-while-using/m-p/138472#M1375</guid>
      <dc:creator>stbjelcevic</dc:creator>
      <dc:date>2025-11-10T20:33:32Z</dc:date>
    </item>
  </channel>
</rss>

