Snowflake Cortex Analyst 101: Spin Up Your Own Conversational Analytics App (2025)
What if you could chat with your data in simple plain English? No more building endless dashboards or writing complex queries. Simply ask your dataset a question and get an instant, accurate answer. For years, people have relied on BI dashboards and static reports to get in-depth insights. But these tools aren't flexible. You're stuck with fixed charts and visualizations that don't adapt to your specific questions. When you need something different, you're back to bothering the data team or trying to decipher complex SQL. We are now in the AI age of conversational data analytics. Instead of clicking through messy dashboards, you can ask direct questions and get immediate answers. Well, here’s the good news if you’re a Snowflake user: you’re already sitting in a pile of next-generation AI features and services, like Snowflake Cortex Search, Snowflake Cortex Analyst, and so much more. Cortex Analyst fills this gap. It is a managed service powered by a Large Language Model that lets you ask questions in plain natural language against your Snowflake data. The best part is, it understands the context and semantics behind your data, so you don’t have to write complex queries.
In this article, we’ll cover everything you need to know about Snowflake Cortex Analyst: what it is, how it works, its current limitations, and detailed setup steps (with both SQL/CLI and Snowsight examples). Also, we’ll cover building a simple, full-fledged conversational chat-like analytics app using Snowflake Cortex Analyst and Streamlit.
Let’s jump right into it!
What is Snowflake Cortex Analyst?
Snowflake Cortex Analyst is a fully-managed, LLM powered Snowflake Cortex feature that helps you create applications capable of reliably answering business questions based on your structured data in Snowflake. It provides a talk-to-your-data interface: you send a plain-English question to a REST endpoint, and Cortex Analyst returns a direct answer (and even the SQL query it ran) without you writing any SQL.
Snowflake Cortex Analyst is an agentic AI system which is a part of Snowflake’s Cortex AI platform and uses state-of-the-art large language models under the hood. Cortex Analyst uses Snowflake-hosted Large Language Models (LLMs) like Meta Llama and Mistral. Optionally, you can also give Cortex Analyst access to Azure-hosted OpenAI GPT models. Cortex Analyst automatically selects the best model combination for each query.
Snowflake Cortex Analyst’s power comes from combining Large Language Models with Semantic Models (YAML file that sits alongside your database schema and encodes business context). An LLM on its own is like a brilliant analyst. They are very smart, but they don't know your data inside and out. It's tough for even the best analysts to write accurate SQL queries based solely on the raw schema. Raw schemas can be messy and often lack the details needed for precise data analysis. There is usually a disconnect between the vocabulary used in business users’ questions and the database schema. Business users tend to use everyday business terms, while the database schema uses more technical terms. This gap makes it hard to build a product that answers data questions accurately. Snowflake Cortex Analyst solves this problem by using Semantic Models to give LLMs the context they need to answer questions accurately.
Want to take Chaos Genius for a spin?
It takes less than 5 minutes.
🔮 Features of Snowflake Cortex Analyst
Here are some key features of Snowflake Cortex Analyst:
1) Natural-language analytics
Users can ask questions in natural language and get answers back from their Snowflake data. This frees analysts and non-technical users from writing complex queries.
2) LLM-powered.
Snowflake Cortex Analyst runs Snowflake-hosted Meta Llama and Mistral models inside Snowflake’s secure environment. (If enabled, it can also call Azure OpenAI models.) You cannot directly pick a model per query; Snowflake auto-selects the best model(s) based on your region and settings. But note that admins can restrict available models using model-level RBAC roles if needed.
3) Semantic Modeling
A Semantic Model (lightweight YAML) encodes tables, columns, relationships, and business terms. This metadata vastly improves precision in translating questions to SQL. Cortex Analyst uses all this metadata info when parsing questions.
4) REST API integration
Snowflake Cortex Analyst takes an API-first approach. It can be easily accessed via a REST endpoint. That makes it easy to call from Python, cURL, or any application (Streamlit, Slack, custom chat interfaces, and more) while Snowflake handles scaling and token management.
5) Multi-source support
You can register multiple Semantic Models (or Semantic Views) for different datasets. Snowflake Cortex Analyst can automatically route each question to the right model without you explicitly specifying it.
6) Security & governance
Snowflake respects Snowflake’s role-based access control (Snowflake RBAC). The generated SQL runs in your Snowflake Virtual Warehouse under your security rules. Snowflake explicitly states Cortex Analyst does not train on or store your data – metadata from your Semantic Model is used only to generate SQL, and then execution happens in your Snowflake account. And by default, the Large Language Models (LLMs) run entirely within Snowflake’s infrastructure, so customer data (and even prompts) stay inside Snowflake’s governance boundary.
Why use Snowflake Cortex Analyst?
It is genuinely difficult to build your own Q&A chat-like conversational analytics app from scratch. You'd have to deal with numerous challenges like natural language processing, SQL accuracy, system architecture, GPU management, and more. Snowflake Cortex Analyst simplifies things by handling all of that for you. Snowflake is in charge of the AI models, maintaining numerous agents in the background while providing precise responses and SQL queries. You don't have to reinvent the wheel, so no need to create custom RAG pipelines or LLM finetuning. And since the SQL runs on Snowflake's engine, you get the performance of a cloud warehouse - you just pay the usual Virtual Warehouse rate, plus a tiny fee for AI credits.
TL;DR: Snowflake Cortex Analyst brings enterprise-grade AI analytics to business users with minimal setup.
Which Access Control Configurations Are Necessary for Snowflake Cortex Analyst?
Before you start, make sure the proper roles and permissions are in place. Any user calling the Cortex Analyst API needs the special role SNOWFLAKE.CORTEX_USER
granted. Snowflake grants this role to PUBLIC by default, so all users initially have it. If you want to limit access, you can revoke it from PUBLIC
and grant it only to specific roles or users.
GRANT ROLE SNOWFLAKE.CORTEX_USER TO ROLE analyst_role;
-- (Alternatively, revoke SNOWFLAKE.CORTEX_USER from PUBLIC if needed)
Beyond that, if you’re using a Semantic Model, the querying role also needs privileges on the model’s resources. Specifically:
- Stage access. If you upload your model YAML to a Snowflake stage, the role needs READ (or WRITE) permission on that stage.
- Table access. The role needs SELECT on all underlying tables referenced by the Semantic Model.
- Cortex Search (optional). If your model uses a Snowflake Cortex Search service (for looking up text or documents), grant USAGE on that service.
Also, when calling the API you must authenticate with a Snowflake token. You’ll typically use the Snowflake Connector or a session token.
Quick Tip: Verify these grants. At a minimum, your working role should have USAGE on the target database and schema, plus SELECT on tables and READ on the model’s stage. Then you can safely call the Cortex Analyst API.
Can Snowflake Cortex Analyst Hold a Conversation? (Multi-Turn Queries)
Yes. Snowflake Cortex Analyst supports multi-turn Q&A, but with some caveats. You can send a conversation history so that follow-up questions build on earlier ones. For example, you might first ask, “What was last year's revenue in Europe?
” and get an answer. Then you can follow up: “What about Asia?
” By including the previous Q&A in your request (within the messages array), Cortex Analyst carries forward context and generates new SQL accordingly.
Here’s a simplified snippet of a multi-turn request body:
{
"messages": [
{"role": "user", "content": [{"type": "text", "text": "Revenue by region for Q1 2025"}]},
{"role": "assistant", "content": [
{"type": "text", "text": "Here is the revenue breakdown..."},
{"type": "statement", "statement": "SELECT region, SUM(sales) ..."}
]},
{"role": "user", "content": [{"type": "text", "text": "And how did that compare to Q2?"}]}
],
"semantic_model_file": "@mydb.public.mystage/<model_name>.yaml"
}
Snowflake Cortex Analyst will see the user’s latest question (“And how did that compare to Q2?”) and use the conversation history to interpret it. Internally, it rewrites the follow-up as a full, standalone question, then generates the SQL for it.
Limitations: Snowflake Cortex Analyst doesn’t remember. Each new request is stateless for the LLM; all context must be explicitly included in messages. Critically, it cannot access past query results. Say, if you ask “List all products
” and then “What is the revenue of the second product?
”, Snowflake Cortex Analyst cannot lookup the first query’s answer to figure out which product is “second.” It only works with the models and data, not intermediate results. Also, it only answers questions that can be resolved by SQL on your data – no free-form insights or summaries. It won’t say “I sense a trend” or do arbitrary text analysis; it sticks to SQL queries. In very long or rambling conversations, the model can also lose track. If you change topics frequently or exceed the context window, you may need to restart the chat.
TL;DR: Multi-turn is supported by feeding back the chat history in each request, but there’s no hidden memory beyond that, and only database-answerable questions (via SQL) will work. Keep prompts focused and reset if things get confusing.
Semantic Views vs Semantic Models
Snowflake’s Cortex Analyst supports two ways to add semantics: Semantic Views and Semantic Models. Both let you encode business logic, but they reside in different places. A Semantic View is a new object type in Snowflake (similar to a specialized database view) that stores tables, columns, metrics, and joins directly inside the database. You can query a Semantic View using SQL or have Snowflake Cortex Analyst use it directly. By contrast, a Semantic Model is an external YAML file (a metadata definition) that you save to a Snowflake stage. Cortex Analyst reads this YAML file to understand your tables and logic.
Semantic Views are primarily designed for BI and data catalog scenarios, whereas Semantic Models are used specifically for Cortex Analyst’s AI-driven queries. For this guide, we focus on Semantic Models. Just know that a Semantic View is stored within Snowflake (and can be granted/shared like other objects), while a Semantic Model is a portable file you upload to a stage for Cortex Analyst to use.
🔮 Step-by-Step Guide to Create Snowflake Cortex Analyst
Now, let’s create a Snowflake Cortex Analyst app from scratch.
Prerequisites and Setup
Before diving into SQL, make sure you have:
- A Snowflake Enterprise Edition account (Cortex features are an AI offering above standard).
- A user/role with privileges to create databases, schemas, tables, and stages.
- The
SNOWFLAKE.CORTEX_USER
role granted (or use anADMIN
role). If you want everyone to have access, note that this role is granted toPUBLIC
by default. - A Snowflake Virtual Warehouse for executing queries.
- Familiarity with Python (for API calls), YAML (Semantic Model), and basic NLP concepts.
- Snowflake CLI (SnowSQL) or equivalent for running SQL commands.
- Snowflake Cortex Analyst enabled (typically enabled by default, but can be managed with
ALTER ACCOUNT SET ENABLE_CORTEX_ANALYST = TRUE/FALSE;
)
Let's dive right in!
Step 1—Log In to Snowflake
Sign in to your Snowflake account (you can use Snowsight or SnowSQL command line). Make sure you're using a role with sufficient privileges.
Step 2—Grant the CORTEX_USER role
Note that all users have CORTEX_USER
. If you revoked it earlier, re-grant it:
USE ROLE ACCOUNTADMIN;
GRANT ROLE SNOWFLAKE.CORTEX_USER TO ROLE <your_role>;
If you want to restrict access, consider revoking it from PUBLIC and then granting it only to your specific role:
USE ROLE SECURITYADMIN;
REVOKE ROLE SNOWFLAKE.CORTEX_USER FROM ROLE PUBLIC;
Then assign it only to your analyst role.
Step 3—Create a Snowflake Virtual Warehouse
Snowflake Cortex Analyst will run queries using this Snowflake Virtual Warehouse:
CREATE WAREHOUSE snowflake_cortex_analyst_wh WAREHOUSE_SIZE = 'SMALL' AUTO_SUSPEND = 60 AUTO_RESUME = TRUE;
Grant usage if needed:
GRANT USAGE ON WAREHOUSE snowflake_cortex_analyst_wh TO ROLE <your_role>;
Step 4—Create Database and Schema
Set up a place for your data and Semantic Model. For consistency with the Semantic Model example later, we'll use a PUBLIC
schema:
CREATE DATABASE snowflake_cortex_analyst_demo_db;
CREATE SCHEMA snowflake_cortex_analyst_demo_db.public;
Grant usage:
-- Grant usage on the new database and schema to your role if it's not the owner
-- GRANT USAGE ON DATABASE snowflake_cortex_analyst_demo_db TO ROLE <your_role>;
-- GRANT USAGE ON SCHEMA snowflake_cortex_analyst_demo_db.public TO ROLE <your_role>;
Having a dedicated database keeps your Snowflake Cortex Analyst resources organized and makes cleanup a whole lot easier.
Step 5—Create Data Tables
Load some example data. Let’s say we have a simple star schema with one fact table and two dimension tables (like orders and product & region):
CREATE TABLE orders (
order_id INT,
product_id INT,
region_id INT,
order_date DATE,
sales_amount FLOAT
);
CREATE TABLE product (
product_id INT,
product_name STRING,
category STRING
);
CREATE TABLE region (
region_id INT,
region_name STRING
);
Let’s populate our table with sample data. In a real scenario, you’d stage your files and use Snowflake’s COPY INTO command to bulk-load them. For this guide, we’ll keep it simple and manually insert a few demo rows with INSERT statements.
-- Insert demo products
INSERT INTO product (product_id, product_name, category) VALUES
(1, 'Smartphone Nothing Phone', 'Electronics'),
(2, 'Macbook Pro', 'Electronics'),
(3, 'Nike Shoes', 'Apparel'),
(4, 'Tea Pot', 'Home & Kitchen'),
(5, 'Drumset', 'Musical Instruments');
-- Insert demo regions
INSERT INTO region (region_id, region_name) VALUES
(1, 'North America'),
(2, 'Europe'),
(3, 'Asia'),
(4, 'South America');
-- Insert demo orders
INSERT INTO orders (order_id, product_id, region_id, order_date, sales_amount) VALUES
(1001, 1, 1, '2025-01-10', 799.99),
(1002, 2, 1, '2025-01-12', 1299.50),
(1003, 3, 2, '2025-01-15', 120.00),
(1004, 4, 3, '2025-01-20', 85.75),
(1005, 5, 2, '2025-02-05', 450.00),
(1006, 1, 3, '2025-02-10', 799.99),
(1007, 3, 4, '2025-02-12', 110.00),
(1008, 2, 4, '2025-02-15', 1350.00),
(1009, 4, 1, '2025-03-01', 95.00),
(1010, 5, 3, '2025-03-05', 475.00);
Step 6—Create Your Semantic Model YAML
Next, define a Semantic Model for your data. You can write it manually or save time by using Snowsight’s model generator. To use the generator, provide a brief description with basic model details, specify at least one table or view as your data source, and then select the columns to include in the model. That’s all you need. In the next section, we’ll dive deeper as we create Snowflake Cortex Analyst in Snowsight.
A minimal Semantic Model (in YAML) might look like:
name: OrderAnalysisModel
description: "Sales by product and region"
tables:
- name: Orders
description: "All customer orders"
base_table:
database: SNOWFLAKE_CORTEX_ANALYST_DEMO_DB
schema: PUBLIC
table: ORDERS
primary_key:
columns:
- order_id
dimensions:
- name: order_id
expr: order_id
data_type: INTEGER
description: "Order ID"
- name: product_id
expr: product_id
data_type: INTEGER
description: "Product ID (FK to Product)"
- name: region_id
expr: region_id
data_type: INTEGER
description: "Region ID (FK to Region)"
facts:
- name: sales_amount
expr: sales_amount
data_type: FLOAT
description: "Sales Amount"
time_dimensions:
- name: order_date
expr: order_date
data_type: DATE
description: "Order Date"
- name: Product
description: "Product master data"
base_table:
database: SNOWFLAKE_CORTEX_ANALYST_DEMO_DB
schema: PUBLIC
table: PRODUCT
primary_key:
columns:
- product_id
dimensions:
- name: product_id
expr: product_id
data_type: INTEGER
description: "Product ID"
- name: product_name
expr: product_name
data_type: VARCHAR
description: "Product Name"
- name: category
expr: category
data_type: VARCHAR
description: "Category"
- name: Region
description: "Geographical regions"
base_table:
database: SNOWFLAKE_CORTEX_ANALYST_DEMO_DB
schema: PUBLIC
table: REGION
primary_key:
columns:
- region_id
dimensions:
- name: region_id
expr: region_id
data_type: INTEGER
description: "Region ID"
- name: region_name
expr: region_name
data_type: VARCHAR
description: "Region Name"
relationships:
- name: product_to_orders
left_table: Product
right_table: Orders
relationship_type: many_to_one
join_type: inner
relationship_columns:
- left_column: product_id
right_column: product_id
- name: region_to_orders
left_table: Region
right_table: Orders
relationship_type: many_to_one
join_type: inner
relationship_columns:
- left_column: region_id
right_column: region_id
As you can see, this YAML (saved as cortex_analyst_order_model.yaml
) defines logical tables Orders, Product, and Region, each tied to a physical base table. It also sets up joins via relationships. If you add more descriptive name fields and optionally description or synonyms, you can help Snowflake Cortex Analyst understand terms. The exact syntax follows the [Semantic Model Spec] – note how relationships list the joins. After creating your model, save it locally as, say, cortex_analyst_order_model.yaml
.
Step 7—Upload Semantic Model to Snowflake Stage
Snowflake Cortex Analyst needs the YAML accessible on a stage. First, create a Snowflake stage if you haven’t already. To do so:
CREATE STAGE snowflake_cortex_analyst_models_stage DIRECTORY = (ENABLE = TRUE);
Now you can upload the YAML file via the Snowsight UI. To do so, go to Data —> Databases —> snowflake_cortex_analyst_demo_db —> Schemas —> <your_schema> Stages —> snowflake_cortex_analyst_models_stage.
And then click “+ Files” and select your cortex_analyst_order_model.yaml
file.
Alternatively, if you have SnowSQL configured:
PUT file://path/to/cortex_analyst_order_model.yaml @snowflake_cortex_analyst_models_stage/cortex_analyst_order_model.yaml;
Now @snowflake_cortex_analyst_models_stage/cortex_analyst_order_model.yaml
holds your model.
Step 8—Grant Database and Schema Usage (if needed)
Make sure your analyst role can access the tables in the model and the stage:
GRANT SELECT ON ALL TABLES IN SCHEMA <db>.<schema> TO ROLE my_analyst_role;
GRANT USAGE ON DATABASE <db> TO ROLE my_analyst_role;
GRANT USAGE ON SCHEMA <db>.<schema> TO ROLE my_analyst_role;
Also, confirm the role can read the stage, as above.
Step 9—Test and Interact with Snowflake Cortex Analyst API
Let’s make a sample API call. You can do this from Python or any REST client. For this example, we will be using curl.
curl -X POST \
"https://HGWXLPJ-KUB49831.snowflakecomputing.com/api/v2/cortex/analyst/message" \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Which product category sold the most?"
}
]
}
],
"semantic_model_file": "@SNOWFLAKE_CORTEX_ANALYST_DEMO_DB.PUBLIC.SNOWFLAKE_CORTEX_ANALYST_MODELS_STAGE/cortex_analyst_order_model.yaml"
}'
You’d have to replace <token>
with a real session token, which you can generate.
After running, you should see a JSON response. Like this:
{
"message": {
"role": "analyst",
"content": [
{
"type": "text",
"text": "This is our interpretation of your question:\n\nWhich product category had the highest total sales amount over the entire available time period?"
},
{
"type": "suggestions",
"suggestions": [
"What is the total sales amount by product category year to date?",
"Which product category had the highest sales amount last month?",
"What is the daily trend of sales amount for each region name?"
]
}
]
},
"request_id": "e3ee4ae7-5042-4ef1-a0d1-d6cdd3b2dbed",
"warnings": [
{
"message": "SQL: WITH __orders AS (\n SELECT\n product_id,\n order_date,\n sales_amount\n FROM snowflake_cortex_analyst_demo_db.public.orders\n), __product AS (\n SELECT\n product_id,\n category\n FROM snowflake_cortex_analyst_demo_db.public.product\n), sales_by_category AS (\n SELECT\n p.category,\n MIN(o.order_date) AS start_date,\n MAX(o.order_date) AS end_date,\n SUM(o.sales_amount) AS total_sales\n FROM __orders AS o\n INNER JOIN __product AS p\n ON p.product_id = o.product_id\n GROUP BY\n p.category\n)\nSELECT\n category,\n start_date,\n end_date,\n total_sales\nFROM sales_by_category\nORDER BY\n total_sales DESC NULLS LAST\nLIMIT 1. "
}
],
"semantic_model_selection": null,
"response_metadata": {
"model_names": ["claude-3-5-sonnet"],
"is_semantic_sql": false,
"cortex_search_retrieval": [],
"question_category": "CLEAR_SQL",
"analyst_orchestration_path": "regular_sqlgen",
"analyst_latency_ms": 9206.0
}
}
This confirms Snowflake Cortex Analyst understood your question and ran the query.
You can ask even more questions. Like:
- “
List sales by region for Q1 2025
” - “
What was the average order amount in the North American region?
” - “
Which product had the highest revenue in 2025?
”
Just send each as a separate API call (or in a Streamlit app/UI as we’ll see). Snowflake Cortex Analyst will reply with answers and the SQL it executed. This completes our basic setup example via SQL.
Step 11—Clean Up and Disable Snowflake Cortex Analyst
Once you are done experimenting, you can drop the Snowflake objects you created and disable Snowflake Cortex Analyst.
DROP DATABASE snowflake_cortex_analyst_demo_db;
DROP WAREHOUSE snowflake_cortex_analyst_wh;
ALTER ACCOUNT SET ENABLE_CORTEX_ANALYST = FALSE;
This returns your account to its prior state (dropping the database also removes the tables/stage inside it). The ALTER ACCOUNT
disables Cortex Analyst so that the feature is off until re-enabled. (Use ENABLE_CORTEX_ANALYST = TRUE
to turn it back on later).
🔮 Step-by-Step Guide to Create Snowflake Cortex Analyst via Snowsight
Snowflake’s Snowsight has a graphical wizard for Cortex Analyst that automates many steps. Here’s how to use it:
Prerequisites and Setup
A Snowsight user interface with your Snowflake account, and a role with SNOWFLAKE.CORTEX_USER
and proper USAGE
on your database/schema. Also have a Snowflake Virtual Warehouse and data table ready (as above). Finally, have a stage ready for saving the model (or make sure you have privileges to create one).
Step 1—Log In to Snowsight
Head over to your browser, open Snowflake and sign in.
Step 2—Switch the Role
In the Snowsight UI (usually bottom-left corner), select the role that has SNOWFLAKE.CORTEX_USER
and access to your data.
In the Snowsight UI (usually bottom-left corner), check your current role. You need a role that includes SNOWFLAKE.CORTEX_USER
privileges:
- Click on your user name in the bottom-right
- Select "Switch Role" if needed
- Choose a role that has Cortex Analyst access
- Verify you can see Snowflake "AI and ML Studio" in the left sidebar
If you don't see Snowflake AI and ML Studio, your current role lacks the necessary privileges.
Step 3—Open Snowflake AI & ML Studio
In the left sidebar, click on Snowflake AI and ML Studio. This section contains all of Snowflake's AI and ML capabilities, including Snowflake Cortex Analyst.
Snowflake AI and ML Studio provides a unified interface for:
- Cortex Functions (LLM functions)
- Snowflake Cortex Analyst (conversational analytics)
- Snowflake Cortex Search
- Snowflake Cortex Playground
- Anomaly Detection
- Forecasting
- Classification
- Snowpark ML (machine learning workflows)
- Snowflake Model Registry (ML model management)
… and more!
Step 4—Create Snowflake Cortex Analyst
Find the Snowflake Cortex Analyst tile and click Try to access the Cortex Analyst interface. Then choose Create new to start building a new Semantic Model.
You'll see three available options:
- Create Semantic Model — create a new model from scratch using the guided interface
- Create Semantic View — create a simpler, single-table approach
- Upload YAML file — import a pre-built Semantic Model file
For this walkthrough, select "Create Semantic Model" since it provides the most flexibility.
Step 5—Select Your Database and Stage
The interface will ask where to store the model. Choose the database containing your source data. Select the schema with your tables. Pick an existing stage or create a new one for storing the Semantic Model.
Step 6—Enter Name and Description
Now, provide meaningful identifiers for your Semantic Model. Use a descriptive name and write a clear description of the business questions this model will answer. These details help team members understand the model's purpose and scope. Good descriptions matter when you have multiple Semantic Models in production.
Step 7—Pick the Source Table (or View)
Now pick the source table(s) or view(s) for the model.
Step 8—Select Required Columns
The wizard may ask you to choose tables or views and then checkboxes for which columns to include. Select all columns you want Snowflake Cortex Analyst to see (don’t include secret or irrelevant columns).
Step 9—Create and Save
When you finish, click Save. Snowsight will generate the YAML file behind the scenes and upload it to your chosen stage. You can confirm that the file (movies_data_model.yaml
) appears under the Stages section.
Step 10—Interact with App Directly via Snowsight UI
After saving, Snowsight often provides a chat interface or a way to test questions right away. You can ask questions in a chat box and see Snowflake Cortex Analyst’s answers directly. This is a fast way to validate your model. (Alternatively, you could copy the model file and use the REST API or a custom app as before).
That’s it for the Snowsight path. You’ve created a Semantic Model without writing YAML by hand. The UI handles generating the YAML for you. When finished, you can again clean up or disable the feature if required (via ALTER ACCOUNT SET ENABLE_CORTEX_ANALYST = FALSE
).
🔮 Example—Create a Custom Conversational Analytics App Using Snowflake Cortex Analyst and Streamlit
Let's build a simple Streamlit app that uses Snowflake Cortex Analyst. This app lets users chat with your Snowflake data in a user-friendly web interface. For this, we'll assume you've set up Snowflake Cortex Analyst and have a role with the necessary permissions (as in the previous examples).
Prerequisites and Setup
In addition to the earlier setup, you need:
- A Snowflake stage with your Semantic Model (or a model created via Snowsight as above).
- A Snowflake Streamlit integration enabled (Snowflake’s Apps framework).
- Python knowledge to write the Streamlit code.
Step 1—Log In to Snowflake
Log into Snowsight and switch to the appropriate role (with CORTEX_USER
, Snowflake Virtual Warehouse, ….). Make sure you can see the data table and the model stage.
Step 2—Search and Download Sample Dataset
For this example, let's create our own movie dataset. You can download one from Hugging Face or Kaggle, use Snowflake’s sample data, or use ChatGPT or Gemini to generate some random data.
This is what our table will look like:
- movies (
movie_id
,title
,genre
,release_year
) - ratings (
rating_id
,movie_id
,user_id
,rating_score
)
Step 3—Plan Your Semantic Model
Decide which tables and questions the app should cover. For instance:
- You want to answer questions about movie popularity by genre and year.
- So include the movies and ratings tables in your model.
- Think of some natural queries:
What was the highest rated movie in 2020?
How many movies scored above 4 stars?
…
Step 4—Create Database and Schema for Semantic Models
Create a dedicated schema to store the model YAML (if you haven’t):
CREATE DATABASE <db_name>;
CREATE SCHEMA <schema_name;
Step 5—Create Snowflake Stages for Semantic Model Storage
Create stages with access controls
CREATE STAGE <db_name>.<schema_name>.movies_data_model DIRECTORY= (ENABLE=TRUE);
Step 6—Load the data into Snowflake Stage
Now load the two CSV files into the Snowflake stage you created earlier:
Movies metadata (movie_id
, title
, genre
, release_year
):
Save this 👇 as movies.csv
.
movie_id,title,genre,release_year
1,The Shawshank Redemption,Drama,1994
2,The Godfather,Crime Drama,1972
3,The Dark Knight,Action Drama,2008
4,The Godfather Part II,Crime Drama,1974
5,12 Angry Men,Drama,1957
6,Schindler's List,Biography Drama History,1993
7,The Lord of the Rings: The Return of the King,Adventure Drama Fantasy,2003
8,Pulp Fiction,Crime Drama,1994
9,The Lord of the Rings: The Fellowship of the Ring,Adventure Drama Fantasy,2001
10,The Good the Bad and the Ugly,Western,1966
11,Forrest Gump,Comedy Drama Romance,1994
12,Inception,Action Adventure Sci-Fi Thriller,2010
13,Fight Club,Drama Thriller,1999
14,The Lord of the Rings: The Two Towers,Epic Fantasy Adventure,2002
15,Star Wars: Episode V - The Empire Strikes Back,Action Adventure Sci-Fi,1980
16,Interstellar,Adventure Drama Sci-Fi,2014
17,Parasite,Thriller Drama,2019
18,Spirited Away,Animation Adventure Fantasy,2001
19,Saving Private Ryan,War Drama,1998
20,The Green Mile,Magical Realism Fantasy Crime Drama,1999
User ratings (rating_id
, movie_id
, user_id
, rating_score
):
Save this 👇 as ratings.csv
.
rating_id,movie_id,user_id,rating_score
1,1,5,4.8
2,1,12,5.0
3,1,3,4.5
4,2,7,4.9
5,2,19,5.0
6,2,1,4.7
7,3,4,4.6
8,3,14,4.8
9,3,20,4.9
10,4,9,4.7
11,4,16,4.8
12,4,2,4.6
13,5,5,4.4
14,5,11,4.5
15,5,18,4.6
16,6,6,4.9
17,6,8,5.0
18,6,13,4.8
19,7,10,4.7
20,7,15,4.8
21,7,17,4.9
22,8,3,4.6
23,8,12,4.7
24,8,20,4.5
25,9,1,4.8
26,9,14,4.9
27,9,19,4.7
28,10,2,4.5
29,10,9,4.6
30,10,18,4.7
31,11,6,4.9
32,11,11,4.8
33,11,23,4.7
34,12,17,4.9
35,12,3,4.6
36,12,8,4.8
37,13,14,4.7
38,13,21,4.8
39,13,27,4.6
40,14,4,4.9
41,14,9,4.8
42,14,15,4.7
43,15,2,4.6
44,15,16,4.8
45,15,29,4.7
46,16,25,4.9
47,16,7,4.8
48,16,12,4.6
49,17,1,4.8
50,17,18,4.9
51,17,6,4.7
52,18,5,4.9
53,18,19,4.8
54,18,24,4.6
55,19,3,4.7
56,19,14,4.8
57,19,30,4.5
58,20,8,4.9
59,20,22,4.7
60,20,29,4.8
61,1,17,5.0
62,2,10,4.9
63,3,2,4.6
64,4,18,4.7
65,5,14,4.5
66,6,3,4.9
67,7,12,4.8
68,8,1,4.7
69,9,6,4.9
70,10,13,4.7
71,11,20,4.8
72,12,11,4.9
73,13,19,4.6
74,14,26,4.7
75,15,4,4.5
76,16,2,4.8
77,17,9,4.7
78,18,10,4.6
79,19,5,4.8
80,20,13,4.9
81,1,25,4.9
82,2,27,4.7
83,3,16,4.6
84,4,15,4.8
85,5,29,4.6
86,6,17,4.9
87,7,23,4.7
88,8,18,4.6
89,9,21,4.8
90,10,8,4.7
91,11,3,5.0
92,12,14,4.9
93,13,7,4.8
94,14,19,4.6
95,15,11,4.7
96,16,30,4.8
97,17,2,4.9
98,18,13,4.7
99,19,20,4.8
100,20,24,4.9
Upload both movies.csv
and ratings.csv
to your Snowflake stage.
Next, return to the Snowflake dashboard and click + Create. From the dropdown, select Table —> From file.
In the modal, choose your database and schema, then click Add from stage.
Select the stage where you uploaded your data, choose movies.csv, and click Add. Enter a name for the new table and click Next.
On the header options, select Skip first line. Uncheck any columns you don’t want, rename columns as needed, then click Load.
A dialog box will confirm that the table has been created and the data has loaded successfully.
Repeat the same process for ratings
.
Step 7—Create Your Semantic Model YAML
Now create a Semantic Model. In Snowsight AI and ML, click Try on Cortex Analyst, then Create New —> Semantic Model (like in the previous UI steps).
Select your analyst_streamlit_demo_db.public database
and movies_data_model
stage. Give the model a name (movies_data
).
Select the movies and ratings tables, and select the relevant columns (movie title, genre, rating).
When done, click Save. The YAML will be saved to:
@analyst_streamlit_demo_db.public.movies_data_model/movies_data.yaml
Finally, define the relationship: movies.movie_id = ratings.movie_id
.
(If you prefer manual, you could also write YAML by hand similar to the “orders
” example, then PUT it into the stage).
Step 8—Upload Semantic Model to Stage
If you use the Snowsight wizard, the model is already in the stage. Otherwise, use SnowSQL:
PUT file://path/to/movies_data.yaml @analyst_streamlit_demo_db.public.movies_data_model/;
Step 10—Test and Interact with App Directly via UI
After saving, Snowsight provides a chat interface for testing questions immediately. You can type a query in the chat box and view Snowflake Cortex Analyst’s answer directly. For example, we asked, “What are the top 10 movies by average rating score released between 1900 and 2025?
” and Snowflake Cortex Analyst responded with a detailed answer and the corresponding SQL queries.
Step 9—Create a Streamlit app (in Snowflake or via VS Code)
Now for the fun part: let’s create an interactive Streamlit app and integrate Snowflake Cortex Analyst. In this demo, we’ll use VS Code, but you can also build and run Streamlit directly within Snowflake.
Here’s how to do it in Snowflake (Streamlit in Snowflake) :
First, in Snowsight, navigate to +Create and select Streamlit App.
Click New Streamlit App.
Provide a name (for example, MovieRatingsChat
), select the database, schema, and Snowflake Virtual Warehouse.
Click Create.
In the code editor, paste the Python script shown below.
Here’s how to do it in VS Code:
To get started with VS Code, first make sure you have it installed. You probably already are familiar with it. Next, create a file named app.py. Once that's done, open the terminal and install two packages: streamlit and requests. To do this, run the following command:
pip install streamlit requests
That’s it. Once installed, paste the code below into app.py and run it using:
streamlit run app.py
Now inside app.py
paste the following script:
import streamlit as st
import requests
import json
# ── PAGE CONFIGURATION ───────────────────────────────────────────────────
st.set_page_config(
page_title="Snowflake Cortex Analyst Chatbot",
page_icon="🍿",
layout="centered",
initial_sidebar_state="collapsed",
)
# ── API & SESSION CONFIGURATION ──────────────────────────────────────────
ACCOUNT_LOCATOR = <your_account>
API_URL = f"https://{ACCOUNT_LOCATOR}.snowflakecomputing.com/api/v2/cortex/analyst/message"
TOKEN = <your_token>
SEMANTIC_MODEL_FILE = "@ANALYST_STREAMLIT_DEMO_DB.PUBLIC.MOVIES_DATA_MODEL/movies_data.yaml"
HEADERS = {
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json",
"Accept": "application/json",
}
# Initialize session state for conversation history
if "history" not in st.session_state:
st.session_state.history = []
# ── UI & CHAT DISPLAY ─────────────────────────────────────────────────────
st.title("🤖 Snowflake Cortex Analyst")
st.caption("Chatbot powered by Snowflake Cortex. Ask about movie data!")
# Display the conversation history
for msg in st.session_state.history:
# Avatar based on the role
avatar = "👤" if msg["role"] == "user" else "🤖"
with st.chat_message(msg["role"], avatar=avatar):
# The content is a list of chunks (text, sql)
for chunk in msg.get("content", []):
content_type = chunk.get("type")
if content_type == "text":
st.markdown(chunk.get("text", ""))
elif content_type == "sql":
st.code(chunk.get("statement", ""), language="sql")
# Welcome message if the chat is new
if not st.session_state.history:
st.info("Ask a question to get started, for example: 'What are the top 10 rated movies?'")
# --- 4. USER INPUT FORM -------------------------------------------------------
# Use a form to batch input and prevent rerunning on every keystroke
with st.form("chat_form", clear_on_submit=True):
user_q = st.text_input("Your question:", placeholder="Ask anything realted to movies...", key="user_input")
submitted = st.form_submit_button("Send it!")
if submitted and user_q:
# Append user message to history and rerun to display it immediately
st.session_state.history.append({
"role": "user",
"content": [{"type": "text", "text": user_q}],
})
st.rerun()
# --- BOT RESPONSE & API LOGIC ----------------------------------------------
# If the last message was from the user, it's the bot's turn to respond
if st.session_state.history and st.session_state.history[-1]["role"] == "user":
# Build a clean, alternating history for the API payload
clean_msgs = [msg for i, msg in enumerate(st.session_state.history) if i == 0 or st.session_state.history[i-1]["role"] != msg["role"]]
payload = {
"messages": clean_msgs,
"semantic_model_file": SEMANTIC_MODEL_FILE,
}
try:
# Create a compact JSON string to mimic curl's behavior
compact_payload = json.dumps(payload, separators=(',', ':'))
with st.spinner("Snowflake Cortex Analyst is thinking..."):
resp = requests.post(
API_URL,
data=compact_payload,
headers=HEADERS,
timeout=45 # Increased timeout for complex queries
)
resp.raise_for_status()
data = resp.json()
# Extract the full list of content chunks from the response
response_chunks = data.get("message", {}).get("content", [])
# If a valid response is received, append it to history and rerun
if response_chunks:
st.session_state.history.append({
"role": "assistant",
"content": response_chunks,
})
st.rerun()
except requests.exceptions.HTTPError as e:
st.error(f"API error: {e.response.status_code} - {e.response.text}")
except requests.exceptions.RequestException as e:
st.error(f"A network or request error occurred: {e}")
except Exception as e:
st.error(f"An unexpected error occurred: {e}")
This Streamlit app sets up a chat box. When the user submits a question, it calls the same REST API endpoint we used in the above section, it then retrieves the answer, and displays it. Make sure to replace "your_account
", "your_account
" etc., with your Snowflake configuration.
Click Save & Run.
You now have a live web UI that chats with your data!
Try asking: “What are the top 10 movies by average rating score released between 1900 and 2025?
”
Copy the code from the app above and run it in Snowflake. You’ll get a list of the top 10 movies by average rating, released between 1900 and 2025.
Step 10—Test and Deploy the Streamlit App
Test several questions to make sure it works as expected. You can then deploy the app (make it available beyond your preview).
Step 11—Wrap Up and Final Check
Once you are done with it, clean up resources to avoid costs.
DROP DATABASE IF EXISTS movie_demo_db;
DROP WAREHOUSE IF EXISTS cortex_wh;
ALTER ACCOUNT SET ENABLE_CORTEX_ANALYST = FALSE;
And that’s it. This concludes our in-depth example of how to build a custom conversational analytics chat app using Streamlit and Snowflake Cortex Analyst.
Snowflake Cortex Analyst Limitations
Snowflake Cortex Analyst is powerful, but it still has lots of limitations. Here are the main Snowflake Cortex Analyst limitations you should know:
1) SQL-only queries
Snowflake Cortex Analyst only answers questions that can be resolved by SQL on your structured data. If you ask a broad or open-ended question, it will not produce insightful analysis beyond what SQL can compute. It won’t analyze unstructured text, images, or general business strategies.
2) Model-defined joins only
Snowflake Cortex Analyst will only join tables and columns you defined in your Semantic Model. If you accidentally left out a relationship, it won’t infer it. Every multi-table query must follow the relationships in your YAML.
3) No VARIANT/JSON support
Snowflake Cortex Analyst is built for structured tables. It cannot natively query semi-structured VARIANT/JSON
data or call SQL functions beyond the tables in the model. If you have JSON columns, you’d need to flatten them into the model tables or views beforehand.
4) Limited conversation memory
As we have mentioned above, the LLM doesn’t have a persistent memory. It processes each multi-turn request from scratch, only seeing whatever history you include. It cannot reference previous query results or “remember” anything outside the immediate messages you send.
5) Prompt length and cost
Longer questions or large context consume more compute. There are context window limits. Snowflake imposes a 1 MB size limit on your Semantic Model file to keep inputs more manageable. Also, very long conversations can become slower and cost more (each turn is a new API call). If a conversation drifts or becomes too big, it’s often best to start fresh.
6) Performance/latency
Snowflake Cortex Analyst generates queries via LLM, so the responses can take a few seconds. Simple questions return quickly, but complex ones (involving many tables or calculations) might be slower. Behind the scenes multiple AI agents are coordinating to provide you the accurate response.
7) Cost considerations
You are billed AI credits per question (per API call) plus the usual Snowflake Virtual Warehouse compute to run the SQL. Specifically, Snowflake Cortex Analyst counts one message per request (successful calls only) and ignores the number of tokens.
8) Limited Region availability
Snowflake Cortex Analyst is not yet in every Snowflake region. At the current time of writing this article it’s available in select AWS and Azure regions:
AWS ap-northeast-1 (Tokyo)
AWS ap-southeast-2 (Sydney)
AWS us-east-1 (Virginia)
AWS us-west-2 (Oregon)
AWS eu-central-1 (Frankfurt)
AWS eu-west-1 (Ireland)
Azure East US 2 (Virginia)
Azure West Europe (Netherlands)
If your account is elsewhere, you’ll need cross-region inference enabled.
Check Snowflake docs for the latest supported regions.
TL;DR: Snowflake Cortex Analyst works best with well-organized, relational data. It tackles business questions that involve aggregates or filters. It is not a general AI chat system. Still, for SQL-type questions, it can save a lot of time and make data access easier. Just make sure to keep its limitations in mind.
How to Monitor Snowflake Cortex Analyst Costs?
Now to monitor your Snowflake Cortex Analyst usage and spending, use Snowflake’s Account Usage views. Snowflake provides a special view SNOWFLAKE.ACCOUNT_USAGE.CORTEX_ANALYST_USAGE_HISTORY that logs each request. For example, to see recent credit usage:
SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_ANALYST_USAGE_HISTORY;
This shows AI credits consumed.
Also, Snowflake Cortex Analyst usage appears in the general METERING_HISTORY (in ACCOUNT_USAGE
) under SERVICE_TYPE = 'AI_SERVICES'
. You can filter that for more details on when AI credits were used.
Note: Snowflake Cortex Analyst billing is per successful response. Tokens per call do not affect the charge. But, any queries your analytics generates will still consume Snowflake Virtual Warehouse credits in the normal way. So monitoring both the Cortex usage view and your warehouse billing dashboard will give the full picture of your total spending.
Save up to 30% on your Snowflake spend in a few minutes!
Conclusion
And that’s a wrap! Snowflake Cortex Analyst is a powerful AI service from Snowflake that lets you literally talk to your data. Snowflake handles all of the behind-the-scenes setup: there’s no infrastructure to provision, no models to train, and no connectors to maintain. It’s a fully managed Snowflake service powered by a state-of-the-art large language model that’s fine-tuned on your own data. Every question you ask in plain English is parsed against your governed tables and schemas in real time. You get instant, context-aware insights without writing a single line of SQL plus you get access to all of Snowflake’s built-in security, data privacy, and governance controls.
In this article, we have covered:
- What is Snowflake Cortex Analyst?
- Snowflake Cortex Analyst Features
- Access Control and Privileges for Snowflake Cortex Analyst
- Difference between Semantic Views vs Semantic Models
- Step-by-Step Guide to Create Snowflake Cortex Analyst and a Semantic Model
- Step-by-Step Guide to Create Snowflake Cortex Analyst via Snowsight
- Example – A Custom Conversational App with Streamlit
- Snowflake Cortex Analyst Limitations and Gotchas
- Monitoring Cortex Analyst Costs
- How to Monitor Snowflake Cortex Analyst Costs?
.. and so much more!
Happy querying, and have fun talking to your data!
FAQS
What is a Snowflake Cortex Analyst?
Snowflake Cortex Analyst is one of the AI features in the Snowflake Cortex AI suite. It’s a managed service that uses large language models (LLMs) to let you ask questions about your Snowflake data in plain English. The system converts your question into SQL behind the scenes and returns the answer, all via an API.
Why use Snowflake Cortex Analyst?
Snowflake Cortex Analyst simplifies data access. Non-technical users can get answers from the data without needing SQL skills. Developers save time because Snowflake handles the LLM infrastructure. It also provides higher accuracy by using a Semantic Model to embed business logic. And since queries run in Snowflake, you benefit from its performance and security.
What roles and permissions do I need to call Snowflake Cortex Analyst?
Aside from having CORTEX_USER
, you need permissions on the data and Semantic Model. If using a model on a stage, grant your role READ on that stage. Also grant SELECT on any tables in the model, and USAGE on the database and schema. If your model uses a Cortex Search service, grant USAGE on that as well.
What is the Snowflake Cortex Agent?
Snowflake Cortex Agent is a related feature in the Cortex AI suite. It’s more general: an “agent” that can call multiple tools (Cortex Search, Cortex Analyst) to answer a question. It orchestrate across both structured and unstructured data sources to deliver insights.
Which LLMs power Snowflake Cortex Analyst, and can I choose between them?
Snowflake Cortex Analyst by default uses Snowflake-hosted Llama 3 and Mistral-2 models inside the Snowflake environment. You can optionally enable Azure OpenAI (e.g. GPT-4o) by setting ENABLE_CORTEX_ANALYST_MODEL_AZURE_OPENAI=TRUE
. You do not pick the model per query – Snowflake automatically selects the best model combination based on your account’s settings, region, and model access.
Can Snowflake Cortex Analyst handle follow-up questions?
Yes, by including the previous conversation in the request you can ask follow-ups. Snowflake Cortex Analyst will use the conversation history to rephrase the follow-up into a full question and answer it. Just remember it still only knows what’s in the data. It doesn’t inherently “remember” query results beyond the context you provide.
What kinds of questions can Snowflake Cortex Analyst answer?
Any question that can be answered by SQL on your modeled data. For example: aggregations (“total sales by region
”), filters (“which product has the most units sold?
”), date comparisons, etc. It cannot do unbounded text analysis, trend commentary, or queries outside of the tables and columns you gave it.
How do I disable Snowflake Cortex Analyst?
Use the Snowflake ACCOUNTADMIN role and run:
ALTER ACCOUNT SET ENABLE_CORTEX_ANALYST = FALSE;
This turns off all Snowflake Cortex Analyst functionality in the account. (To re-enable, set it to TRUE).
What are the main limitations of Snowflake Cortex Analyst?
As mentioned above, its answers are limited to SQL queries on your data. It can’t join tables that aren’t related in the model. It doesn’t support semi-structured VARIANT queries by itself. Multi-turn chats can get confused if too long or off-topic. Semantic Models have size limits (1 MB file, ~32K tokens). And it’s only available in certain cloud regions.
How can I monitor my Snowflake Cortex Analyst usage and spending?
Snowflake provides views for this. Run queries on SNOWFLAKE.ACCOUNT_USAGE.CORTEX_ANALYST_USAGE_HISTORY
to see each request’s credit usage. You can group by day or user for reporting. Also, check METERING_HISTORY filtered by SERVICE_TYPE='AI_SERVICES'
in ACCOUNT_USAGE. Remember, billing is per successful API call (message), as per Snowflake’s consumption table.
Can Snowflake Cortex Analyst query JSON or VARIANT data?
Not directly. It expects structured columns. If you have JSON/VARIANT data, you’d need to create a view or table that flattens it into structured columns and then include that flattened view/table in your Semantic Model. The LLM won’t know how to interpret raw JSON paths on its own.