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

# Get Started with Snowflake

> Configure read and write connections to Snowflake.

{user?.groups?.includes("spotify") && <NotForSpotify />}

<Tip>
  You can run this setup with an AI assistant instead. Run this skill and your assistant guides you through the steps:

  ```bash theme={null}
  npx skills add spotify/confidence-ai-plugins --skill setup-warehouse-snowflake
  ```

  The installer works with Claude Code, Cursor, Codex, Gemini CLI, and other AI assistants.
</Tip>

This tutorial helps you configure Confidence to talk to Snowflake to store
assignment data and calculate metrics. The steps to take are the following:

1. Create a Snowflake user and role that Confidence can use to read and write data to your warehouse.
2. Grant the role permissions to use a Snowflake warehouse.
3. Set up a schema and/or a database to store assignment data coming out of Confidence Flags.
4. Set up a schema and/or a database to store exposure calculation data.
5. Generate a key pair in Confidence, and assign the public key to your Snowflake user.
6. Configure a Data Warehouse connection so that Confidence can compute metrics
   using Snowflake.
7. Configure a Flag Applied connector so that Confidence can store
   assignment data in Snowflake.

<Note>
  If you already followed the setup guide on the **Admin** page, your
  setup is already complete. You can skip directly to [what's next](#whats-next).
</Note>

## Before You Begin

* This tutorial assumes you have a Confidence account.
* This tutorial assumes you have a Snowflake account ready, and have the permissions needed to
  create users, roles, databases and schemas for that account. You should also have a Snowflake warehouse
  available to run Confidence queries.

## Step 1. Create a Snowflake User and/or Role

As a first step, you create a Snowflake user, and grant a role to that user. You can either use a pre-existing role
that you already have, or create a new role just for the Confidence integration.

```sql theme={null}
CREATE ROLE CONFIDENCE_ROLE;
CREATE USER CONFIDENCE DEFAULT_ROLE = CONFIDENCE_ROLE;
GRANT ROLE CONFIDENCE_ROLE TO USER CONFIDENCE;
```

## Step 2. Give the Role Permissions to Run Queries in a Warehouse

Confidence needs to run queries to calculate metrics, so for this you need to grant the role you created permissions
to use the warehouse. You can either [create a new warehouse](https://docs.snowflake.com/en/sql-reference/sql/create-warehouse) only for Confidence, or use an existing warehouse.

```sql theme={null}
GRANT USAGE ON WAREHOUSE <warehouse_name> TO ROLE CONFIDENCE_ROLE;
```

## Step 3. Create Database and Schemas for Assignment Data

Confidence needs two schemas in Snowflake: one to store assignment data and one to store internal data for the exposure calculations.
In the following example, you create a separate database to hold Confidence data. To create the schemas, follow these steps (or change according to your organization guidelines):

```sql theme={null}
CREATE DATABASE CONFIDENCE;
GRANT USAGE ON DATABASE CONFIDENCE TO ROLE CONFIDENCE_ROLE;
CREATE SCHEMA CONFIDENCE.FLAG_APPLIED;
GRANT USAGE ON SCHEMA CONFIDENCE.FLAG_APPLIED TO ROLE CONFIDENCE_ROLE;
GRANT CREATE TABLE ON SCHEMA CONFIDENCE.FLAG_APPLIED TO ROLE CONFIDENCE_ROLE;
GRANT ALL ON ALL TABLES IN SCHEMA CONFIDENCE.FLAG_APPLIED TO ROLE CONFIDENCE_ROLE;
GRANT ALL ON FUTURE TABLES IN SCHEMA CONFIDENCE.FLAG_APPLIED TO ROLE CONFIDENCE_ROLE;
```

The role also needs **read-only** access to any tables you want to use to define metrics (the tables you use to define fact table queries).

## Step 4. Create Schemas for Exposure Calculations

Repeat the preceding steps to create a second schema. For example, `EXPOSURE`.

## Step 5. Generate a Key in Confidence, and Assign the Public Key to Your Snowflake User

1. Go to the Confidence App.
2. On the bottom of the left sidebar, select **Admin > Connections > Metrics Data Warehouse**.
3. Select **Snowflake**.
4. Click the **Crypto key** combo box, and generate a new key that you can call whatever you want. Then click **Copy public key**
   to the right of the combo box to copy the public key to your clipboard.
5. Run the following SQL command in Snowflake to let Confidence authenticate as the user you created using the public key:

   ```sql theme={null}
   ALTER USER <username> SET rsa_public_key='<paste key here>';
   ```

You are now ready to configure the rest of the settings on the warehouse connection.

## Step 6. Configure a Metrics Data Warehouse

For Confidence to be able to compute metrics using Snowflake, you need to set up
the connection between Confidence and Snowflake. To do so, follow these steps:

1. Go to the Confidence App.
2. On the bottom of the left sidebar, select **Admin > Connections > Metrics Data Warehouse**.
3. Select **Snowflake**.
4. Select the Crypto key you created in the earlier step, and complete the rest of the configuration form. After configuring
   the account identifier, user, and the crypto key, Confidence reads the available roles, databases and schemas from Snowflake and
   populates the remaining options.
5. Click **SAVE**.

If you have misconfigured anything, you see an error message. Otherwise,
you should see a success message.

## Step 7. Configure a Flag Applied Connector

For Confidence to be able to store assignment data in Snowflake, you need to set
up the connection between Confidence and Snowflake. To do so, follow these steps:

1. Go to the Confidence App.
2. On the bottom of the left sidebar, select **Admin > Connections > Flag Applied**.
3. Click **Create**.
4. Select **Snowflake** as destination.
5. Select the Crypto key you created in the earlier step, and complete the rest of the configuration form. After configuring
   the account identifier, user, and the crypto key, Confidence reads the available roles, databases and schemas from Snowflake and
   populates the remaining options.
6. Click **Save**.

## Step 8. Configure an Assignment Table

For Confidence to be able to use the stored assignment table, you need to set
up an assignment that reads from the Snowflake table. You first need to create
an entity, which represents the thing you're experimenting on, like your users.
To do so, follow these steps:

<Steps>
  <Step title="Go to Confidence" />

  <Step title="Navigate to Entities">
    On the left sidebar, select **Admin > Entities**.
  </Step>

  <Step title="Click Create" />

  <Step title="Create the entity">
    Enter `User` and specify the data type of the identifier that identifies the entity. For example, if you have a UUID that identifies your users, your primary key type is a **String**.
  </Step>
</Steps>

Now that you have an entity, you can create an assignment table that reads from
the Snowflake table. To do so, follow these steps:

<Steps>
  <Step title="Go to the Confidence App" />

  <Step title="Navigate to the Snowflake connection">
    On the bottom of the left sidebar, select **Admin > Connections > Flag Applied** and select the Snowflake connection you created.
  </Step>

  <Step title="Click Create in the Assignment table section" />

  <Step title="Select the entity you created in the earlier step" />

  <Step title="Enter a name for the assignment table">
    Enter a name for the assignment table, such as `flag_applied`.
  </Step>

  <Step title="Click Create" />
</Steps>

## Step 9. Celebrate

That's it! You have now configured Confidence to store assignment data and compute metrics using
Snowflake. You can now start defining metrics and compute results.

## What's Next?

The next step is to [create a fact table](/docs/metrics/fact-tables), and a
[metric](/docs/metrics/introduction). For an overview, see the [metric introduction](/docs/metrics/introduction)
page, and the [metrics quickstart](/docs/quickstarts/configure-metric).

## Related Resources

<CardGroup cols={2}>
  <Card title="Metrics Introduction" href="/docs/metrics/introduction">
    Overview of metrics in Confidence
  </Card>

  <Card title="Fact Tables" href="/docs/metrics/fact-tables">
    Configure fact tables for metrics
  </Card>

  <Card title="Assignment Tables" href="/docs/metrics/assignment-tables">
    Set up assignment tracking
  </Card>

  <Card title="Configure Metric Quickstart" href="/docs/quickstarts/configure-metric">
    Create your first metric
  </Card>
</CardGroup>
