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
- Text or documents stored in a table or stage
- Is there an AI_ task function for the job? Yes: Call it in SQL. No: Write a prompt for AI_COMPLETE.
- Run it on a small LIMIT sample and check the output
- Are results and token cost acceptable? Yes: Apply to the full table or a pipeline. No: Refine labels, prompt or model.
- 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
- AI Functions are called in SQL; no separate ML infrastructure
- AI_COMPLETE is the general-purpose LLM function
- Task functions (AI_CLASSIFY, AI_FILTER, AI_SENTIMENT...) need no prompt engineering
- Legacy SNOWFLAKE.CORTEX.* functions should be migrated to AI_ functions
- Needs the CORTEX_USER or AI_FUNCTIONS_USER database role
- Billed by tokens; model availability differs by region