Skip to main content

Security, Access and Cost Controls

Using an AI function in a worksheet is simple. Operating it safely for a team requires explicit access, model, privacy, and cost controls.

Learning objectives​

By the end of this lesson, you will be able to:

  • separate AI access from ordinary data access;
  • restrict which AI functions and models a role can use;
  • identify data that must not be included in prompts;
  • monitor token consumption and investigate unexpected spend.

1. Apply least-privilege access​

Calling Cortex AI Functions requires an account-level AI function privilege and an appropriate Snowflake database role. Avoid relying on broad access through PUBLIC in production.

USE ROLE ACCOUNTADMIN;

CREATE ROLE IF NOT EXISTS CORTEX_ANALYTICS_ROLE;

-- Grant only the AI functions required by this workload.
GRANT USE AI FUNCTION AI_COMPLETE ON ACCOUNT
TO ROLE CORTEX_ANALYTICS_ROLE;

-- Provides access to scalar AI functions without granting every Cortex service.
GRANT DATABASE ROLE SNOWFLAKE.AI_FUNCTIONS_USER
TO ROLE CORTEX_ANALYTICS_ROLE;

GRANT USAGE ON WAREHOUSE AI_ANALYTICS_WH
TO ROLE CORTEX_ANALYTICS_ROLE;

Use SNOWFLAKE.CORTEX_USER only when the role genuinely needs broader Cortex capabilities such as Cortex Search, Analyst, or Agents.

2. Control model access​

Model access and function access are separate controls. A role can have permission to call AI_COMPLETE but still be prevented from using a particular model.

For broad account-level control, configure the model allowlist:

USE ROLE ACCOUNTADMIN;

ALTER ACCOUNT SET CORTEX_MODELS_ALLOWLIST =
'mistral-large2,llama3.1-70b';

For finer control, use model objects in SNOWFLAKE.MODELS and grant access through RBAC. Test permissions without powerful secondary roles enabled, because a secondary administrative role can hide missing grants.

3. Protect prompt data​

Treat prompts as governed data-processing inputs.

  • Select only the columns required for the AI task.
  • Apply masking and row-access policies before invoking the model.
  • Do not include secrets, credentials, tokens, or unnecessary personal data.
  • Separate trusted instructions from untrusted user or document content.
  • Review regional availability and cross-region inference settings for regulated data.
  • Store prompt templates in a controlled table or repository and version every change.

4. Understand the cost model​

AI Functions are billed using AI Credits. Text-generation functions charge for input and output tokens, while embedding functions generally charge for input tokens. Cortex Guard adds its own processing cost.

Before processing a large table:

  1. Test on a small representative sample.
  2. Estimate prompt and response length.
  3. Set max_tokens for generated output.
  4. Select the smallest model that meets the quality target.
  5. Avoid sending repeated boilerplate or unused columns.

5. Monitor usage​

Account Usage exposes AI function telemetry for operational monitoring.

SELECT *
FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_AI_FUNCTIONS_USAGE_HISTORY
WHERE START_TIME >= DATEADD('day', -7, CURRENT_TIMESTAMP())
ORDER BY START_TIME DESC;

Create alerts for unusual growth by user, role, function, or model. Review AI usage together with warehouse consumption because SQL queries that invoke AI functions can incur both AI and warehouse costs.

Production checklist​

  • Dedicated role and warehouse
  • Function-level grants where practical
  • Approved model list
  • Masking and row-access policies applied
  • Prompt and model versions recorded
  • Token limits configured
  • Usage dashboard and budget alerts enabled

Official references​