Zero Labs
Industry News / AI

Stop Giving Every User the Keys to Your AI Kingdom: Per-Function Privileges for Snowflake Cortex AI…

Source · Towards AI By Satish Kumar

From the publisher’s feed, collected in the ZeroLabs newsroom.

Stop Giving Every User the Keys to Your AI Kingdom: Per-Function Privileges for Snowflake Cortex AI FunctionsAs of May 13, 2026, Snowflake’s access control for Cortex AI Functions just got a major upgrade — and your PUBLIC role should be the first thing you audit.IntroductionHere’s a scenario most Snowflake admins know too well: you’ve enabled Cortex AI Functions for your organization, and suddenly every user with the PUBLIC role can call AI_COMPLETE, AI_CLASSIFY, AI_EXTRACT, and every other AI function in the catalog. That's convenient — until your finance team accidentally kicks off a million-token AI_COMPLETE job, or an intern discovers AI_TRANSLATE and decides to translate your entire data warehouse into Klingon.Until now, access control for Cortex AI Functions was all-or-nothing. You either granted USE AI FUNCTIONS (blanket access to everything) or revoked it entirely. There was no middle ground.As of May 13, 2026, Snowflake changed that with per-function privileges for Cortex AI Functions, now Generally Available. This feature lets you grant access to individual AI functions — like AI_COMPLETE or AI_EMBED — on a per-role basis, using the new USE AI FUNCTION privilege.In this article, you’ll learn how to design and implement a production-grade, least-privilege access control strategy for Cortex AI Functions — from architecture to SQL to audit.Architecture OverviewBefore diving into code, let’s understand how the privilege model works.The Two-Layer Access ModelSnowflake Cortex AI Functions require two independent layers of authorization:Account-level privilege: Either the blanket USE AI FUNCTIONS or a per-function USE AI FUNCTION Database role: Either SNOWFLAKE.CORTEX_USER (full Cortex access) or SNOWFLAKE.AI_FUNCTIONS_USER (scalar AI functions only — no Cortex Agent, Analyst, or Search)Think of it like a building with two doors. The account-level privilege is the front door — it determines which functions you can call. The database role is the service elevator — it determines whether you can reach the AI floor at all. You need both.The OR RelationshipThe blanket USE AI FUNCTIONS and per-function USE AI FUNCTION privileges have an OR relationship:| Scenario | Can Call `AI_COMPLETE`? | Details || ------------------------------------------- | ----------------------- | ------------------------------------------------------------------ || Role has `USE AI FUNCTIONS` only | ✅ Yes | Can call all available AI functions, including `AI_COMPLETE` || Role has `USE AI FUNCTION AI_COMPLETE` only | ✅ Yes | Can call only `AI_COMPLETE` (restricted to this specific function) || Role has both permissions | ✅ Yes | Full access — can call `AI_COMPLETE` and all other AI functions || Role has neither permission | ❌ No | Cannot call `AI_COMPLETE` or any other AI functions |This OR relationship is critical to understand. If you revoke a per-function privilege but the role still has the blanket USE AI FUNCTIONS, nothing changes. You must revoke the blanket privilege first for per-function grants to have any effect.Data FlowPrerequisitesA Snowflake account with Cortex AI Functions available in your regionACCOUNTADMIN role (required to manage account-level privileges)Basic understanding of Snowflake RBAC (roles, grants, database roles)Step-by-Step ImplementationStep 1: Audit Your Current StateBefore changing anything, understand what’s currently granted. Run these queries to see your existing privilege landscape:-- Check if USE AI FUNCTIONS is granted to PUBLIC (the default)SHOW GRANTS TO ROLE PUBLIC;Look for a row with USE AI FUNCTIONS in the output. If it's there, every user in your account currently has blanket access to all Cortex AI functions.-- Check all existing AI-related grants on the accountSHOW GRANTS ON ACCOUNT;-- See who's actually using Cortex functions (and what it's costing)SELECT FUNCTION_NAME, USER_NAME, COUNT(*) AS call_count, SUM(CREDITS_USED) AS total_creditsFROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_FUNCTIONS_USAGE_HISTORYWHERE START_TIME >= DATEADD('day', -30, CURRENT_TIMESTAMP())GROUP BY FUNCTION_NAME, USER_NAMEORDER BY total_credits DESC;This usage query is critical. It tells you which functions each user actually needs — not which functions they might need. Build your privilege strategy around real usage data, not assumptions.Step 2: Design Your Role HierarchyBased on your audit, design roles that map to actual job functions. Here’s a production-grade role hierarchy:USE ROLE ACCOUNTADMIN;-- Step 2a: Revoke blanket access from PUBLIC-- This is the prerequisite for per-function privileges to take effectREVOKE USE AI FUNCTIONS ON ACCOUNT FROM ROLE PUBLIC;-- Step 2b: Create function-specific roles-- Role: AI Analysts — need classification, extraction, and summarizationCREATE ROLE IF NOT EXISTS AI_ANALYST_ROLE;GRANT USE AI FUNCTION AI_COMPLETE ON ACCOUNT TO ROLE AI_ANALYST_ROLE;GRANT USE AI FUNCTION AI_CLASSIFY ON ACCOUNT TO ROLE AI_ANALYST_ROLE;GRANT USE AI FUNCTION AI_EXTRACT ON ACCOUNT TO ROLE AI_ANALYST_ROLE;GRANT USE AI FUNCTION AI_SENTIMENT ON ACCOUNT TO ROLE AI_ANALYST_ROLE;GRANT USE AI FUNCTION AI_SUMMARIZE ON ACCOUNT TO ROLE AI_ANALYST_ROLE;GRANT USE AI FUNCTION AI_SUMMARIZE_AGG ON ACCOUNT TO ROLE AI_ANALYST_ROLE;GRANT USE AI FUNCTION AI_AGG ON ACCOUNT TO ROLE AI_ANALYST_ROLE;-- Role: ML Engineers — need embeddings and completions for pipelinesCREATE ROLE IF NOT EXISTS AI_ML_ENGINEER_ROLE;GRANT USE AI FUNCTION AI_COMPLETE ON ACCOUNT TO ROLE AI_ML_ENGINEER_ROLE;GRANT USE AI FUNCTION AI_EMBED ON ACCOUNT TO ROLE AI_ML_ENGINEER_ROLE;GRANT USE AI FUNCTION AI_SIMILARITY ON ACCOUNT TO ROLE AI_ML_ENGINEER_ROLE;GRANT USE AI FUNCTION AI_PARSE_DOCUMENT ON ACCOUNT TO ROLE AI_ML_ENGINEER_ROLE;-- Role: Content Team — need translation and redaction onlyCREATE ROLE IF NOT EXISTS AI_CONTENT_ROLE;GRANT USE AI FUNCTION AI_TRANSLATE ON ACCOUNT TO ROLE AI_CONTENT_ROLE;GRANT USE AI FUNCTION AI_REDACT ON ACCOUNT TO ROLE AI_CONTENT_ROLE;GRANT USE AI FUNCTION AI_SUMMARIZE ON ACCOUNT TO ROLE AI_CONTENT_ROLE;-- Role: Data Engineers — need document parsing for ETL pipelinesCREATE ROLE IF NOT EXISTS AI_DATA_ENGINEER_ROLE;GRANT USE AI FUNCTION AI_PARSE_DOCUMENT ON ACCOUNT TO ROLE AI_DATA_ENGINEER_ROLE;GRANT USE AI FUNCTION AI_EXTRACT ON ACCOUNT TO ROLE AI_DATA_ENGINEER_ROLE;GRANT USE AI FUNCTION AI_TRANSCRIBE ON ACCOUNT TO ROLE AI_DATA_ENGINEER_ROLE;Step 3: Wire Up the Database RoleRemember the two-layer model. Per-function privileges alone aren’t enough — each role also needs one of the Cortex database roles:USE ROLE ACCOUNTADMIN;-- Grant CORTEX_USER for full Cortex capability (includes Agent, Analyst, Search)GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE AI_ML_ENGINEER_ROLE;-- Grant AI_FUNCTIONS_USER for scalar AI functions only-- (excludes Cortex Agent, Analyst, Fine-tuning, Search)GRANT DATABASE ROLE SNOWFLAKE.AI_FUNCTIONS_USER TO ROLE AI_ANALYST_ROLE;GRANT DATABASE ROLE SNOWFLAKE.AI_FUNCTIONS_USER TO ROLE AI_CONTENT_ROLE;GRANT DATABASE ROLE SNOWFLAKE.AI_FUNCTIONS_USER TO ROLE AI_DATA_ENGINEER_ROLE;Why use AI_FUNCTIONS_USER instead of CORTEX_USER? Least privilege. If a role only needs scalar AI functions, don't give it access to Cortex services like Agent or Analyst. This is defense-in-depth — and it closes a surface area most teams don't even realize they've left open.Step 4: Assign Roles to Users and ValidateUSE ROLE ACCOUNTADMIN;-- Assign roles to usersGRANT ROLE AI_ANALYST_ROLE TO USER analyst_jane;GRANT ROLE AI_ML_ENGINEER_ROLE TO USER ml_eng_bob;GRANT ROLE AI_CONTENT_ROLE TO USER content_maria;GRANT ROLE AI_DATA_ENGINEER_ROLE TO USER data_eng_alex;-- Validate: Check what analyst_jane can doSHOW GRANTS TO ROLE AI_ANALYST_ROLE;Test enforcement by switching to a restricted role and attempting a function call outside your grants:USE ROLE AI_CONTENT_ROLE;-- This should succeed (AI_TRANSLATE is granted)SELECT AI_TRANSLATE('Hello, world!', 'en', 'fr');-- This should fail (AI_COMPLETE is NOT granted to AI_CONTENT_ROLE)SELECT AI_COMPLETE('llama3.1-8b', 'Tell me a joke');If the second query returns an access error, your per-function privileges are working correctly.Results / Example OutputAfter implementing this strategy, your SHOW GRANTS output for AI_ANALYST_ROLE will look like:| Privilege | Granted On | Name || -------------------------------- | ---------- | ---------------- || USE AI FUNCTION AI_COMPLETE | ACCOUNT | AI_COMPLETE || USE AI FUNCTION AI_CLASSIFY | ACCOUNT | AI_CLASSIFY || USE AI FUNCTION AI_EXTRACT | ACCOUNT | AI_EXTRACT || USE AI FUNCTION AI_SENTIMENT | ACCOUNT | AI_SENTIMENT || USE AI FUNCTION AI_SUMMARIZE | ACCOUNT | AI_SUMMARIZE || USE AI FUNCTION AI_SUMMARIZE_AGG | ACCOUNT | AI_SUMMARIZE_AGG || USE AI FUNCTION AI_AGG | ACCOUNT | AI_AGG |And your usage monitoring will show clean separation between roles:| FUNCTION_NAME | USER_NAME | CALL_COUNT | TOTAL_CREDITS || ------------- | ------------- | ---------: | ------------: || AI_COMPLETE | ml_eng_bob | 12,450 | 8.34 || AI_CLASSIFY | analyst_jane | 8,200 | 2.17 || AI_TRANSLATE | content_maria | 3,100 | 0.89 || AI_EXTRACT | data_eng_alex | 5,600 | 3.22 |Performance & Optimization TipsWarehouse sizing: Snowflake recommends warehouses no larger than MEDIUM for Cortex AI Function calls. Larger warehouses do not increase AI function throughput — they just cost more.Batch over interactive: Cortex AI Functions are optimized for throughput, not latency. Process tables in batch rather than calling functions row-by-row in interactive sessions.Track costs proactively: Use SNOWFLAKE.ACCOUNT_USAGE.CORTEX_FUNCTIONS_QUERY_USAGE_HISTORY to identify expensive queries before they become budget problems.Use AI_FUNCTIONS_USER over CORTEX_USER where possible. If a role doesn't need Cortex Agent, Analyst, or Search, don't grant the broader database role.Security & GovernanceThe Revoke-Then-Grant PatternThis is the core pattern for production environments:-- 1. Revoke blanket accessREVOKE USE AI FUNCTIONS ON ACCOUNT FROM ROLE PUBLIC;-- 2. Grant per-function privileges to specific rolesGRANT USE AI FUNCTION ON ACCOUNT TO ROLE ;-- 3. Audit regularlySHOW GRANTS ON ACCOUNT;Never skip step 1. If PUBLIC still has USE AI FUNCTIONS, every per-function grant you create is redundant — everyone already has access to everything.Restricted Caller’s RightsIf you’re using AI Functions inside Snowpark Container Services or stored procedures with EXECUTE AS RESTRICTED CALLER, you need to grant privileges to both the session role AND the service/procedure owner role:-- Session roleGRANT USE AI FUNCTION AI_COMPLETE ON ACCOUNT TO ROLE session_role;-- Service owner role (for Restricted Caller's Rights)GRANT CALLER USE AI FUNCTIONS ON ACCOUNT TO ROLE service_owner_role;Ongoing Audit QueryRun this monthly to catch privilege drift:SELECT GRANTEE_NAME AS role_name, PRIVILEGE, GRANTED_BY, CREATED_ONFROM SNOWFLAKE.ACCOUNT_USAGE.GRANTS_TO_ROLESWHERE PRIVILEGE LIKE 'USE AI FUNCTION%' OR PRIVILEGE = 'USE AI FUNCTIONS'ORDER BY GRANTEE_NAME, PRIVILEGE;Key TakeawaysPer-function privileges (USE AI FUNCTION ) are now GA, giving admins fine-grained control over which Cortex AI functions each role can call.Revoke USE AI FUNCTIONS from PUBLIC first — per-function grants have no effect while the blanket privilege is active.Two layers are required: an account-level privilege (blanket or per-function) AND a database role (CORTEX_USER or AI_FUNCTIONS_USER).Design roles around job functions, not individuals. Analysts, ML engineers, content teams, and data engineers have different AI function needs.Use AI_FUNCTIONS_USER instead of CORTEX_USER for roles that only need scalar AI functions — this blocks access to Cortex Agent, Analyst, and Search.Audit with SHOW GRANTS and usage views to ensure your privilege model matches actual usage patterns.Batch processing and MEDIUM warehouses are the cost-efficient way to run Cortex AI Functions at scale.What’s NextModel-level RBAC: Combine per-function privileges with Snowflake’s model access controls (SNOWFLAKE.MODELS schema) to restrict not just which functions a role can call, but which LLMs they can use — preventing cost overruns from expensive large models.Cost alerting: Build a scheduled task that queries CORTEX_FUNCTIONS_USAGE_HISTORY and sends alerts when a role exceeds its expected AI credit budget.Call to ActionIf you’re running Cortex AI Functions in production today with the default USE AI FUNCTIONS on PUBLIC, take 15 minutes to run the audit query from Step 1. You might be surprised by who's calling what — and how much it's costing.Per-function privileges are one of those features that takes minutes to implement but saves hours of troubleshooting and thousands in unexpected AI credits. Start with the revoke-then-grant pattern, build roles around real usage data, and audit monthly.Have you implemented per-function privileges in your Snowflake environment? What role hierarchy worked best for your team? Drop a comment below — I’d love to hear your approach.All code examples in this article are based on Snowflake documentation as of May 2026. Per-function privileges for Cortex AI Functions are Generally Available.🔔 Follow on Medium → @snowflakechronicles 🔗 Connect on LinkedIn → Satish Kumar#Snowflake #DataGovernance #CortexAI #DataEngineering #CloudSecurityStop Giving Every User the Keys to Your AI Kingdom: Per-Function Privileges for Snowflake Cortex AI… was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.