Cortex AI Cookbook

The Cortex AI Cookbook collects deployment patterns for Cortex AI, drawn from real Snowflake deployments. Each recipe explains the design and the security model, then gives you verified code to run in your own account and adapt.

Every recipe follows the same shape:

  • When to use this: the problem the pattern solves, and when a simpler option is better.
  • How it works: the architecture and the security model.
  • Quickstart and walkthrough: numbered SQL scripts that build the pattern, with a teardown script that removes everything.
  • Verify: queries that prove the pattern works in your account.

Each recipe has a code page that shows every file, and a zip file with all of them to download. Each recipe is a reference implementation: review it and adapt it to your environment before production use.

Recipes

Recipes follow the AI lifecycle, in reading order: start at Scope and work through to Operate. Select stages to filter.

RecipeStageTopicsStatus
Scoping agentic implementations: from 'talk to your data' to a testable agent spec

A workshop method for turning a broad agent idea into personas, a question taxonomy, a registered evaluation dataset, and a phased delivery plan.

ScopeEvaluateCortex AgentsAI ObservabilityCortex AI FunctionsGA
Snowflake-managed MCP or the Cortex Agents REST API

Decide how people reach a Cortex Agent, with identity and policies in each lane, then best practices for managed MCP servers and the Agents REST API.

ScopeSecureBuildSnowflake MCPCortex AgentsGA
Agentic schema mapping: messy CSVs to canonical tables with a Cortex Agent

A Cortex Agent profiles messy CSV files, proposes column mappings with AI_COMPLETE, resolves free-text values, and loads approved mappings through allowlisted SQL.

BuildCortex AI FunctionsCortex AgentsGA
Embedded app context for a Cortex Agent

Give an agent embedded in a Streamlit dashboard the page, filters, and persona the user is looking at, by prepending an app-context block to the user message.

BuildCortex AgentsGA
Attach documents to Cortex Agent conversations

Let users attach PDFs, Office files, images, and CSVs to a custom agent frontend with a caller's-rights document tool, per-user stage folders, and authenticated middleware.

BuildSecureCortex AgentsGA
Multi-agent orchestration with a CoWork profile

One Snowflake CoWork profile routes to specialist agents with the agent_router tool, so Snowflake grants decide which specialist each user reaches.

BuildSecureCortex AgentsSemantic ViewsPreview
PII redaction with AI_REDACT, AI_COMPLETE extraction, and an entity cache

Redact PII in free text with AI_REDACT, cover domain identifiers with AI_COMPLETE structured extraction, and serve redactions from a stream-maintained cache.

BuildSecureCortex AI FunctionsGA
Causally grounded Cortex Agent that refuses when the data cannot answer

A Cortex Agent whose every number comes from a persisted causal estimator, and which declines to answer for cohorts where no honest estimate exists.

BuildEvaluateCortex AgentsSemantic ViewsGA
Mixed-grain tables: diagnose and fix wrong agent answers with a GRAIN dimension and verified queries

An agent double-counts a table that holds daily and monthly rows. Diagnose it from wrong answers, fix the semantic view with a GRAIN enum, rules, and verified queries, re-test.

BuildEvaluateSemantic ViewsCortex AgentsGA
Long-running Cortex Agent runs over managed MCP

Split one long MCP tool call into a fast submit and a bounded fetch over background agent runs, so no call nears a client's timeout and caller's rights still apply.

BuildOperateSnowflake MCPCortex AgentsGA
OAuth token passthrough to a Cortex Agent

Relay each signed-in user's Entra ID token to a Cortex Agent so the agent runs as that person, with per-user results from a row access policy on CURRENT_USER().

SecureCortex AgentsGA
Multi-tenant agents with session attributes and fail-closed policies

Serve many tenants from one Cortex Agent: the app server names the end user in an immutable session attribute, and policies derive the tenant from an entitlement.

SecureBuildCortex AgentsSemantic ViewsGA
Semantic view description quality: a rubric, a linter, and how to apply fixes

Grade semantic view descriptions on preciseness, conciseness, non-circularity, and correctness, lint them in SQL, and apply fixes with CREATE OR ALTER or the YAML procedure.

EvaluateSemantic ViewsCortex AI FunctionsGA
Evaluate and promote Cortex Agent versions

Run Cortex Agent evaluations with pinned metric versions and a custom judge, compare two committed versions, and promote the winner by alias.

EvaluateOperateCortex AgentsGA
Refine a semantic view from agent logs: triage, SME review, and verified queries

Mine Cortex Agent traces for guessed, exploratory, and no-data answers, get the right answer from a subject matter expert, ship it into the semantic view, and re-test.

EvaluateOperateSemantic ViewsAI ObservabilityCortex AgentsGA
Turn agent feedback and rephrased questions into an evaluation dataset

Mine thumbs-down feedback and user rephrases from agent traces, confirm each with one LLM call, and write a deduplicated eval dataset.

EvaluateOperateAI ObservabilityCortex AgentsGA
Agent versioning and promotion

Commit, alias, promote, A/B route, and roll back Cortex Agent versions with runnable SQL and the behaviors observed along the way.

OperateCortex AgentsGA
AI usage and cost attribution across agents, CoWork, Cortex Code, and AI functions

One reconciled view of Cortex AI credits by surface, user, agent, model, and cost center, plus budgets and per-user quotas.

OperateAI ObservabilityCortex CodeCortex AI FunctionsGA
Diagnose slow Cortex Agent requests from their traces

A caller's-rights procedure that reads one agent request's trace, computes a time breakdown by span, and returns an LLM explanation.

OperateAI ObservabilityCortex AgentsGA
Size Cortex Code per-user limits from real usage

Tiered per-user CoCo quotas, daily limits, and alert-only team budgets, starting from conservative defaults and sized from your own ACCOUNT_USAGE.

OperateAI ObservabilityCortex CodeGA
LangChain agents on Cortex AI Gateway with MCP tools and traces

External LangChain agents reason through Cortex AI Gateway, act through a Snowflake MCP server, and are analyzed from gateway traces and per-user cost.

OperateBuildCortex AI GatewaySnowflake MCPAI ObservabilityPreview
Cortex AI Gateway governance quickstart

Route an app through Cortex AI Gateway with its own identity: both API formats, a model allowlist, traces, per-user cost, and a blocking quota.

OperateSecureCortex AI GatewayAI ObservabilityPreview
Agent CI/CD with dbt: per-PR builds, versioned deploys, and an evaluation gate

dbt builds the tables and semantic view, the agent ships as a versioned spec from a stage, and an evaluation gate in GitHub Actions blocks promotion.

OperateEvaluateCortex AgentsSemantic ViewsGA