CertSafari
    Databricks Certified Generative AI Engineer Associate· Lessons

    Domain 3 · Lesson 15/56

    Choosing LangChain, DSPy and agent tools on Databricks

    Select Langchain/similar tools for use in a Generative AI application.

    17 min read
    2.31% of exam
    8 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Choose an authoring framework once the agent pattern is fixed, knowing Databricks Agent Framework accepts LangChain, LangGraph, OpenAI, LlamaIndex or DSPy code
    • Decide when DSPy's declarative, optimizable modules should replace hand-written prompt strings
    • Give a LangChain agent tools of the right type: a local @tool function, a governed Unity Catalog function through UCFunctionToolkit, or a VectorSearchRetrieverTool over an AI Search index
    • Add Genie and MCP servers as tools to a LangChain agent, and trace the whole app with mlflow.langchain.autolog()

    Key concept

    Framework-specific tool wrappers — Each Databricks capability (Unity Catalog functions, AI Search indexes, Genie, MCP servers) comes with a ready-made adapter for each major framework, mostly in databricks-langchain or the unitycatalog-* packages. Picking a tool for a LangChain agent means picking the right wrapper, not writing the logic again.

    1.Pick the pattern first, then the framework

    You can build a generative AI application in many libraries: LangChain, LangGraph, the OpenAI SDK, LlamaIndex, DSPy. Picking one too early ties you to a structure before you know what the application needs. The order that works is to decide the pattern first. That means a deterministic chain, a single tool-calling agent, or a multi-agent supervisor, as covered in Deterministic chain vs single agent vs multi-agent supervisor. The pattern then tells you which framework features matter. A fixed retrieve-augment-generate chain needs little more than a prompt template and a model client. A tool-calling agent needs a tool-binding API and a loop that stops.

    On Databricks, the framework decision is less of a commitment than it looks. Custom agents can be written with any authoring library, and they get the same deployment, evaluation and MLflow Tracing integration whichever library you use. Custom Agents also don't care which pattern you choose. A team can ship a deterministic chain now and add tool calling later without moving to a different platform path.

    The tools don't lock you in either. The same Unity Catalog function can be handed to a LangGraph, OpenAI, Anthropic or LlamaIndex agent, and each framework installs its own small adapter package. So choose a framework for its authoring style and the features your pattern needs, such as LangGraph's prebuilt create_react_agent for a tool-calling loop. Don't choose it because you think only one framework can reach your data.

    One Unity Catalog function, four frameworks: each installs its own wrapper package
    FrameworkInstallation command
    LangGraph%pip install --upgrade unitycatalog-langchain[databricks] databricks-langchain langgraph
    OpenAI%pip install --upgrade unitycatalog-openai[databricks]
    Anthropic%pip install --upgrade unitycatalog-anthropic[databricks]
    LlamaIndex%pip install --upgrade unitycatalog-llamaindex[databricks] llama-index-llms-openai

    Whatever framework you pick, give the agent only the tools it needs. An agent handed an unbounded set of APIs, or a pile of irrelevant context, has more chances to call the wrong tool and to hallucinate. Decide on your tool approach during design, alongside the pattern.

    Checkpoint 1 of 8· Check yourself

    A team is building a tool-calling agent on Databricks. Their engineers know LlamaIndex well, and they want the agent deployed, evaluated and traced with MLflow like the platform's other agents. Which statement is correct?

    Sources12

    2.When DSPy beats hand-written prompts

    DSPy takes a different approach from LangChain-style prompt templates. You don't write and tweak a prompt string. You declare what each step should do, and an optimizer works out how to prompt the model to do it well. DSPy can automate prompt engineering, and it can also orchestrate LLM fine-tuning.

    DSPy is built from four parts:

    • Signatures state a step's input and output in natural language, for example question -> answer.
    • Modules carry out one text transformation, such as answering or summarizing. They replace hand-written prompts and can learn from examples.
    • Programs connect modules into a pipeline.
    • The compiler tunes a program's modules to meet a performance metric, either by generating better prompts or by fine-tuning the model.

    That design tells you when DSPy wins. Reach for it when you can measure quality with a metric and have examples to learn from, and when hand-tuning prompts has turned into a cycle of small edits that fix one case and break another. Recompiling against the metric replaces that guesswork. It also helps when you change the underlying model, because the prompts are generated, not handcrafted for one model's quirks. A quick prototype with no evaluation data gains little from DSPy, because the compiler has nothing to optimize against.

    You don't have to start over to adopt DSPy. Databricks publishes example notebooks that migrate existing LangChain model code to DSPy and then optimize it. DSPy programs can also act as agents in larger systems, for example as UC function-calling agents under a multi-agent orchestrator.

    Checkpoint 2 of 8· Check yourself

    Which of these projects would gain the most from moving to DSPy instead of continuing to hand-tune prompt templates?

    Sources3

    3.Governed Unity Catalog function tools

    A Unity Catalog function is the right tool when the agent has to run predefined logic: a lookup, a calculation, or a SQL query whose parameters the agent fills in. The logic sits in Unity Catalog, and Unity Catalog grants control it. To call a function, a user needs USE CATALOG and USE SCHEMA on its parent catalog and schema, plus EXECUTE on the function itself. Because the function is registered once, every agent and every framework that calls it reuses the same governed code.

    For LangChain and LangGraph, the wrapper is UCFunctionToolkit, imported from the databricks-langchain package. Pass it the functions' full three-part names. Its .tools property then returns LangChain-compatible tools that call the registered functions directly, which you hand to the agent with everything else. databricks-sdk is a different package: it supplies the WorkspaceClient for general workspace calls, and it doesn't turn UC functions into LangChain tools.

    Wrapping a registered Unity Catalog function as a LangGraph agent toolpython
    from databricks_langchain import ChatDatabricks, UCFunctionToolkit
    from langgraph.prebuilt import create_react_agent
    
    toolkit = UCFunctionToolkit(function_names=[function_name], client=client)
    agent = create_react_agent(
        ChatDatabricks(endpoint="databricks-claude-sonnet-4-5"),
        tools=toolkit.tools,
    )

    Serverless compute is a common setup failure: a workspace with only a SQL warehouse can register functions but can't run them through the Function Client. The other common mistake is a design one. Suppose a team copies the body of a governed inventory-lookup function into a local @tool function because it seems quicker. The agent now runs code that no Unity Catalog grant protects, and two copies of the logic will drift apart. If the function already exists in Unity Catalog, wrap it. Don't re-implement it, publish it as an HTTP endpoint, or export its results to a table on a schedule.

    Checkpoint 3 of 8· Check yourself

    An inventory-lookup function is already registered in Unity Catalog, and only users with EXECUTE on it may run it. You are giving a LangGraph agent the same lookup capability. Which approach keeps the logic governed?

    Checkpoint 4 of 8· Exam question

    Which Python package provides purpose-built LangChain tool wrappers for Unity Catalog functions, letting a governed UC function be surfaced directly as a LangChain-compatible tool for an agent?

    Checkpoint 5 of 8· Exam question

    A team has already registered a Python function in Unity Catalog that looks up current inventory levels by SKU, and access to it is controlled through Unity Catalog grants. They want a LangChain agent to call this exact governed function as a tool, without re-implementing the lookup logic or bypassing UC access control. Which approach should they use?

    Sources45

    4.Retriever tools over an AI Search index

    Unstructured knowledge such as manuals, tickets or policies reaches an agent through a retriever tool over a vector index. On Databricks that index lives in AI Search, which was formerly called Vector Search, so exam questions may use either name. When the index already exists, the agent needs a tool that queries it, not a new retrieval system.

    VectorSearchRetrieverTool is part of Databricks AI Bridge and ships in databricks-langchain. Point it at the index's three-part name and give it a tool_name and a tool_description. The model reads the description to decide when to search, so write it as an instruction ("Search Databricks documentation to answer product questions"), not as a label.

    Exposing an existing AI Search index as a LangChain agent toolpython
    from databricks_langchain import VectorSearchRetrieverTool, ChatDatabricks
    from langgraph.prebuilt import create_react_agent
    
    vs_tool = VectorSearchRetrieverTool(
        index_name="catalog.schema.my_databricks_docs_index",
        tool_name="databricks_docs_retriever",
        tool_description="Search Databricks documentation to answer product questions.",
    )

    That minimal form works for an index with Databricks managed embeddings. A direct-access index, or a Delta Sync index with self-managed embeddings, also needs text_column and an embedding model, for example DatabricksEmbeddings. The tool also accepts num_results, columns, filters and query_type (ANN or HYBRID) to shape what comes back.

    The older route is a SQL table function that wraps vector_search(), registered in Unity Catalog and loaded with UCFunctionToolkit. It is governed, discoverable, and automatically produces RETRIEVER spans in MLflow traces. Keep it for existing integrations rather than new agents. It also has two catches. SQL clients can truncate large rows, so long chunk columns need trimming with substring. And it inherits every limitation of vector_search().

    Checkpoint 6 of 8· Fill the gap

    The agent's model has to decide when to call this retriever. Which parameter carries the instruction it reads to make that decision?

    from databricks_langchain import VectorSearchRetrieverTool, ChatDatabricks
    from langgraph.prebuilt import create_react_agent
    
    vs_tool = VectorSearchRetrieverTool(
        index_name="catalog.schema.my_databricks_docs_index",
        tool_name="databricks_docs_retriever",
         ? ="Search Databricks documentation to answer product questions.",
    )

    Checkpoint 7 of 8· Exam question

    An engineering team already has a Mosaic AI Vector Search (AI Search) index over chunked support documents and wants to give a LangChain agent read-only access to that index as a callable retrieval tool, with minimal custom code and while keeping MLflow tracing on retrieval calls. Which option best satisfies this?

    Sources5

    5.Local tools, Genie, MCP and tracing

    The third tool type is a plain Python function decorated with LangChain's @tool. Choose it when the logic belongs to this one agent and needs no catalog governance, for example a helper that lists and reads files from a configured Unity Catalog volume. The function's docstring becomes the tool description the model sees. Because the code runs inside the agent, any safety checks are yours to write: the volume example rejects absolute paths and .. before it touches storage.

    The three tool types a LangChain agent can take, and when each wins
    Tool typeHow you create itGovernanceUse when
    Local Python function@tool decorator from langchain_core.toolsWhatever the function's own code enforcesAgent-specific helper logic
    Unity Catalog functionUCFunctionToolkit with three-part function namesUnity Catalog grants (EXECUTE)Predefined logic to share across agents and frameworks
    RetrieverVectorSearchRetrieverTool on an AI Search indexAccess to the index's Unity Catalog securableSearching unstructured documents

    For structured data, a Genie Agent answers natural-language questions about tables (see Genie as a subagent in multi-agent systems). In LangChain, you make it one more tool: wrap a GenieAgent from databricks_langchain.genie in an @tool function. The agent can then choose between the retriever for documents, a UC function for fixed logic, and Genie for questions about tables.

    Wrapping a GenieAgent as a LangChain tool for structured-data questionspython
    @tool
    def ask_genie(question: str) -> str:
        """Ask the configured Genie Agent a question about its business data."""
        response = genie.invoke({
            "messages": [{"role": "user", "content": question}]
        })
        return response["messages"][-1].content

    MCP gives tools to LangChain without tying them to any one framework. A managed MCP server exposes its tools once, and any framework can use them. In LangChain, DatabricksMultiServerMCPClient takes one or more DatabricksMCPServer URLs, and await mcp_client.get_tools() returns tools you pass to create_react_agent. The same client works for managed, external and custom servers. For anything that isn't predefined UC logic, Databricks recommends starting with MCPs.

    Once the tools are wired up, a single call traces the whole app. mlflow.langchain.autolog() records LLM calls, tool usage and agent steps without any change to the chain or agent code, and LangGraph apps use the same call (see MLflow Tracing (autolog and spans)). On serverless compute it is not switched on for you, so put the call in the agent code explicitly.

    Checkpoint 8 of 8· Match them up

    An agent needs five capabilities. Match each LangChain tool approach to the job it suits best.

    Tap a term, then the definition that fits it.

    Sources56748

    Practise it for real

    Register a Unity Catalog Python function, give it to a LangGraph agent with UCFunctionToolkit, and trace the run.

    1. 1.In a Databricks notebook with serverless compute enabled, run %pip install --upgrade unitycatalog-langchain[databricks] databricks-langchain langgraph, then dbutils.library.restartPython() in a separate cell.

      Why: The LangChain wrapper for UC functions ships in databricks-langchain, and the Function Client runs tools on serverless general compute.

      You should see: The packages install and Python restarts without errors.

    2. 2.Use DatabricksFunctionClient().create_python_function to register add_numbers in a catalog and schema where you hold CREATE FUNCTION, then call execute_function on it with number_1=2.0 and number_2=3.0.

      Why: Testing the function on its own first separates registration or permission problems from agent problems.

      You should see: result.value prints 5.0.

    3. 3.Call mlflow.langchain.autolog(), build UCFunctionToolkit(function_names=[function_name], client=client), and pass toolkit.tools to create_react_agent with ChatDatabricks.

      Why: Autolog has to be switched on explicitly on serverless, and the toolkit makes the governed function available as a LangChain tool.

      You should see: The agent is created without errors.

    4. 4.Invoke the agent with "Use the tool to add 2.0 and 3.0." and open the trace in the MLflow UI.

      Why: The trace shows whether the model actually called the UC tool or answered from memory.

      You should see: The answer contains 5, and the trace shows the LLM call followed by a tool call to add_numbers.

    Stuck? Get a nudge

    If the tool call fails with a permission error, check that the calling identity has EXECUTE on the function and USE CATALOG / USE SCHEMA on its parents.

    Sources

    (8)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Supports agents written with any authoring library, including LangGraph, LangChain, OpenAI, and LlamaIndex.”
      ↩︎ Pick the pattern first, then the framework
      “Supports agents written with any authoring library, including LangGraph, LangChain, OpenAI, and LlamaIndex.”
      ↩︎ Exam trap 1
      “Supports agents written with any authoring library, including LangGraph, LangChain, OpenAI, and LlamaIndex. Integrated with MLflow Tracing.”
      ↩︎ Checkpoint
    2. 2.
      “Custom Agents are agnostic to these design patterns, so you can start simple and evolve toward higher levels of automation and autonomy”
      ↩︎ Pick the pattern first, then the framework
      “Provide only the tools and context your agent requires, rather than an unbounded set of APIs or large irrelevant context.”
      ↩︎ Pick the pattern first, then the framework
    3. 3.
      “DSPy can automate prompt engineering and orchestrate LLM fine-tuning to improve performance.”
      ↩︎ When DSPy beats hand-written prompts
      “They replace traditional hand-written prompts and can learn from examples, making them more adaptable.”
      ↩︎ When DSPy beats hand-written prompts
      “It improves LM pipelines by adjusting modules to meet a performance metric, either by generating better prompts or fine-tuning models.”
      ↩︎ When DSPy beats hand-written prompts
      “These notebooks show how to migrate LangChain model code to DSPy and optimize it for better performance.”
      ↩︎ When DSPy beats hand-written prompts
    4. 4.
      “Use Unity Catalog functions when your agent needs to run predefined logic, such as a SQL query whose parameters the agent supplies.”
      ↩︎ Governed Unity Catalog function tools
      “calling an existing function requires EXECUTE on it”
      ↩︎ Governed Unity Catalog function tools
      “Each uses UCFunctionToolkit to call the function directly.”
      ↩︎ Governed Unity Catalog function tools
      “For other tools, start with MCPs.”
      ↩︎ Local tools, Genie, MCP and tracing
      “add it to an agent using your choice of framework”
      ↩︎ Key concept
      “Each uses UCFunctionToolkit to call the function directly.”
      ↩︎ Exam trap 2
      “The Function Client uses serverless general compute to run tools; a SQL warehouse alone is not sufficient.”
      ↩︎ Prediction
      “Use Unity Catalog functions when your agent needs to run predefined logic, such as a SQL query whose parameters the agent supplies.”
      ↩︎ Checkpoint
    5. 5.
      “from databricks.sdk import WorkspaceClient”
      ↩︎ Governed Unity Catalog function tools
      “AI Search was formerly Vector Search.”
      ↩︎ Retriever tools over an AI Search index
      “Use VectorSearchRetrieverTool from databricks-langchain or databricks-openai to expose an index as an agent tool.”
      ↩︎ Retriever tools over an AI Search index
      “you must configure the VectorSearchRetrieverTool and specify a custom embedding model and text column”
      ↩︎ Retriever tools over an AI Search index
      “This enables automatic tracing through MLflow by automatically generating RETRIEVER span types in MLflow logs.”
      ↩︎ Retriever tools over an AI Search index
      “For new Python agents, use AI Bridge. The following example is a reference for existing integrations.”
      ↩︎ Retriever tools over an AI Search index
      “Bind the tools to an LLM and run a tool-calling loop:”
      ↩︎ Local tools, Genie, MCP and tracing
      “For new Python agents, use AI Bridge. The following example is a reference for existing integrations.”
      ↩︎ Exam trap 3
    6. 6.
      “Genie agents can be used in multi-agent systems to answer natural language queries about your structured data.”
      ↩︎ Local tools, Genie, MCP and tracing
      “Tool support includes MCP servers and Unity Catalog Functions, both of which provide Unity Catalog-based governance.”
      ↩︎ Checkpoint
    7. 7.
      “The same client works for managed, external (MCP Service), and custom server URLs”
      ↩︎ Local tools, Genie, MCP and tracing
      “The same client works for managed, external (MCP Service), and custom server URLs”
      ↩︎ Exam trap 4
    8. 8.
      “mlflow.langchain.autolog() # LangGraph uses LangChain's autolog”
      ↩︎ Local tools, Genie, MCP and tracing
      “On serverless compute clusters, autologging for genAI tracing frameworks is not automatically enabled.”
      ↩︎ Local tools, Genie, MCP and tracing

    Spotted a mistake, or was something unclear? Tell us.