CertSafari
    Snowflake SnowPro Advanced: Security Engineer (SEA-C01)· Lessons

    Domain 5 · Lesson 20/21

    Cortex AI for data security: Guard, access control, Analyst and Agents

    Leverage Snowflake Cortex AI to enhance data security.

    17 min read
    4% of exam
    13 sources
    Published 20 Oct 2026
    Docs as of 18 Oct 2026

    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.

    Cortex Guard compared with Cortex AI Guardrails
    AspectCortex GuardCortex AI Guardrails
    ScopeOne call to AI_COMPLETE / COMPLETE / TRY_COMPLETEWhole account: CoCo, Snowflake CoWork, Cortex Agents
    How it is enabledguardrails option in the requestALTER ACCOUNT SET AI_SETTINGS
    Threat addressedPotentially harmful model outputPrompt injection and jailbreak attacks
    Audit trailBilled with the function callCORTEX_AI_GUARDRAILS_USAGE_HISTORY, agent traces, CoCo conversation logs
    Enabling account-level Cortex AI Guardrails (not Cortex Guard)sql
    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
    $$;

    Checkpoint 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?

    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?

    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?

    Sources1234

    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.

    Removing the default account-wide accesssql
    REVOKE DATABASE ROLE SNOWFLAKE.CORTEX_USER FROM ROLE PUBLIC;
    Granting CORTEX_USER through a dedicated account rolesql
    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?

    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)

    0 of 2 selected

    Sources5671

    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.

    Cortex functions useful for sensitive free text
    FunctionWhat it returnsSecurity use
    CLASSIFY_TEXT / AI_CLASSIFYA label from your category listTag rows by sensitive category for review or masking
    AI_FILTERTrue or False for a text or image inputKeep only rows matching a natural-language condition, inside WHERE
    AI_REDACTText with PII redactedStrip 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.

    Sources85

    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.

    Retrieving Analyst request logs for one semantic model or viewsql
    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.

    Where each Cortex feature records audit data
    FeatureTrace or log locationUsage view
    Cortex Analyst (direct)SNOWFLAKE.LOCAL.CORTEX_ANALYST_REQUESTS_RAWCORTEX_ANALYST_USAGE_HISTORY
    Cortex AgentsSNOWFLAKE.LOCAL.AI_OBSERVABILITY_EVENTSCORTEX_AGENT_USAGE_HISTORY
    Cortex Search (REQUEST_LOGGING on)AI_OBSERVABILITY_EVENTS via GET_AI_OBSERVABILITY_EVENTSCORTEX_SEARCH_DAILY_USAGE_HISTORY
    AI_COMPLETE, AI_CLASSIFYNo tracesCORTEX_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.

    Sources9104

    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.

    Requests flagged by Cortex AI Guardrails in the last 72 hourssql
    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;

    Sources1112134

    Sources

    (13)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 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. 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. 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. 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. 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. 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. 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. 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. 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. 10.
      “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. 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. 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

    Ready to test yourself?

    Practise the 15 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.