Categories:

Context functions (General)

SYS_CONTEXT (SNOWFLAKE$CURRENT namespace)

Returns information about the current execution context in which the function is called. The current execution context can differ from the session context when the function is called inside an owner’s rights executable or during an agent invocation.

You can call this function in the following contexts:

  • You can call this function directly in the current session.
  • You can run a caller’s rights executable (for example, a caller’s rights stored procedure) that calls this function.
  • You can run an owner’s rights executable (for example, an owner’s rights stored procedure) that calls this function.

Unlike the SNOWFLAKE$SESSION namespace, calling this function in an owner’s rights executable doesn’t require the READ SESSION privilege.

In any other context, the function returns NULL.

See also:

SYS_CONTEXT , SYS_CONTEXT (SNOWFLAKE$SESSION namespace) , IS_AGENT_ACTIVATED (SYS_CONTEXT function) , IS_DATABASE_ROLE_ACTIVATED (SYS_CONTEXT function) , IS_ROLE_ACTIVATED (SYS_CONTEXT function)

Syntax

Syntax for retrieving properties:

SYS_CONTEXT(
  'SNOWFLAKE$CURRENT' ,
  '<property>'
)

Syntax for calling functions:

SYS_CONTEXT(
  'SNOWFLAKE$CURRENT' ,
  '<function>' [ , '<argument>' , ... ]
)

Arguments

'SNOWFLAKE$CURRENT'

Specifies that you want to retrieve a property or call a function to return information about the current execution context.

'property'

Name of the property that you want to retrieve. You can specify the following properties:

PropertyDescription
IS_AGENT_ACTIVATEDReturns 'TRUE' if an agent is active in the current execution context; otherwise, returns 'FALSE'. An agent is active when:

- A Snowflake first-party agent is executing the query (a named Cortex Agent, a stateless lite agent invoked via the REST API or a Snowflake CoCo client, or a query through Snowflake CoWork)
- An external agent connects through a managed MCP server
- The session was opened by a SERVICE_AGENT user
- The session uses a custom OAuth integration configured with IS_AGENTIC = TRUE

Use this property in masking policies and row access policies to restrict data access when an agent is running a query. For more details, see IS_AGENT_ACTIVATED.
'function'

Name of the function that you want to call. When called via the SNOWFLAKE$CURRENT namespace, IS_ROLE_ACTIVATED and IS_DATABASE_ROLE_ACTIVATED check the current execution context rather than the session.

You can call the following functions:

'argument' [ , ... ]

Arguments to pass to the function that you want to call.

Returns

The function returns a VARCHAR value or NULL:

2026_06 behavior change bundle

When the 2026_06 behavior change bundle is enabled in your account, SYS_CONTEXT('SNOWFLAKE$CURRENT', 'IS_ROLE_ACTIVATED', '<role>') and SYS_CONTEXT('SNOWFLAKE$CURRENT', 'IS_AGENT_ACTIVATED') return BOOLEAN. Other properties and functions in this namespace continue to return VARCHAR.

Existing casts, such as ::BOOLEAN or ::NUMBER, continue to work unchanged.

For the return type of every property and function by namespace, see SYS_CONTEXT return types.

Usage notes

  • The SNOWFLAKE$CURRENT namespace returns values for the innermost execution context. Inside an owner’s rights stored procedure, for example, this reflects the owner’s context, not the caller’s session context. Use the SNOWFLAKE$SESSION namespace if you need session-level values instead.

  • The following table summarizes when SNOWFLAKE$CURRENT and SNOWFLAKE$SESSION return different values:

    ScenarioSNOWFLAKE$CURRENTSNOWFLAKE$SESSION
    Direct query in the sessionSession contextSession context
    Inside a caller’s rights stored procedureSession contextSession context
    Inside an owner’s rights stored procedureOwner’s context (activated roles reflect the owner; no READ SESSION required)Session context (requires READ SESSION privilege)
    During an agent invocationAgent’s execution context (agent properties are populated)Session context of the invoking user
  • To simulate the values of functions in this namespace when testing policies, use the corresponding POLICY_CONTEXT arguments. For example, use SNOWFLAKE$CURRENT_ACTIVATED_ROLES to simulate the result of IS_ROLE_ACTIVATED.

  • If you are specifying the function call in a double-quoted string in a shell, escape the $ character with a backslash (\) so that $CURRENT is not interpreted as a shell variable.

Examples

The following examples demonstrate how to check whether a role or database role is active in the current execution context:

Checking role activation in the current context

The following example checks whether a role is activated in the current execution context (which may differ from the session context inside an owner’s rights executable):

SELECT SYS_CONTEXT('SNOWFLAKE$CURRENT', 'IS_ROLE_ACTIVATED', 'analyst')::BOOLEAN;

Checking database role activation in the current context

The following example checks whether a database role is activated in the current execution context:

SELECT SYS_CONTEXT('SNOWFLAKE$CURRENT', 'IS_DATABASE_ROLE_ACTIVATED', 'ANALYST_ROLE')::BOOLEAN;