> ## Documentation Index
> Fetch the complete documentation index at: https://docs.markifact.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect Databricks

> Connect your Databricks workspace to Markifact with a service principal or a personal access token, and choose whether Markifact can only read or also write.

Markifact connects to one Databricks workspace at a time. You give it the workspace URL and one credential, and Databricks decides what that credential is allowed to read or change.

***

## What you need

| Item | Where to find it |
| - | - |
| **Workspace URL** | The address in your browser when you are in Databricks, for example `https://dbc-a1b2c3d4-e5f6.cloud.databricks.com` |
| **A credential** | A service principal (recommended) or a personal access token |
| **A SQL warehouse** | The credential needs **Can use** on at least one SQL warehouse |
| **Data permissions** | Access to the tables Markifact should read, and optionally write |

> [!NOTE]
>
> A service principal is a separate identity made for tools like Markifact, so it keeps working when a person leaves the team. Creating one needs a workspace admin. A personal access token is quicker, but it acts as you and Databricks treats it as a legacy option.

***

## Option A: Service principal (recommended)

**1. Create the service principal**

In Databricks, open **Settings**, then **Identity and access**, then **Service principals**, and click **Add service principal**. Choose **Add new**, give it a name such as `markifact`, and keep **Databricks SQL access** and **Workspace access** turned on.

**2. Generate a secret**

Open the service principal, go to the **Secrets** tab and click **Generate secret**. Set a lifetime (up to 730 days), then add the **sql** and **unity-catalog** scopes and pick a level for each from the table in [Choose read-only or read and write](#choose-read-only-or-read-and-write).

**3. Copy the Client ID and Secret**

Databricks shows the secret only once. Copy both values.

## Option B: Personal access token

**1. Open your access tokens**

In Databricks, open **Settings**, then **Developer**, and click **Manage** next to **Access tokens**.

**2. Generate a token**

Click **Generate new token**, give it a name and a lifetime, then add the **sql** and **unity-catalog** scopes and pick a level for each from the table in [Choose read-only or read and write](#choose-read-only-or-read-and-write).

**3. Copy the token**

Databricks shows the token only once.

***

## Allow it to use a SQL warehouse

Every query runs on one of your SQL warehouses.

1. In Databricks, open **SQL Warehouses** and select a warehouse.
2. Click **Permissions**.
3. Add the service principal (or yourself) with **Can use**.

A stopped warehouse starts on its own when Markifact runs a query. Databricks bills that usage to your account.

***

## Choose read-only or read and write

Databricks gives you two locks, and you can use either or both.

**1. The scope level on the secret or token.** You pick it when you generate the credential.

| You want Markifact to | **sql** scope | **unity-catalog** scope | Markifact operations that work |
| - | - | - | - |
| **Read only** | Read + Restricted query | Read | Execute Read-Only Statement, List Warehouses, List Catalogs, List Schemas, List Tables, Get Table |
| **Read and write** | Read + Write | Read | All of the above, plus Execute Statement and Insert Rows |

With **Read + Restricted query**, Databricks itself refuses every statement that changes data, whatever permissions the identity has.

**2. Data permissions** on your catalogs, schemas and tables. A workspace admin or the data owner grants them in **Catalog** or with SQL.

| You want Markifact to | Grant on the schema |
| - | - |
| **Read only** | `USE CATALOG`, `USE SCHEMA`, `SELECT` |
| **Read and write** | The above plus `MODIFY`, and `CREATE TABLE` if Markifact should create tables |

Example for a read-only connection on the schema `main.marketing`. For a service principal, use its Client ID (application ID) in backticks. For a personal access token, use your own user name.

```sql theme={"dark"}
GRANT USE CATALOG ON CATALOG main TO `<client-id>`;
GRANT USE SCHEMA, SELECT ON SCHEMA main.marketing TO `<client-id>`;
```

To also allow writes:

```sql theme={"dark"}
GRANT MODIFY ON SCHEMA main.marketing TO `<client-id>`;
GRANT CREATE TABLE ON SCHEMA main.marketing TO `<client-id>`;
```

> [!NOTE]
>
> With a read-only connection, the write operations stay visible in Markifact, but Databricks refuses them and the run tells you what to change. Nothing is written.

***

## Connect in Markifact

1. Open [Connections](https://www.markifact.com/app/connections) and click **Connect** next to Databricks.
2. Paste your **Workspace URL**.
3. Choose **Service principal** or **Personal access token** and paste the values.
4. Click **Save Connection**. Markifact tests the credential before saving.

Each connection covers one workspace. Add another connection for a second workspace.

***

## Good to know

* **Queries never change data by accident.** Execute Read-Only Statement only accepts statements that read (SELECT, WITH, SHOW, DESCRIBE, EXPLAIN). Changes go through Execute Statement or Insert Rows, which ask for approval when an AI agent runs them.
* **Row limit.** A query returns up to 1,000 rows by default. Raise **Row Limit** for more. The output tells you when a result was cut.
* **Large results.** Databricks stops a query whose result is larger than 25 MiB. Select fewer columns or rows.
* **One statement per run.** Send a single SQL statement each time.
* **Credentials expire.** A secret or token stops working at the end of its lifetime, and Databricks removes one that has not been used for 90 days. Generate a new one and reconnect.

***

## Troubleshooting

| Message | What to do |
| - | - |
| Databricks rejected the service principal | Check the Workspace URL, the Client ID and the Secret. If the secret expired, generate a new one. |
| Databricks rejected the credentials | The token is wrong, expired or revoked. Create a new one and reconnect. |
| Does not include the sql or unity-catalog scope | Generate a secret or token that includes both **sql** and **unity-catalog**, then reconnect. |
| This Databricks connection is read-only | The secret was generated with **sql** set to Read + Restricted query. To let Markifact write, generate a secret with **sql** set to Read + Write and reconnect. |
| Cannot see any SQL warehouse, or no permission to use the SQL warehouse | Give the identity **Can use** on a SQL warehouse. |
| Does not have USE SCHEMA or SELECT | Grant read access on that schema or table. |
| Does not have INSERT, MODIFY or CREATE TABLE | The connection is read-only for that object. Grant `MODIFY` (and `CREATE TABLE` to create tables) if Markifact should write there. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.