How it works
The first governance question a Gen AI program faces is which models are allowed to run at all. Snowflake exposes two distinct mechanisms that work together:
- The account-level allowlist parameter
CORTEX_MODELS_ALLOWLIST(covered in depth in the next section). - The application-role pattern of granting
USAGEon specific Cortex SQL functions or on wrapper UDFs that pin a single model identifier.
The allowlist answers "which models is anyone in this account ever allowed to invoke", and the role pattern answers "which of those allowed models does this team or workload actually get to call". A well-governed deployment uses both, because a single allowlist value applied to the whole account is too coarse for a multi-team data platform where the analytics team should call llama3.1-8b but the legal review pipeline must only call mistral-large2.
The application-role pattern starts with the observation that AI_COMPLETE, SNOWFLAKE.CORTEX.COMPLETE, AI_CLASSIFY, AI_EXTRACT, and every other Cortex function takes the model name as an argument, not as a privilege. Granting USAGE on the function surface gives a role the ability to call any model that is allowed at the account level.
To pin a team to a specific model the deployment exposes a wrapper UDF that internally calls Cortex with a hard-coded model identifier, then grants the role USAGE on the wrapper rather than on the underlying Cortex function. The wrapper UDF is owned by SECURITYADMIN or a delegated application role and runs with EXECUTE AS OWNER, which means it can name a model the calling role would not be allowed to invoke directly. The calling role only sees the wrapper signature, never the model string.
A typical wrapper layout reserves a database for governance, say GOVERNANCE_DB.CORTEX_WRAPPERS, owned by the security application role.
Inside this database one wrapper UDF exists per approved model and task pair.
- The legal review function takes a contract string and returns a JSON classification, hard-coded to
mistral-large2. - The customer-support summarizer takes a transcript and returns a short summary, hard-coded to
llama3.1-8b. - The marketing draft generator is a wrapper around
claude-3-5-sonnet.
Each wrapper sets its own context-window cap by truncating its input to a documented maximum token budget before calling Cortex, which is the cheapest hallucination prevention available because it removes ambiguous overhang from the prompt.
💡 Exam Trap: Granting
USAGEonSNOWFLAKE.CORTEX.COMPLETEdoes not restrict which model the caller can name. A role withUSAGEon the function surface and no other governance can pass any model string that the account allowlist permits. To pin a role to a single model you must wrap the call and grant on the wrapper, or you must rely on the account-level allowlist to remove the unwanted model entirely.
Cortex Analyst cost considerations
Cortex Analyst pricing is structured as a per-message charge that bundles the underlying LLM calls Analyst issues to translate a natural-language question into SQL.
Each user message billed by Cortex Analyst covers the orchestration calls Analyst makes against its internal model graph plus the final SQL generation.
Multi-turn conversations bill per message in the conversation, not per call inside the orchestration.
The implication for governance is that an Analyst stop word, an unwarranted clarifying question, or a session that loops because of a malformed Semantic View costs the same as a session that returns a clean SQL answer.
A governance program treats Analyst spend as a budget over messages, sets a per-role daily message ceiling through a wrapper or an event-table trigger, and audits sessions where the message count per user question exceeds two.
In practice
The token-cost surface of Cortex AI functions is different.
Every direct AI_COMPLETE, AI_CLASSIFY, AI_EXTRACT, AI_SUMMARIZE_AGG, AI_TRANSLATE, and AI_AGG call bills against input tokens (the prompt plus context) and output tokens (the completion).
Snowflake publishes per-model token pricing in its Service Consumption Table and bills the AISQL meter accordingly.
The single largest lever a developer has on AISQL spend is prompt length:
- stripping boilerplate,
- removing redundant context,
- and trimming examples reduces the input token count linearly.
The second lever is model choice: a llama3.1-8b call costs a fraction of a claude-3-5-sonnet call for the same token budget, and Snowflake exposes the price differential through the Service Consumption Table.
The third lever is AI_COUNT_TOKENS, a helper function from the previous chapter that returns the token count for a string against a named model, letting a pipeline pre-check input size before billing a call.
A working governance pattern for AISQL cost control is the truncation wrapper:
- every wrapper UDF calls
AI_COUNT_TOKENSon its input, - raises a custom exception if the input exceeds the budget,
- and only forwards the call to Cortex when the count is safe.
This prevents a misconfigured pipeline from streaming megabytes of text into a claude-3-5-sonnet call accidentally.
Pair this with a session-level query tag that names the wrapper, and the AISQL_USAGE_HISTORY view can attribute every dollar to a wrapper, a model, and the calling role.
📊 Limit: Per the Snowflake Service Consumption Table for AISQL pricing, AISQL spend is metered per million input tokens and per million output tokens at a per-model rate published in the table. The model identifiers, rates, and the rate ratios between small models (llama3.1-8b, mixtral-8x7b) and frontier models (claude-3-5-sonnet, claude-3-7-sonnet, mistral-large2) are versioned in the table; the exact unit rates are subject to revision and must be quoted from the live table in any customer-facing design.
-- Wrapper UDF that pins legal review to mistral-large2 and caps input tokens.
CREATE OR REPLACE FUNCTION governance_db.cortex_wrappers.classify_legal_clause(clause_text STRING)
RETURNS VARIANT
LANGUAGE SQL
EXECUTE AS OWNER
AS
$
SELECT CASE
WHEN SNOWFLAKE.CORTEX.COUNT_TOKENS('mistral-large2', clause_text) > 4000 THEN
OBJECT_CONSTRUCT('error', 'INPUT_TOO_LONG', 'token_count',
SNOWFLAKE.CORTEX.COUNT_TOKENS('mistral-large2', clause_text))
ELSE
SNOWFLAKE.CORTEX.COMPLETE(
'mistral-large2',
ARRAY_CONSTRUCT(
OBJECT_CONSTRUCT('role','system','content','Return only valid JSON.'),
OBJECT_CONSTRUCT('role','user','content',clause_text)
),
OBJECT_CONSTRUCT(
'response_format', OBJECT_CONSTRUCT(
'type','json',
'schema', PARSE_JSON('{"type":"object","properties":{"risk":{"type":"string"},"category":{"type":"string"}},"required":["risk","category"]}')
),
'max_tokens', 512
)
)
END
$;
GRANT USAGE ON FUNCTION governance_db.cortex_wrappers.classify_legal_clause(STRING)
TO APPLICATION ROLE legal_review_app;
-- Pre-flight token check used by a pipeline before issuing a Cortex call.
SELECT
SNOWFLAKE.CORTEX.COUNT_TOKENS('claude-3-5-sonnet', transcript) AS input_tokens,
CASE WHEN SNOWFLAKE.CORTEX.COUNT_TOKENS('claude-3-5-sonnet', transcript) > 90000
THEN 'BUDGET_EXCEEDED' ELSE 'OK' END AS status
FROM raw.support_transcripts
WHERE created_date = '2099-01-01';
⚠️ Anti-Pattern: Granting
USAGEonSNOWFLAKE.CORTEX.COMPLETEto a broad analyst role and relying on developer discipline to pick the cheaper model. Developers under deadline pressure pick the strongest available model, AISQL spend climbs without explanation, and the only way to attribute it is to back-fit query tags after the fact. Pin the model in a wrapper, grant on the wrapper, and the per-model spend is fixed by definition.
💡 Exam Trap: The
max_tokensparameter onAI_COMPLETEcaps output tokens only; it does not bound input tokens or the prompt body. A 80,000-token prompt withmax_tokens=128still bills for the 80,000 input tokens. Token budgeting on the input side must useAI_COUNT_TOKENSorSNOWFLAKE.CORTEX.COUNT_TOKENS, not the completion cap.
The Decision Anchor for model-restriction design:
- Choose the application-role wrapper pattern when teams must be pinned to specific models or specific cost profiles, because it gives per-team granularity and reuses the account allowlist as a safety net.
- Choose the account-level allowlist alone when the account is single-tenant and one approved model set fits every workload.
- Combine both when the account hosts multiple business units and at least one of them must run a different model from the global approval list.
🎯 Scenario: A bank deploys Cortex for two workloads: a customer-service summary pipeline (high volume, latency-sensitive, small token budgets) and a legal contract review pipeline (low volume, accuracy-critical, large context windows). The account allowlist permits
llama3.1-8b,mistral-large2, andclaude-3-5-sonnet. Without wrappers the customer-service team could callclaude-3-5-sonnetfor every short summary, doubling spend without measurable quality gains. The team builds two wrappers:support_summary(transcript)pinned tollama3.1-8bwithmax_tokens=256and a 6,000-input-token cap, andlegal_review(clause)pinned tomistral-large2. Each wrapper sets a query tag naming the workload. After thirty days the AISQL_USAGE_HISTORY view shows 87% of calls routed tollama3.1-8b, with the legal workload contained inside its own model identifier, and the per-workload cost is auditable on a single grouped query.
