Skip to main content

Connect agents to structured data

AI agents often need to query or manipulate structured data to answer questions, update records, or create data pipelines.

Databricks provides multiple approaches for connecting agents to structured data in Unity Catalog tables and external data stores. Use pre-configured MCP servers for immediate access to Genie spaces and SQL warehouses, or build custom tools for specialized workflows.

This page shows how to:

Query data in Unity Catalog tables

If your agent needs to query data in Unity Catalog tables, Databricks recommends using Genie spaces. A Genie space is a collection of up to 25 Unity Catalog tables that Genie can keep in context and query using natural language. Agents can access the Genie space using a pre-configured MCP URL.

To connect to a Genie space:

  1. Create a Genie space with the tables you want to query and share the space with the users, or service principals, that must access it. See Set up and manage an AI/BI Genie space.
  2. Create an agent and connect it to the pre-configured managed MCP url for the space: https://<workspace-hostname>/api/2.0/mcp/genie/{genie_space_id}.

To learn how to author an agent that connects to managed MCP servers, see Use Databricks managed MCP servers.

note

The managed MCP server for Genie invokes Genie as an MCP tool, which means history isn't passed when invoking Genie APIs.

Query data using Unity Catalog SQL function tool

Create a structured retrieval tool using Unity Catalog SQL functions when the query is known ahead of time and the agent provides the parameters.

The following example creates a Unity Catalog function called lookup_customer_info, which allows an AI agent to retrieve structured data from a hypothetical customer_data table.

Run the following code in a SQL editor.

SQL
CREATE OR REPLACE FUNCTION main.default.lookup_customer_info(
customer_name STRING COMMENT 'Name of the customer whose info to look up'
)
RETURNS STRING
COMMENT 'Returns metadata about a particular customer, given the customer's name, including the customer's email and ID. The
customer ID can be used for other queries.'
RETURN SELECT CONCAT(
'Customer ID: ', customer_id, ', ',
'Customer Email: ', customer_email
)
FROM main.default.customer_data
WHERE customer_name = customer_name
LIMIT 1;

After you create a Unity Catalog tool, add it to your agent. See Create an agent tool.