Cortex AI Functions

Snowflake · Advanced Features

Theory

Snowflake Cortex AI Functions let you call large language models directly from SQL. The current functions use the AI_ prefix: AI_COMPLETE sends any prompt to a chosen model, while task functions such as AI_CLASSIFY, AI_FILTER, AI_SENTIMENT, AI_EXTRACT, AI_TRANSLATE, AI_SUMMARIZE_AGG and AI_AGG handle common jobs without prompt writing. AI_EMBED creates vectors and AI_PARSE_DOCUMENT reads PDFs from a stage. Models run inside Snowflake's governance boundary. The older SNOWFLAKE.CORTEX.COMPLETE, SENTIMENT and similar functions are legacy, and Snowflake provides a migration guide.

For example, WHERE AI_FILTER(PROMPT('The reviewer liked the food: {0}', review)) keeps only positive reviews, and AI_CLASSIFY(review, ['delivery', 'quality', 'price']):labels[0] tags each one with a topic.

Why we use it

Adding AI to data work usually means exporting data to another service, managing API keys and building pipelines. AI Functions put these capabilities in SQL, next to the data and under the same roles, so analysts can enrich whole tables with one query.

When to use it

Use AI Functions for text and document tasks over tables: classification, filtering, sentiment, extraction, translation and summaries. Use ML functions like FORECAST for time series. Test on a LIMIT sample first, since usage is billed by tokens, and check model availability per region.

General and Task Functions

AI_COMPLETE sends a prompt to a hosted model and returns text or structured output. Task functions such as AI_CLASSIFY, AI_FILTER, AI_SENTIMENT, AI_EXTRACT and AI_TRANSLATE do one common job with a fixed output shape, and AI_AGG and AI_SUMMARIZE_AGG work across many rows.

Migrating From Legacy Functions

Older code uses SNOWFLAKE.CORTEX.COMPLETE, SENTIMENT, CLASSIFY_TEXT and similar. Their AI_ replacements sometimes return different shapes — AI_SENTIMENT returns sentiment categories instead of a -1 to 1 score, and AI_CLASSIFY returns a labels array — so test before switching.

ML Functions and Cortex Analyst

FORECAST and ANOMALY_DETECTION are ML functions for time-series data. Cortex Analyst and Cortex Search build on the same platform to answer questions over structured and unstructured data; they have their own topics in this section.

How it works

  1. Text or documents stored in a table or stage
  2. Is there an AI_ task function for the job? Yes: Call it in SQL. No: Write a prompt for AI_COMPLETE.
  3. Run it on a small LIMIT sample and check the output
  4. Are results and token cost acceptable? Yes: Apply to the full table or a pipeline. No: Refine labels, prompt or model.
  5. Store results in a column or table

Example

-- Model names vary by region; see 'Models and regional availability' in the docs
SELECT AI_COMPLETE('claude-haiku-4-5',
  'Explain what a virtual warehouse is in 2 sentences.') AS ai_response;

SELECT review_id,
       AI_CLASSIFY(review, ['delivery', 'quality', 'price']):labels[0]::STRING AS topic,
       AI_SENTIMENT(review) AS sentiment
FROM reviews;

SELECT * FROM reviews
WHERE AI_FILTER(PROMPT('The reviewer enjoyed the food: {0}', review));

SELECT AI_TRANSLATE('Hello, how are you?', 'en', 'hi') AS hindi_translation;
SELECT AI_AGG(review, 'Summarise the main complaints') FROM reviews;

Key points

Snowflake topics

Snowflake Fundamentals

Warehouses & Performance

Staging & SnowSQL

Tables & Data Handling

Cloud Integrations

Storage & Optimization

Security & Governance

Views, Pipelines & Automation

Data Types & SQL Fundamentals

Semi-Structured Data Deep Dive

Advanced Features

Data Sharing & Collaboration

Cost Management & Monitoring

Databases, Schemas & Objects

Performance Deep Dive

Advanced Security & Governance

Stored Procedures & UDFs

Ecosystem & Integrations

SnowPro Certification Prep

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Mastering Snowflake

The modern data cloud, from architecture to SnowPro certification. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Snowflake SQL Sharpen the SQL you use in Snowflake: 150 query problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Snowflake  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

{{ sec.h }}

{{ sec.body }}

{{ sec.body }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
On screen — where to click

{{ rich.ui.title }}

{{ u.text }}
  1. {{ st.n }}{{ st.text }}
{{ rich.ui.title }}
{{ u.text }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
Want to run this yourself? Unlike the SQL and Python courses, Snowflake needs a real account — there's no in-browser engine for it. Click Copy above, then paste it into a free Snowflake trial (30 days, no card required) and run it in Snowsight.
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic