Skip to content

Snowflake ​

The Snowflake Source connects an AI System to one Snowflake database with a programmatic access token. Metric Tests read metrics that you write as SQL queries in a catalog table. Scout, Agent Tests, and the Risk Agent read tables and run read-only queries.

Used byMetric Tests, Agent Tests, Scout, Risk Agent
ModePull
CredentialsAccount identifier, programmatic access token, warehouse, and database
Metric selectionSelect a metric of the MODULOS_METRIC_CATALOG table

Where in Modulos ​

  • AI System → Settings → Sources → Add Source → Snowflake adds the Source.

Before you start ​

How to prepare Snowflake ​

  1. In Snowflake, give a dedicated user a role with the USAGE and SELECT privileges only.
  2. Open Admin → Users & Roles.
  3. Select the user.
  4. Create a programmatic access token.
  5. Get the account identifier in the format ORGNAME-ACCOUNTNAME.
  6. Get the warehouse.
  7. Get the database.

How to connect Snowflake ​

  1. Open AI System → Settings → Sources.
  2. Select Add Source.
  3. Select Snowflake.
  4. Type a Source Name.
  5. Type the account identifier in Account Identifier.
  6. Paste the token into Programmatic Access Token.
  7. Type the warehouse in Warehouse.
  8. Type the database in Database.
  9. If necessary, type a schema in Schema (Optional) and a role in Role (Optional).
  10. Select Save.
Add Source dialog with Snowflake selected: the connection instructions on the left, the fields on the right.
Add a Snowflake Source.
  1. 1
    Warehouse
    The warehouse that runs the queries of Modulos.
  2. 2
    Database
    The database that Modulos queries.
  3. 3
    Role
    Empty: the default role of the user.

Keep Role (Optional) empty to use the default role. When you save, Modulos runs SELECT 1 in the warehouse and the database. This check does not test the access to your tables.

Metrics for Metric Tests ​

A Snowflake metric is a SQL query that gives one number. You write the metrics in a table with the name MODULOS_METRIC_CATALOG, in a schema of the database:

ColumnContent
metric_keyA unique key for the metric, without /
metric_labelThe name that the test dialog shows
metric_queryThe SQL query that gives the value

For example:

sql
CREATE TABLE MODULOS_METRIC_CATALOG (
  metric_key   VARCHAR,
  metric_label VARCHAR,
  metric_query VARCHAR
);

INSERT INTO MODULOS_METRIC_CATALOG VALUES (
  'rows_scored_24h',
  'Rows scored in the last 24 hours',
  'SELECT COUNT(*) FROM SCORES WHERE scored_at >= DATEADD(hour, -24, CURRENT_TIMESTAMP())'
);

Each metric_query must obey these rules:

  • It is one statement that starts with SELECT or WITH.
  • It gives one row with one numeric column.
  • It sets its own time window. Modulos does not apply the schedule of the test to the query.
  • It finishes in less than 30 seconds.

Modulos reads a catalog table in each schema of the database that has one. Modulos runs each query in the schema of its catalog table. Because of this, a table name without a schema works.

To use a metric in a Metric Test:

  1. In the test dialog, select the Snowflake Source.
  2. Select the Metric. The menu shows each metric as <label> · <schema>.

If the database has no catalog table, the menu is empty.

Scout, Agent Tests, and the Risk Agent ​

Scout, Agent Tests, and the Risk Agent read a Snowflake Source:

  • Tables: the tables of the schema, or of the database if Schema (Optional) is empty, and the columns of one table.
  • Queries: one read-only statement that starts with SELECT, WITH, SHOW, or DESCRIBE. A result shows a maximum of 200 rows.

If an AI System has more than one Snowflake Source, the agent names the Source in each request by its account and database (ACCOUNT/DATABASE).

Important considerations ​

  • Give the token a role with USAGE and SELECT only. The role sets the limit on what Modulos can do in Snowflake.
  • If a metric query fails, the test gets no value. Test each query in Snowflake before you add it to the catalog.