What you will be able to do
- Turn on Cortex Guard in COMPLETE or TRY_COMPLETE, and choose TRY_COMPLETE when one bad row must not abort a batch
- Tell per-request Cortex Guard apart from account-level Cortex AI Guardrails set through AI_SETTINGS
- Limit who can call Cortex functions by revoking CORTEX_USER from PUBLIC and granting it, or a narrower database role, to named roles
- Use CLASSIFY_TEXT, AI_CLASSIFY, AI_FILTER and AI_REDACT for sensitive categories in free text
- Secure Cortex Analyst semantic models and Cortex Agent tools under RBAC, and audit their questions, generated SQL and traces
Key concept
Caller-governed AI access — Every Cortex surface reaches data through the privileges of the role that makes the call. Guard filters what the model says, but the role grants decide what the model can see and run, and those grants are the main security control.
1.Filtering unsafe LLM output with Cortex Guard and TRY_COMPLETE
Generating text with an LLM inside SQL is a content-safety risk. A summarisation job over customer tickets can return violent, hateful or self-harm content straight into a reporting table. Cortex Guard is the control for this. It is an option of SNOWFLAKE.CORTEX.COMPLETE (and of its successor AI_COMPLETE). It checks each model response before the response reaches your application, and it filters responses tied to violent crimes, hate, sexual content, self-harm and similar categories. Guard tokens are billed on top of the completion itself.
Guard is switched on for each call, never per account. You set guardrails to TRUE inside the options object, alongside temperature, max_tokens and response_format. Passing options also changes how the call behaves. The prompt argument must now be an array of role/content message objects in chronological order, not a bare string. The return value becomes a JSON string with choices, created, model and usage keys, unless you also set response_format. Even an empty {} causes this switch, so code that parses the output has to change when you add Guard.
TRY_COMPLETE solves a separate problem: what happens when a row cannot be completed. It does the same work as COMPLETE, but where COMPLETE raises an error, TRY_COMPLETE returns NULL. In a single INSERT ... SELECT over two million rows, one error from COMPLETE aborts the whole statement. With TRY_COMPLETE plus 'guardrails': true, a row that is filtered or fails comes back as NULL, the other rows still load, and a later WHERE ... IS NOT NULL drops the empties. A SQL scripting EXCEPTION handler cannot do the same thing, because the error has already ended the statement it would wrap. A regex over the output column applies none of Guard's classifiers.
Cortex Guard is easy to confuse with Cortex AI Guardrails, which is a separate feature. Guardrails is configured once per account by ACCOUNTADMIN through the AI_SETTINGS parameter. It protects CoCo, Snowflake CoWork and Cortex Agents against prompt injection and jailbreaks, and it does not cover the Cortex REST API. It also requires cross-region inference to be enabled.
| Aspect | Cortex Guard | Cortex AI Guardrails |
|---|---|---|
| Scope | One call to AI_COMPLETE / COMPLETE / TRY_COMPLETE | Whole account: CoCo, Snowflake CoWork, Cortex Agents |
| How it is enabled | guardrails option in the request | ALTER ACCOUNT SET AI_SETTINGS |
| Threat addressed | Potentially harmful model output | Prompt injection and jailbreak attacks |
| Audit trail | Billed with the function call | CORTEX_AI_GUARDRAILS_USAGE_HISTORY, agent traces, CoCo conversation logs |
ALTER ACCOUNT SET AI_SETTINGS = $$
guardrails:
advanced_prompt_injection:
- enabled: true
$$;Checkpoint 1 of 9· Fill the gap
An ACCOUNTADMIN wants account-wide protection for Cortex Agents and Snowflake CoWork against jailbreaks and injected instructions hidden in tool outputs. Which key completes this statement?
ALTER ACCOUNT SET AI_SETTINGS = $$
guardrails:
? :
- enabled: true
$$;Account-level Cortex AI Guardrails, set through AI_SETTINGS, defend against prompt injection and jailbreaks. Filtering harmful model output is a different feature: Cortex Guard, the per-request guardrails option of COMPLETE, TRY_COMPLETE and AI_COMPLETE.
Source: docs.snowflake.comCheckpoint 2 of 9· Check yourself
A single INSERT ... SELECT summarises two million support tickets with an LLM. The job must drop unsafe output, and one bad row must not abort the whole load. Which approach meets both requirements?
TRY_COMPLETE returns NULL where COMPLETE would raise an error, so the other rows still load. Guard filters unsafe output only when the guardrails option is set to TRUE. An EXCEPTION handler can't help because the error has already ended the statement it wraps.
“Performs the same operation as the COMPLETE function but returns NULL instead of raising an error when the operation cannot be performed.”Source: docs.snowflake.com
Checkpoint 3 of 9· Exam question
A nightly job runs INSERT INTO summaries SELECT id, SNOWFLAKE.CORTEX.COMPLETE('mistral-large2', prompt) FROM tickets over 2 million rows. One unsafe or failing row aborts the whole statement. Security wants unsafe model output blocked and the batch to continue. What should the engineer change?
Correct answer: C — Call TRY_COMPLETE with an options object setting 'guardrails': true, so filtered or failed rows return NULL and a later predicate can drop them.
- A. Incorrect: setting
guardrailsto false disables Cortex Guard, and a regular expression is not the Cortex Guard model. Such a pattern filter would miss most harmful content. - B. Incorrect: an EXCEPTION block works per statement, not per row, so one rejected row still aborts the INSERT. It also cannot retry a single row inside a set-based SELECT.
- C. Correct: TRY_COMPLETE returns NULL instead of raising an error, and the
guardrailsoption enables Cortex Guard filtering. Filtered rows become NULL, so the batch completes and a WHERE clause removes them. - D. Incorrect: the
guardrailsoption defaults to FALSE, so a call without options performs no Cortex Guard filtering. TRY_COMPLETE only changes error handling, not safety filtering.
Checkpoint 4 of 9· Exam question
An analyst runs COMPLETE and TRY_COMPLETE on the same prompt with guardrails enabled, and Cortex Guard filters the model response. Which statement describes what each function does?
Correct answer: D — COMPLETE raises an error for the filtered response, while TRY_COMPLETE returns NULL for that row so the query keeps running without an exception.
- A. Incorrect: this reverses the behavior. NULL-on-failure is the defining trait of TRY_COMPLETE, and COMPLETE is the one that raises.
- B. Incorrect: neither function substitutes a placeholder string. A filtered response is surfaced as an error or as NULL depending on the function.
- C. Incorrect: Cortex Guard withholds the response rather than annotating it. No
filteredflag exists that lets the caller receive the unsafe text. - D. Correct: COMPLETE raises errors when it cannot complete the operation, while TRY_COMPLETE converts the failure, including a Cortex Guard filter, into NULL. That makes TRY_COMPLETE the fault-tolerant choice for batch work.
2.Controlling who can call Cortex functions
Calling a Cortex AI function takes two grants: the account-level USE AI FUNCTIONS privilege and one of the SNOWFLAKE.CORTEX_USER or SNOWFLAKE.AI_FUNCTIONS_USER database roles. In a fresh account almost everyone already has the database role, because CORTEX_USER is granted to PUBLIC, and PUBLIC is granted to every user and role.
Restricting access takes two steps, both run as ACCOUNTADMIN. First, revoke the default grant from PUBLIC. Then grant the database role to a custom role or an existing team role, such as analyst. Database roles cannot be granted directly to users, so a user gets access through an account role.
REVOKE DATABASE ROLE SNOWFLAKE.CORTEX_USER FROM ROLE PUBLIC;USE ROLE ACCOUNTADMIN;
CREATE ROLE cortex_user_role;
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE cortex_user_role;
GRANT ROLE cortex_user_role TO USER some_user;CORTEX_USER is broad: it covers every Covered AI feature. When a team needs only part of that, grant a narrower database role. AI_FUNCTIONS_USER allows the scalar AI functions but not Cortex Agents, Analyst, Fine-tuning or Search. CORTEX_ANALYST_USER and CORTEX_AGENT_USER each open a single service.
Two other controls can look like the answer but do not limit who can call Cortex. CORTEX_ENABLED_CROSS_REGION sets the regions where inference may run (ANY_REGION, AWS_US, AWS_EU and so on), so it is a data-residency setting. The shared SNOWFLAKE database is not the access gate either. Revoking IMPORTED PRIVILEGES ON DATABASE SNOWFLAKE from PUBLIC also removes PUBLIC's access to ACCOUNT_USAGE views and other objects, so run it only if you mean to restrict all of that.
Checkpoint 5 of 9· Check yourself
After a security review, only the data-science team should be able to call Cortex AI functions in a new account. Everyone else should lose access, and nothing unrelated should break. What should the ACCOUNTADMIN do?
CORTEX_USER is granted to PUBLIC by default, so access must be revoked from PUBLIC and then granted through an account role. A database role cannot be granted directly to a user. CORTEX_ENABLED_CROSS_REGION controls where inference runs, not who can call it. Revoking IMPORTED PRIVILEGES also takes away PUBLIC's access to ACCOUNT_USAGE views and other objects.
“If you don't want all users to have this privilege, you can revoke access to the PUBLIC role and grant access to specific roles.”Source: docs.snowflake.com
Checkpoint 6 of 9· Exam question
A security administrator finds that every user in the account can call Cortex LLM functions because the CORTEX_USER database role was inherited through PUBLIC. Only members of ANALYST_ROLE should be allowed to call them. Which TWO actions achieve this?(Select 2)
Correct answers: A, D — Run GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE ANALYST_ROLE so that only that role carries the privilege to call the functions.; Run REVOKE DATABASE ROLE SNOWFLAKE.CORTEX_USER FROM ROLE PUBLIC so that the default account-wide access is removed.
- A. Correct: granting the CORTEX_USER database role to a specific custom role gives the intended group access. Combined with the revoke, it restricts use to that role.
- B. Incorrect: a resource monitor limits credit consumption on a warehouse and does not authorize or deny Cortex function calls by role.
- C. Incorrect: usage on the SNOWFLAKE database does not confer Cortex access. The CORTEX_USER database role carries that privilege.
- D. Correct: removing the role from PUBLIC ends the default access that every user inherits. Without this step, the targeted grant would not restrict anyone.
- E. Incorrect: the cross-region parameter controls whether requests may be processed in another region, not which roles may call functions.
3.Finding sensitive categories in free text
Sensitive data classification (automatic, custom and SYSTEM$CLASSIFY) inspects columns and assigns semantic and privacy categories. Free text is where that falls short. A support-ticket body or chat transcript can contain a credential, a health disclosure or a threat in any row. CLASSIFY_TEXT handles this case. It sorts each free-form string into categories that you define, using an LLM, so the category list is yours to write, for example credential_leak, medical_disclosure, routine_request.
The category list sets both accuracy and cost. Provide 2 to 100 unique labels. Labels are case sensitive, and so is the input. Each label can be a plain string or an object with a description and up to 20 examples. A task_description option frames the whole job. Every label, description and example counts as input tokens for every row, so a detailed taxonomy run over a large table costs real credits. Labels work best when they are descriptive and mutually exclusive, with no jargon or abbreviations. Input should be mostly plain English: code snippets and logs reduce accuracy without raising an error, which makes raw machine logs a poor fit.
| Function | What it returns | Security use |
|---|---|---|
| CLASSIFY_TEXT / AI_CLASSIFY | A label from your category list | Tag rows by sensitive category for review or masking |
| AI_FILTER | True or False for a text or image input | Keep only rows matching a natural-language condition, inside WHERE |
| AI_REDACT | Text with PII redacted | Strip personal data before text is shared or summarised |
Use system classification for structured columns and CLASSIFY_TEXT for categories that only show up in prose. CLASSIFY_TEXT needs the SNOWFLAKE.CORTEX_USER database role. For new work, AI_CLASSIFY is the canonical function, and CLASSIFY_TEXT is kept for backward compatibility.
Checkpoint 7 of 9· Match them up
Match each Cortex function to the security job it does on free-text support tickets
Tap a term, then the definition that fits it.
AI_CLASSIFY (and the legacy CLASSIFY_TEXT) picks a label from categories you define. AI_FILTER returns a boolean for filtering, and AI_REDACT strips PII. None of these filters harmful generated output. That is Cortex Guard, the per-request guardrails option of AI_COMPLETE.
“AI_CLASSIFY: Classifies text or images into user-defined categories.”Source: docs.snowflake.com
4.Securing and auditing Cortex Analyst
Cortex Analyst turns natural-language questions into SQL. The generated SQL runs under the caller's role, so RBAC, masking and row access still apply to every result. The model sees the semantic model's metadata, such as table names, column names and descriptions, and uses it only to generate SQL. The SQL then runs in your own warehouse. Because of that, the semantic model is the main security object: it decides which tables Analyst can reach at all.
Calling Analyst takes CORTEX_USER or the narrower CORTEX_ANALYST_USER role. The caller also needs SELECT on every table the model references, USAGE on any Cortex Search service it names, and READ or WRITE on the stage that holds a YAML model. That stage privilege is how you scope legacy YAML models: keep each model in a stage and grant access to the stage. Semantic Views, the recommended approach, are schema-level objects with native RBAC, and they can mark facts and metrics as public or private to control visibility.
Every request is logged with the user, the question, the generated SQL, errors and warnings, and the request and response bodies. This is the record to check when you need to know who asked what and which SQL actually ran. Logs appear 1 to 2 minutes after the request. Viewing them takes SELECT on the referenced tables plus MONITOR or OWNERSHIP on the semantic view, or WRITE on the stage for a YAML model.
SELECT * FROM TABLE(
SNOWFLAKE.LOCAL.CORTEX_ANALYST_REQUESTS(
'<semantic_model_or_view_type>',
'<semantic_model_or_view_name>'
)
);Analyst and the other Cortex features store their logs in different places, and Event tables and external observability/SIEM integration covers how to ship any of them out. Direct Analyst calls write to SNOWFLAKE.LOCAL.CORTEX_ANALYST_REQUESTS_RAW. When an agent calls Analyst as a tool, that step lands in AI_OBSERVABILITY_EVENTS as part of the agent trace. Built-in functions such as AI_COMPLETE write no traces at all; only credits and tokens appear, in CORTEX_AI_FUNCTIONS_USAGE_HISTORY.
| Feature | Trace or log location | Usage view |
|---|---|---|
| Cortex Analyst (direct) | SNOWFLAKE.LOCAL.CORTEX_ANALYST_REQUESTS_RAW | CORTEX_ANALYST_USAGE_HISTORY |
| Cortex Agents | SNOWFLAKE.LOCAL.AI_OBSERVABILITY_EVENTS | CORTEX_AGENT_USAGE_HISTORY |
| Cortex Search (REQUEST_LOGGING on) | AI_OBSERVABILITY_EVENTS via GET_AI_OBSERVABILITY_EVENTS | CORTEX_SEARCH_DAILY_USAGE_HISTORY |
| AI_COMPLETE, AI_CLASSIFY | No traces | CORTEX_AI_FUNCTIONS_USAGE_HISTORY |
Checkpoint 8 of 9· Match them up
An auditor is tracing natural-language questions and AI calls across several Cortex workloads. Pair each workload with where its audit record actually lives.
Tap a term, then the definition that fits it.
Direct Analyst requests are logged in their own table, CORTEX_ANALYST_REQUESTS_RAW. An Analyst step only shows up in AI_OBSERVABILITY_EVENTS when an agent calls it, as part of the agent trace. Search writes there only when request logging is on. Built-in functions write no traces, only usage rows.
“Cortex Analyst stores direct Analyst request and response telemetry in SNOWFLAKE.LOCAL.CORTEX_ANALYST_REQUESTS_RAW, not in the shared AI observability event table.”Source: docs.snowflake.com
5.Running Cortex Agents for security and governance workflows
A Cortex Agent is a schema-level object that bundles a model, instructions and tools. It plans, calls tools, reflects on the results and responds. For security work, the tools set the agent's reach. Analyst over a semantic view can answer questions about access history. Cortex Search can retrieve policy documents. Custom tools built from stored procedures and UDFs can call backend systems or apply your own logic, such as opening a ticket. An agent with no tools can still chat, but it cannot query anything in the account.
Permissions come from the request's Snowflake context. If the caller's role cannot use a tool, the run carries on with the tools it can use. Grant CORTEX_AGENT_USER to open Agents alone. Make the agent secure so non-owner roles cannot read its specification. Remember that web search and MCP connectors send requests over the public internet, unlike tools that run inside Snowflake.
Agents can also work over governance metadata. CoCo uses catalog context to write SQL, trace lineage and review governance posture, and Cortex writes table and column descriptions from metadata and sample data. That is the AI-assisted side of Snowflake Horizon Catalog. Access to metadata is granted separately from access to data, so a role can review catalog posture without being able to query the rows. When agents do query data, the same RBAC, masking and row-access policies apply to them as to people.
Audit agents in two places. Threads, turns and execution spans go automatically to SNOWFLAKE.LOCAL.AI_OBSERVABILITY_EVENTS, and you can review them in Snowsight under AI & ML » Agents, in the Observability pane. Trace delivery is best effort, so base spend reporting on CORTEX_AGENT_USAGE_HISTORY. If AI Guardrails is enabled, each scan is recorded in Account Usage, and flagged requests have GUARDRAILS_SIGNAL = TRUE. Expect some false positives and review them regularly.
SELECT *
FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_AI_GUARDRAILS_USAGE_HISTORY
WHERE GUARDRAILS_SIGNAL = TRUE
AND USAGE_TIME >= DATEADD('hour', -72, CURRENT_TIMESTAMP())
LIMIT 100;Checkpoint 9 of 9· Fill the gap
During a weekly review, a security engineer wants to list the Cortex Agent requests from the last three days that account-level AI Guardrails flagged as possible prompt injection. Which Account Usage view completes the query?
SELECT *
FROM SNOWFLAKE.ACCOUNT_USAGE. ?
WHERE GUARDRAILS_SIGNAL = TRUE
AND USAGE_TIME >= DATEADD('hour', -72, CURRENT_TIMESTAMP())
LIMIT 100;When AI Guardrails is enabled, every scan is recorded in CORTEX_AI_GUARDRAILS_USAGE_HISTORY, and flagged requests have GUARDRAILS_SIGNAL = TRUE. CORTEX_AGENT_USAGE_HISTORY is where agent spend is reported, and CORTEX_AI_FUNCTIONS_USAGE_HISTORY only holds credits and tokens for built-in functions such as AI_COMPLETE. Neither one records guardrail scans.
Source: docs.snowflake.comSources
(13)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Users with the ACCOUNTADMIN role can configure Cortex AI Guardrails.”
↩︎ Filtering unsafe LLM output with Cortex Guard and TRY_COMPLETE“The account parameter CORTEX_ENABLED_CROSS_REGION must be set to ANY_REGION, AWS_US, AWS_EU, AWS_JP, AWS_APJ, or AWS_GLOBAL.”
↩︎ Controlling who can call Cortex functions - 2.
“Cortex Guard works by evaluating the responses of a language model before that output is returned to the application.”
↩︎ Filtering unsafe LLM output with Cortex Guard and TRY_COMPLETE“language model responses which may be associated with violent crimes, hate, sexual content, self-harm, and more are automatically filtered.”
↩︎ Filtering unsafe LLM output with Cortex Guard and TRY_COMPLETE - 3.
“Performs the same operation as the COMPLETE function but returns NULL instead of raising an error when the operation cannot be performed.”
↩︎ Filtering unsafe LLM output with Cortex Guard and TRY_COMPLETE“If options is present, the argument must be an array of objects representing a conversation in chronological order.”
↩︎ Filtering unsafe LLM output with Cortex Guard and TRY_COMPLETE“affects how the prompt argument is interpreted and how the response is formatted”
↩︎ Filtering unsafe LLM output with Cortex Guard and TRY_COMPLETE“guardrails: Filters potentially unsafe and harmful responses from a language model using Cortex Guard. Either TRUE or FALSE. Default: FALSE”
↩︎ Exam trap 1“guardrails: Filters potentially unsafe and harmful responses from a language model using Cortex Guard. Either TRUE or FALSE. Default: FALSE”
↩︎ Prediction - 4.
“They do not apply to the Cortex REST API or TruLens External Agents.”
↩︎ Filtering unsafe LLM output with Cortex Guard and TRY_COMPLETE“Built-in functions such as AI_COMPLETE and AI_CLASSIFY do not write traces to the observability event table.”
↩︎ Securing and auditing Cortex Analyst“Trace delivery is best effort, so totals computed from the event table can under-report consumption.”
↩︎ Running Cortex Agents for security and governance workflows“That per-request option is distinct from account-level Cortex AI Guardrails configured through AI_SETTINGS.”
↩︎ Exam trap 2“Cortex Analyst stores direct Analyst request and response telemetry in SNOWFLAKE.LOCAL.CORTEX_ANALYST_REQUESTS_RAW, not in the shared AI observability event table.”
↩︎ Exam trap 4“Cortex Analyst stores direct Analyst request and response telemetry in SNOWFLAKE.LOCAL.CORTEX_ANALYST_REQUESTS_RAW, not in the shared AI observability event table.”
↩︎ Checkpoint - 5.
“your role needs the USE AI FUNCTIONS account-level privilege and one of the CORTEX_USER or AI_FUNCTIONS_USER database roles.”
↩︎ Controlling who can call Cortex functions“AI_REDACT: Redact personally identifiable information (PII) from text.”
↩︎ Finding sensitive categories in free text“AI_CLASSIFY: Classifies text or images into user-defined categories.”
↩︎ Checkpoint - 6.
“By default, the CORTEX_USER database role is granted to the PUBLIC role, which is automatically granted to all users and roles.”
↩︎ Controlling who can call Cortex functions“Only run this command if you intend to restrict all of that access.”
↩︎ Controlling who can call Cortex functions“By default, the CORTEX_USER database role is granted to the PUBLIC role, which is automatically granted to all users and roles.”
↩︎ Exam trap 3 - 7.
“without granting access to Cortex services such as Cortex Agent, Cortex Analyst, Cortex Fine-tuning, or Cortex Search.”
↩︎ Controlling who can call Cortex functions - 8.
“Classifies free-form text into categories that you provide.”
↩︎ Finding sensitive categories in free text“Must contain at least two and at most 100 unique categories. Categories are case sensitive.”
↩︎ Finding sensitive categories in free text“try to limit content such as code snippets or logs in the text input.”
↩︎ Finding sensitive categories in free text“For new use cases, start with AI_CLASSIFY, which is the canonical surface going forward.”
↩︎ Finding sensitive categories in free text - 9.
“ensuring that SQL queries generated and executed adhere to all established access controls.”
↩︎ Securing and auditing Cortex Analyst“CORTEX_USER provides access to all Covered AI features, while CORTEX_ANALYST_USER provides access only to Cortex Analyst.”
↩︎ Securing and auditing Cortex Analyst“To control access to specific semantic models, you can store the YAML file in a stage and control access to that stage.”
↩︎ Securing and auditing Cortex Analyst“Access modifiers: Mark facts and metrics as public or private to control visibility”
↩︎ Securing and auditing Cortex Analyst“If you don't want all users to have this privilege, you can revoke access to the PUBLIC role and grant access to specific roles.”
↩︎ Checkpoint - 10.https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-analyst/admin-observabilityOfficial docs
“This table function performs access control checks to ensure that the caller has required privileges to access the request data.”
↩︎ Securing and auditing Cortex Analyst - 11.
“Custom tools built from stored procedures and user-defined functions (UDFs) to call backend systems or implement your own business logic.”
↩︎ Running Cortex Agents for security and governance workflows“Secure agents hide the specification from non-owner roles.”
↩︎ Running Cortex Agents for security and governance workflows“Tools that reach external services, such as web search and MCP connectors, send requests over the public internet.”
↩︎ Running Cortex Agents for security and governance workflows“Data access is governed by Snowflake privileges and the execution context of each configured tool.”
↩︎ Key concept“Data access is governed by Snowflake privileges and the execution context of each configured tool.”
↩︎ Prediction - 12.
“Snowflake CoCo, which uses catalog context when it writes SQL, traces lineage, or reviews governance posture.”
↩︎ Running Cortex Agents for security and governance workflows - 13.
“Metadata access in Horizon Catalog is separate from data access.”
↩︎ Running Cortex Agents for security and governance workflows