Granting Snowflake Query History to Shadowfax

Shadowfax can use Snowflake query history to better understand data lineage and user query patterns. This helps the AI agent retrieve the right business context and rank potential tables based on real world usage.

Before granting query history access, ensure that the Shadowfax database has been created as part of agent role creation. For more information, please refer to the Shadowfax role creation guide.

Implementation Steps

Note: Query history view must be created by an account admin.

1. First, switch to the account admin role:

USE ROLE ACCOUNTADMIN;

2. Create a view to provide filtered access to query history, this view is owned by account admin:

CREATE OR REPLACE VIEW SHADOWFAX.PUBLIC.QUERY_HISTORY
AS
    SELECT *
    FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
    WHERE ROLE_NAME != 'SHADOWFAX';

3. Grant read-only access to Shadowfax:

GRANT SELECT ON SHADOWFAX.PUBLIC.QUERY_HISTORY TO SHADOWFAX;

Customizing Access Filters

You can apply additional filtering in the view definition to exclude queries from sensitive databases, roles, or users. Here are some examples:

CREATE OR REPLACE VIEW ...
AS
...
    WHERE ROLE_NAME != 'SHADOWFAX'
    AND DATABASE_NAME != '...'
    AND ROLE_NAME != '...'
    AND USER_NAME != '...'