Snowflake Snowflake
Back to Industry Index

User Guide

How to Use Cortex Code in Snowsight

Step-by-step guide for running the Cortex Code Prompts for each use case directly in Snowsight. From opening the panel to deploying Streamlit dashboards in production.

1 What Is Cortex Code?

Cortex Code is the AI-powered programming assistant built into Snowsight, Snowflake's web interface. It lets you generate SQL, Python, and Streamlit code directly from natural language, accelerating the development of analytical solutions.

Key capabilities

Important: Cortex Code generates code that runs in your Snowflake account. Everything stays within your environment — no external dependencies, no data sent outside.

2 Prerequisites

Before you begin, make sure you have the following set up:

Snowflake account

Important: Ask your Snowflake representative to create the required accounts for your team. This ensures all Cortex Code and Cortex AI features are supported: ML.CLASSIFICATION, ML.FORECAST, CORTEX.COMPLETE, CORTEX.SENTIMENT, Cortex Search, and Feature Store.

Access Cortex Code in Snowsight

Once inside your account, the Cortex Code assistant panel appears on the right side of the screen. It is your AI programming companion for running all the prompts in this catalog:

Cortex Code panel in Snowsight

Ready: If you see the Cortex Code panel with the message «How can I help?» on the right, you can start copying and pasting the prompts from any use case.

Account and permissions

For advanced features

Note on regions: Some Cortex AI features (such as ML.CLASSIFICATION or CORTEX.COMPLETE) require specific regions. Check the availability documentation to verify your region.

3 Open Cortex Code in Snowsight

Cortex Code is integrated into several Snowsight surfaces. Here are the ways to access it:

Option A — From Workspaces

  1. Go to SnowsightProjectsWorkspaces
  2. Create or open an existing workspace
  3. Click the Cortex icon (✨) in the right sidebar, or use the shortcut Cmd+Shift+Space (Mac) / Ctrl+Shift+Space (Windows)
  4. The Cortex Code panel will open to the right of the editor

Tip: The Cortex Code panel maintains the context of your workspace. If you have tables referenced in the editor, Cortex Code will use them as context to generate more accurate code.

4 Add the Best-Practices Skill to Cortex Code

To improve the performance and reduce the cost of the generated code, you can add the best-practices skill to Cortex Code. Once loaded, it will be available before each prompt and will guide the assistant to generate more efficient code optimized for Snowflake.

4.1 — Download the skill

Download the compressed file containing the best-practices skill and save it to your computer:

Download best-practices.zip

4.2 — Extract locally

Extract the downloaded file on your computer. You will get a folder called best-practices containing the skill files ready to upload.

Tip: Extract to an easy-to-find location (for example, your Desktop or Downloads folder), since in the next step you will need to select it from Snowsight.

4.3 — Upload the skill to Cortex Code in Snowsight

In Snowsight, inside the Cortex Code panel, click the + button, select the «Upload Skill Folder(s)» option, and choose the best-practices folder you just extracted locally:

+ button in Cortex Code to upload a skill

Note: The + button is located at the top of the Cortex Code panel, next to the context selector. Clicking it will display a menu — select «Upload Skill Folder(s)» and navigate to where you extracted the skill.

4.4 — Use the skill before each prompt

Once uploaded, the skill will be available in your Cortex Code session. Type the /best-practices command before each prompt to activate it and get more efficient code:

/best-practices command available in Cortex Code

Ready: With the skill active, Cortex Code will automatically apply Snowflake best practices to all generated code: efficient warehouse usage, clustering keys, query optimization, and credit cost reduction.

5 Prompt Workflow

Each use case in this catalog includes between 8 and 11 sequential prompts. The recommended workflow is:

1
Choose
use case
2
View
Guide
3
Open
Cortex Code
4
Copy & paste
each prompt
5
Review &
execute

Structure of each use case

When you click «View Prompts» on any use case card, you will see:

Sequential execution: The prompts are designed to run in order. Each step depends on the objects created in the previous steps. Do not skip steps.

6 Run a Use Case Step by Step

Let's walk through the complete process with a practical example:

6.1 — Select industry and use case

  1. Go to the industry catalog
  2. Choose an industry (for example, Banking)
  3. Browse the cards or use the search bar to find a use case
  4. Read the «Problem» section to understand the business pain point

6.2 — Read the Guide

  1. Click «View Guide»
  2. Read the sections: Context, Focus, Challenge, Objectives, Features, Data, Stratification, and How to Use
  3. This will give you the conceptual framework before generating code

6.3 — Execute the Prompts

  1. Click «View Prompts»
  2. In Snowsight, open a workspace and activate Cortex Code
  3. For each step:
    • Click «Copy» on the prompt
    • Paste it into the Cortex Code panel
    • Cortex Code will generate the corresponding SQL/Python code
    • Review it before executing (see section 7)
    • Click «Run» or «Apply»
    • Verify that it executed successfully
    • Move on to the next prompt
Example-- Prompt copied from the catalog (Step 1): "Create the BANKING_FRAUD_DB database with an ANALYTICS schema and a BANKING_WH warehouse (size S). Include comments for the transactional fraud detection project." -- Cortex Code generates: CREATE DATABASE IF NOT EXISTS BANKING_FRAUD_DB COMMENT = 'Transactional fraud detection project with Cortex AI/ML'; CREATE SCHEMA IF NOT EXISTS BANKING_FRAUD_DB.ANALYTICS COMMENT = 'Main schema for fraud analytics'; CREATE WAREHOUSE IF NOT EXISTS BANKING_WH WAREHOUSE_SIZE = 'SMALL' AUTO_SUSPEND = 300 AUTO_RESUME = TRUE COMMENT = 'Warehouse for banking fraud project'; USE DATABASE BANKING_FRAUD_DB; USE SCHEMA ANALYTICS; USE WAREHOUSE BANKING_WH;

Expected result: At the end of all steps you will have: a database with synthetic data tables, trained ML models, configured Cortex AI functions, and a functional Streamlit dashboard.

7 Review and Validate the Generated Code

Cortex Code generates high-quality code, but you should always review it before executing. Key points:

Review checklist

Adapt to real data

The prompts generate synthetic data for demonstration. To move to production:

  1. Replace the synthetic CREATE TABLE ... INSERT statements with CREATE VIEW or SELECT on your real tables
  2. Adjust column names to match your data model
  3. Modify the business thresholds and parameters
  4. Keep the structure for features, models, and dashboards

Synthetic data: The generated data is fictional and representative. Do not use it in real business reports. It serves to validate the end-to-end pipeline before connecting real data.

8 Deploy Streamlit Dashboards

Nearly all use cases include a prompt to generate a Streamlit dashboard. Here is how to deploy it:

8.1 — Generate the Streamlit app

  1. Execute the «Dashboard» prompt (usually the second-to-last step)
  2. Cortex Code will generate Python code with Streamlit
  3. Go to SnowsightProjectsStreamlit

8.3 — Verify and share

  1. Check that all charts and tables load correctly
  2. If there are errors, verify that the tables and views exist (they were created in previous steps)
  3. Share the app with other users using «Share»
Typical structure# Streamlit generated by Cortex Code import streamlit as st from snowflake.snowpark.context import get_active_session session = get_active_session() st.set_page_config(page_title="Dashboard", layout="wide") # Main KPIs col1, col2, col3 = st.columns(3) with col1: st.metric("Metric 1", value1) # ... charts, tables, interactive filters

9 Automate with Tasks and Pipelines

The last prompt in each use case creates Snowflake Tasks to automate the pipeline:

What gets automated

Typical Task structure

SQL-- Weekly scoring task CREATE OR REPLACE TASK weekly_scoring WAREHOUSE = MY_WH SCHEDULE = 'USING CRON 0 6 * * 1 Europe/Madrid' COMMENT = 'Weekly ML scoring on active data' AS CALL run_scoring(); -- Activate ALTER TASK weekly_scoring RESUME;

Task DAGs: Advanced use cases create DAGs (Directed Acyclic Graphs) where some Tasks depend on others. Cortex Code automatically generates the dependencies using AFTER.

10 Check Usage Costs

After running one or more use cases, use this prompt in Cortex Code to get a consolidated summary of all credits and tokens consumed on the current day: warehouses, Cortex AI functions, ML models, and Cortex Code in Snowsight.

Prompt — Daily cost summary

Copy and paste this prompt directly into Cortex Code (remember to activate /best-practices first):

PromptGenerate a SQL query that shows a consolidated summary of all costs and consumption for the Snowflake account on the current day (CURRENT_DATE). Include the following sections: 1. WAREHOUSE CREDITS - Source: SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY - Columns: warehouse_name, SUM(credits_used) AS warehouse_credits - Filter by: DATE(start_time) = CURRENT_DATE() 2. CORTEX AI FUNCTIONS (tokens and credits) - Source: SNOWFLAKE.ACCOUNT_USAGE.CORTEX_FUNCTIONS_USAGE_HISTORY - Columns: function_name, SUM(tokens_used) AS tokens_used, SUM(credits_used) AS cortex_credits - Filter by: DATE(start_time) = CURRENT_DATE() 3. SERVERLESS ML FUNCTIONS (ML.CLASSIFICATION, ML.FORECAST, etc.) - Source: SNOWFLAKE.ACCOUNT_USAGE.METERING_DAILY_HISTORY - Filter by: service_type IN ('ML_FUNCTIONS','SNOWPARK_ML') AND DATE(usage_date) = CURRENT_DATE() - Columns: service_type, credits_used_compute AS ml_credits 4. CORTEX CODE IN SNOWSIGHT - Source: SNOWFLAKE.ACCOUNT_USAGE.METERING_DAILY_HISTORY - Filter by: service_type = 'CORTEX_CODE' AND DATE(usage_date) = CURRENT_DATE() - Columns: service_type, credits_used_compute AS cortex_code_credits 5. TOTAL SUMMARY BY SERVICE TYPE - Combine all previous results with UNION ALL - Final columns: service_type, name, tokens_used, credits_spent - Order by credits_spent DESC - Add a TOTAL row at the end with SUM of all credits Use CTEs for each section. If a view does not exist in the account, replace it with SNOWFLAKE.ACCOUNT_USAGE.METERING_DAILY_HISTORY filtering by the equivalent service_type. Add comments explaining each CTE.

Note: ACCOUNT_USAGE data has a latency of up to 45 minutes. If you just ran a use case and no data appears, wait a few minutes and rerun the query.

Alternative: If CORTEX_FUNCTIONS_USAGE_HISTORY is not available in your account, Cortex Code will automatically replace that section with METERING_DAILY_HISTORY using service_type = 'AI_SERVICES'.

11 Tips and Best Practices

Development

Cortex Code

Production

12 Frequently Asked Questions

Do I need to know SQL to use the prompts?
It's not required, but it helps. Cortex Code generates the SQL for you, but understanding the basics (CREATE TABLE, SELECT, JOIN) will allow you to review and adapt the code with confidence.
Does synthetic data consume a lot of credits?
Very little. Generating synthetic data with INSERT consumes very few credits (seconds of a size-S warehouse). The biggest consumption comes from ML training and Cortex functions, which depend on data volume.
Can I use the prompts with my real data from the start?
Yes. Replace the «Create data» steps with references to your existing tables. Make sure the column names match what the subsequent steps expect, or ask Cortex Code to adapt the code.
What should I do if a prompt generates an error?
Most commonly: (1) a previous step that creates the referenced table was not executed, (2) the warehouse is not active, (3) the Cortex function is not available in your region. Check the error message and ask Cortex Code to fix it: «This code gives error X, fix it».
How long does it take to complete a use case?
Between 8 and 15 minutes to run all the prompts with synthetic data. The time shown on each card is a realistic estimate including code review.
Can I combine use cases from different industries?
Absolutely. Many patterns are cross-industry: a customer Feature Store works the same in Banking, Retail, or Telecom. Adapt the column names and business logic.
Does Cortex Code remember previous steps?
Within the same worksheet session, yes. If you close and reopen it, you'll need to provide context again. That's why we recommend executing all steps of a use case in a continuous session.
Can I modify the prompts?
Yes, and it's encouraged. The prompts are designed as a starting point. Add your business details, adjust data volumes, change thresholds, or add domain-specific columns for more accurate results.
What's the difference between «View Guide» and «View Prompts»?
View Guide shows the conceptual framework: problem context, objectives, required data, and implementation strategy. View Prompts contains the step-by-step prompts that you copy and paste directly into Cortex Code to generate the code.
Do I need to install anything?
Almost nothing. All the code runs inside Snowsight in the browser, with no Python environments or external tools. The only prerequisite is to download the best-practices skill (the best-practices.zip file), extract it on your computer, and upload the folder to Cortex Code from the + button in Snowsight. Once uploaded, it will be available with the /best-practices command and you won't need to repeat the process.