What you will be able to do
- State the privileges needed to call Cortex AI Functions and when to use them instead of the REST API
- Call AI_COMPLETE and predict its behaviour when individual rows fail
- Constrain AI_COMPLETE output with a SQL type literal or a JSON schema
- Pick the right task-specific function (AI_CLASSIFY, AI_EXTRACT, AI_FILTER, AI_AGG and the rest) for a job
- Build prompt objects and file references with PROMPT and TO_FILE
Key concept
Cortex AI Functions as SQL functions — Snowflake exposes managed LLM capabilities as ordinary SQL functions (also callable from Python). You call them inside queries over whole tables, and they are tuned for batch throughput rather than low-latency interaction.
1.What Cortex AI Functions are and who can call them
Cortex AI Functions let you run LLM work, such as extraction, classification, summarization and translation, directly in SQL against the data already in your tables. The models run inside Snowflake: the documentation says all the LLMs Snowflake provides access to are deployed within the Snowflake Service perimeter.
You need access before you can call them. The general AI Functions page says your role needs the USE AI FUNCTIONS account-level privilege and one of the CORTEX_USER or AI_FUNCTIONS_USER database roles. The AI_COMPLETE reference page names only the SNOWFLAKE.CORTEX_USER database role. So the two pages are consistent: CORTEX_USER is the role both of them name, and the general page also allows AI_FUNCTIONS_USER as an alternative.
The documentation sorts the functions into two groups. Cortex AI functions do the actual work. AI_COMPLETE is the general one, and the rest are task-specific, built for routine jobs that need no customization. Helper functions keep those calls from failing, for example by counting tokens before you call so you stay under a model limit. The vector functions used for similarity search are SQL functions on the VECTOR data type, and they work alongside AI_EMBED.
The functions are tuned for batch work. Snowflake recommends them for processing many inputs, such as text from large tables. For interactive work where latency matters, the recommendation is the REST API (Complete, Embed and Agents APIs).
Checkpoint 1 of 6· Check yourself
A team needs sub-second responses for an interactive chat feature. Large overnight table scans are not involved. According to Snowflake, what should they use?
AI Functions are optimized for throughput and batch processing. For interactive, latency-sensitive work the docs point to the REST API.
“For more interactive use cases where latency is important, use the REST API.”Source: docs.snowflake.com
2.AI_COMPLETE: the general-purpose function
AI_COMPLETE generates a completion from a text string or an image using the LLM you choose. Snowflake recommends it for most generative AI tasks. It accepts three kinds of input: a single text prompt, a single image with a text prompt, or a prompt object that can hold multiple images and text. AI_COMPLETE is the updated version of the older COMPLETE function, and the docs say to use AI_COMPLETE for the latest functionality.
Beyond the model and the prompt, the migration guide gives the call shape as AI_COMPLETE(<model>, <prompt> [, <model_parameters>, <response_format>, <show_details> ]). The model_parameters object holds only the model hyperparameters: temperature, top_p, max_tokens and guardrails. The legacy COMPLETE options object documented the defaults temperature 0, top_p 0, max_tokens 4096 (maximum 8192) and guardrails FALSE, and the migration page says the names and defaults are unchanged. response_format is its own argument and is not recognized inside model_parameters. Set show_details to TRUE to get the detailed JSON object (choices, usage, model and created) instead of a plain string.
SELECT AI_COMPLETE(
model => '<model>',
prompt => prompt,
model_parameters => {'temperature': 0.7, 'max_tokens': 100},
show_details => TRUE
) AS response
FROM my_table;This per-row behaviour matters in pipelines: one bad row doesn't abort a large batch. If you need to know *why* a row failed, every syntax variant takes an optional final BOOLEAN argument, return_error_details. When it is TRUE, the function returns an OBJECT with a value field and an error field. One of the two is NULL, depending on whether the call succeeded.
| return_error_details | Return value |
|---|---|
| FALSE or not passed | NULL |
| TRUE | OBJECT with value and error fields |
Checkpoint 2 of 6· Check yourself
You want AI_COMPLETE to tell you why a particular row failed instead of just returning NULL. What do you add?
return_error_details is the optional final BOOLEAN argument. When it is TRUE, the function returns an OBJECT containing the value and the error message.
“All syntax variations accept an optional return_error_details BOOLEAN argument as the final parameter.”Source: docs.snowflake.com
3.COMPLETE structured outputs: type literals and JSON schemas
Free-text answers usually need parsing afterwards. With structured output, you give AI_COMPLETE a response_format that the response must follow. AI_COMPLETE checks each generated token against that definition, so the response conforms to your structure. Every model that AI_COMPLETE supports can produce structured output, although the more powerful models typically produce better responses.
There are two ways to define the structure. A type literal uses SQL types: it starts with the TYPE keyword and uses an OBJECT as the top-level type. Snowflake maps STRING/VARCHAR to JSON strings and FIXED types without a scale to JSON integers. The empty OBJECT() isn't allowed, and some types, such as VARIANT, MAP and date/time types, have no mapping and return an error. Type literals work only with the single-string prompt form of AI_COMPLETE.
The optional show_details => TRUE argument returns inference metadata along with the structured output. In the documentation's examples the result is then an object with created, model, structured_output and usage fields, where usage reports the completion, prompt and total token counts.
Checkpoint 3 of 6· Fill the gap
Which argument, set to TRUE in this call, makes AI_COMPLETE return inference metadata such as token usage along with the structured output?
SELECT AI_COMPLETE(
model => 'llama3.3-70b',
prompt => 'Extract structured data from this customer interaction note: Customer Sarah Jones complained about the mobile app crashing during checkout. She tried to purchase 3 items: a red XL jacket ($89.99), blue running shoes ($129.50), and a fitness tracker ($199.00). The app crashed after she entered her shipping address at 123 Main St, Portland OR, 97201. She has been a premium member since January 2024.',
response_format => TYPE OBJECT(note OBJECT(items_count NUMBER, price ARRAY(STRING), address STRING, member_date STRING)),
? => TRUE
);show_details returns the inference metadata (created, model, structured_output, usage). return_error_details instead controls how row errors are reported.
Source: docs.snowflake.comFor more control, such as constraints and required fields, pass a JSON schema as response_format instead. For simple tasks you don't even need to tell the model to answer in JSON. For complex ones, asking for JSON in the prompt can improve accuracy.
AI_COMPLETE(
...
response_format => {
'type': 'json',
'schema': {
'type': 'object',
'properties': {
'property_name': {
'type': 'string'
},
...
},
'required': ['property_name', ...]
}
}
)Checkpoint 4 of 6· Check yourself
A schema works with mistral-large2 but is rejected when the team switches to an OpenAI GPT model. What is the most likely fix?
OpenAI models require additionalProperties: false in every node and a required list that names every property.
“additionalProperties field must be set to false in every node of the schema.”Source: docs.snowflake.com
Sources4
4.Task-specific functions: pick the managed function for the job
For common jobs, you don't need to write prompts for AI_COMPLETE. Snowflake provides purpose-built managed functions for routine tasks that need no customization. The exam expects you to recognize which function fits which task. Notice which ones take files and which work across many rows.
| Function | What it does |
|---|---|
| AI_CLASSIFY | Classifies text or images into user-defined categories |
| AI_FILTER | Returns True/False for text or image input; usable in SELECT, WHERE, or JOIN ... ON |
| AI_EXTRACT | Extracts information from a string or file (text, images, documents); multilingual |
| AI_SENTIMENT | Extracts sentiment from text |
| AI_SUMMARIZE | Summarizes text, images and documents |
| AI_AGG | Aggregates a text column into insights across rows using your prompt; not subject to context window limits |
| AI_SUMMARIZE_AGG | Aggregates a text column into a summary across rows; not subject to context window limits |
| AI_TRANSLATE | Translates text between supported languages |
| AI_EMBED / AI_SIMILARITY | Generates an embedding vector / calculates embedding similarity between two inputs |
| AI_PARSE_DOCUMENT | Extracts text (OCR mode) or text with layout (LAYOUT mode) from staged documents; can extract images |
| AI_TRANSCRIBE | Transcribes staged audio and video, with timestamps and speaker information |
| AI_REDACT | Redacts personally identifiable information (PII) from text |
Arguments and return shapes the sources spell out:
- AI_CLASSIFY takes the input and an array of categories, for example ['refund','shipping','other']. It returns an object whose labels field is an array, so you read :labels[0] (the legacy CLASSIFY_TEXT returned a single :label). The AI_COUNT_TOKENS examples for ai_classify also show categories written as objects with label and description, plus an options object with task_description and examples.
- AI_EXTRACT takes the input in text and the questions to answer in the responseFormat argument. It returns a JSON object, not a string. The optional scores argument, set to TRUE, adds confidence scores. It replaces the legacy EXTRACT_ANSWER.
- AI_SENTIMENT takes the text and returns an object with a categories array, not the legacy FLOAT score. Each category record has a sentiment field with a value such as positive, negative, neutral, mixed or unknown. Pass entities as a second argument for entity-level (aspect-based) sentiment.
- AI_TRANSLATE works on input text with a source language and a target language: the AI_COUNT_TOKENS syntax for ai_translate lists input_text, source_language and target_language.
- AI_FILTER takes a text or file input, usually built with PROMPT, and returns a boolean, so it can sit in a WHERE clause.
- AI_AGG takes AI_AGG(<expr>, <instruction>) and returns a string. The instruction should be a declarative plain-English description of the data and the goal. It works with GROUP BY, and you can combine several columns with CONCAT or ||.
- AI_SIMILARITY computes a similarity score based on the vector cosine similarity of the embeddings of its two inputs.
- AI_REDACT detects and redacts PII from unstructured text; the sources give no further argument detail.
SELECT AI_CLASSIFY(review, ['refund','shipping','other']):labels[0] AS topic
FROM tickets;SELECT AI_EXTRACT(
text => doc_text,
responseFormat => {'total': 'What is the invoice total?'},
scores => TRUE
) AS answer
FROM docs;Two distinctions show up often. First, AI_AGG and AI_SUMMARIZE_AGG are *aggregate* functions: they combine many rows into one result and aren't limited by the model's context window. AI_SUMMARIZE works on a single input. Second, AI_PARSE_DOCUMENT and AI_TRANSCRIBE read files from a stage rather than text in a column.
The exam guide also lists SUMMARIZE. This is the legacy function in the SNOWFLAKE.CORTEX namespace. It returns a summary of the given text, and it is meant for English-language input (the Snowflake CLI command for it summarizes English-language text). It handles one text value per call, so it is not the multi-row aggregate. The migration guide lists AI_SUMMARIZE as its direct replacement, with arguments and output unchanged. AI_SUMMARIZE takes either text or a file, for example AI_SUMMARIZE(TO_FILE('@my_docs', 'cartoon_image.jpeg')). For a summary across many rows, use AI_SUMMARIZE_AGG.
Checkpoint 5 of 6· Match them up
Match each requirement to the function built for it
Tap a term, then the definition that fits it.
Each function is purpose-built for one task. Aggregation across rows is AI_SUMMARIZE_AGG, and the staged-file functions handle documents and audio.
“AI_SUMMARIZE_AGG: Aggregates a text column and returns a summary across multiple rows.”Source: docs.snowflake.com
5.PROMPT and TO_FILE: passing columns and files to AI functions
Many of the functions above accept files and combinations of columns. Two helper functions prepare those inputs. TO_FILE creates a reference to a file in an internal or external stage, for AI_COMPLETE and other functions that accept files. You pass the stage and the relative path, as in TO_FILE('@my_stage', 'document.pdf'). PROMPT builds a prompt object: a template string with numbered placeholders {0}, {1}, … plus the expressions that fill them. Those expressions can be column values or FILE values.
PROMPT doesn't format the string itself. It returns an OBJECT with template and args keys, and the AI function that receives it uses that object. Using a placeholder that has no matching expression is an error. Passing extra expressions that the template doesn't use is not an error.
SELECT AI_PARSE_DOCUMENT(
TO_FILE('@my_stage', 'document.pdf'),
{'mode': 'LAYOUT', 'page_split': true}
) AS parsed_doc;AI_COMPLETE('claude-4-sonnet',
PROMPT('Classify the input image {0} in no more than 2 words. Respond in JSON', img_file)) AS image_classification
FROM image_table;WITH reviews AS (
SELECT 'Wow... Loved this place.' AS review, 5 AS rating
UNION ALL
SELECT 'Crust is not good.', 2 AS rating
)
SELECT * FROM reviews
WHERE AI_FILTER(PROMPT('The reviewer enjoyed the restaurant: {0}, Rating: {1}', review, rating));Checkpoint 6 of 6· Check yourself
What does SELECT PROMPT('Hello, {0}! Today is {1}.', 'Alice', 'Monday') return?
PROMPT doesn't substitute values. It returns an object containing the template and the arguments, and the Cortex AI function that receives it uses that object.
“PROMPT does not perform any string formatting itself. It is intended to construct an object to be consumed by Cortex AI functions.”Source: docs.snowflake.com
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.A SQL type literal can define structured output for any form of AI_COMPLETE, including image and prompt-object calls.Why is that wrong?
Type literals work only with the single-string text prompt version of AI_COMPLETE. For other forms, use a JSON schema.
Covered in COMPLETE structured outputs: type literals and JSON schemas
2.If one row's AI_COMPLETE call fails, the whole multi-row query aborts.Why is that wrong?
By default, rows with errors return NULL and the query still completes. Pass return_error_details => TRUE to get the error message for each row.
Covered in AI_COMPLETE: the general-purpose function
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“To call any of these functions, your role needs the USE AI FUNCTIONS account-level privilege and one of the CORTEX_USER or AI_FUNCTIONS_USER database roles.”
↩︎ What Cortex AI Functions are and who can call them“Cortex AI Functions are optimized for throughput.”
↩︎ What Cortex AI Functions are and who can call them“Helper functions are purpose-built managed functions that reduce cases of failures when running other Cortex AI Functions”
↩︎ What Cortex AI Functions are and who can call them“AI_COMPLETE: Generates a completion for a given text string or image using a selected LLM. Use this function for most generative AI tasks.”
↩︎ AI_COMPLETE: the general-purpose function“These task-specific functions are purpose-built managed functions that automate routine tasks, like simple summaries and quick translations”
↩︎ Task-specific functions: pick the managed function for the job“AI_PARSE_DOCUMENT: Extracts text (using OCR mode) or text with layout information (using LAYOUT mode) from documents in an internal or external stage.”
↩︎ Task-specific functions: pick the managed function for the job“AI_TRANSCRIBE: Transcribes audio and video files stored in a stage, extracting text, timestamps, and speaker information.”
↩︎ Task-specific functions: pick the managed function for the job“TO_FILE: Creates a reference to a file in an internal or external stage for use with AI_COMPLETE and other functions that accept files.”
↩︎ PROMPT and TO_FILE: passing columns and files to AI functions“Snowflake Cortex features are provided as SQL functions and are also available in Python.”
↩︎ Key concept“For more interactive use cases where latency is important, use the REST API.”
↩︎ Checkpoint“AI_SUMMARIZE_AGG: Aggregates a text column and returns a summary across multiple rows.”
↩︎ Checkpoint - 2.
“Users must use a role that has been granted the SNOWFLAKE.CORTEX_USER database role.”
↩︎ What Cortex AI Functions are and who can call them“AI_COMPLETE is the updated version of COMPLETE. For the latest functionality, use AI_COMPLETE.”
↩︎ AI_COMPLETE: the general-purpose function“A prompt object that can support multiple images and text.”
↩︎ AI_COMPLETE: the general-purpose function“If the query processes multiple rows, rows with errors return NULL”
↩︎ Exam trap 2“If the query processes multiple rows, rows with errors return NULL”
↩︎ Prediction“All syntax variations accept an optional return_error_details BOOLEAN argument as the final parameter.”
↩︎ Checkpoint - 3.https://docs.snowflake.com/en/user-guide/snowflake-cortex/aisql-migrate-legacy-functionsOfficial docs
“The legacy options object becomes model_parameters, which holds only the model hyperparameters (temperature, top_p, max_tokens, guardrails).”
↩︎ AI_COMPLETE: the general-purpose function“To return the detailed JSON object (with choices, usage, model, and created), set show_details to TRUE.”
↩︎ AI_COMPLETE: the general-purpose function“AI_CLASSIFY returns an object whose labels field is an array. Read :labels[0] instead of :label.”
↩︎ Task-specific functions: pick the managed function for the job“Provide the questions to answer in the responseFormat argument, and set the optional scores argument to TRUE to include confidence scores.”
↩︎ Task-specific functions: pick the managed function for the job“AI_SENTIMENT returns an object with a categories array instead of a FLOAT score.”
↩︎ Task-specific functions: pick the managed function for the job“SNOWFLAKE.CORTEX.SUMMARIZE | AI_SUMMARIZE | Direct replacement.”
↩︎ Task-specific functions: pick the managed function for the job“AI_PARSE_DOCUMENT takes a Snowflake FILE object created with TO_FILE, rather than separate stage and path arguments.”
↩︎ PROMPT and TO_FILE: passing columns and files to AI functions - 4.
“AI_COMPLETE verifies each generated token against your structured output definition to ensure that the response conforms to your type structure.”
↩︎ COMPLETE structured outputs: type literals and JSON schemas“Begin your type literal with the TYPE keyword and use a SQL OBJECT as the top-level type.”
↩︎ COMPLETE structured outputs: type literals and JSON schemas“For more control over structured output, use a JSON schema as the value for response_format.”
↩︎ COMPLETE structured outputs: type literals and JSON schemas“Structured output is supported in snowflake-ml-python version 1.8.0 and later.”
↩︎ COMPLETE structured outputs: type literals and JSON schemas“using the show_details argument to return inference metadata”
↩︎ COMPLETE structured outputs: type literals and JSON schemas“Type literals are supported only for the single string text prompt version of AI_COMPLETE.”
↩︎ Exam trap 1“additionalProperties field must be set to false in every node of the schema.”
↩︎ Checkpoint - 5.
“AI_COUNT_TOKENS( 'ai_translate', <input_text>, <source_language>, <target_language> [, <return_error_details> ] )”
↩︎ Task-specific functions: pick the managed function for the job - 6.
“AI_AGG( <expr>, <instruction> )”
↩︎ Task-specific functions: pick the managed function for the job - 7.
“AI_REDACT | Detects and redacts personally identifiable information (PII) from unstructured text data.”
↩︎ Task-specific functions: pick the managed function for the job - 8.https://docs.snowflake.com/en/developer-guide/snowflake-cli/command-reference/cortex-commands/summarizeOfficial docs
“Summarizes the given English-language input text.”
↩︎ Task-specific functions: pick the managed function for the job - 9.
“SELECT AI_SUMMARIZE(TO_FILE('@my_docs', 'cartoon_image.jpeg')) AS image_summary;”
↩︎ Task-specific functions: pick the managed function for the job - 10.
“It is an error to use a placeholder in the template string that does not have a corresponding expression”
↩︎ PROMPT and TO_FILE: passing columns and files to AI functions“PROMPT does not perform any string formatting itself. It is intended to construct an object to be consumed by Cortex AI functions.”
↩︎ Checkpoint