Snowflake AI SQL Functions
AI SQL functions put language intelligence inside ordinary queries. An analyst writes one SELECT statement and gets summaries, categories, translations, or extracted facts for every row of a table. No separate service, script, or data export is needed.
The Assembly Line Comparison
Picture a factory conveyor belt that carries thousands of parcels. A worker at one station stamps a label on each parcel, and the belt keeps moving. An AI function works like that station. The table rows ride the belt, the function reads each row's text, and the result column carries the label.
AI FUNCTION ON A TABLE
======================
support_tickets result
+----+---------------------------+ +----+------------+
| id | message | | id | category |
+----+---------------------------+ --> +----+------------+
| 1 | My card was charged twice | | 1 | billing |
| 2 | App crashes on login | | 2 | technical |
| 3 | Need a quote for 50 seats | | 3 | sales |
+----+---------------------------+ +----+------------+
AI_CLASSIFY reads each rowThe Main Functions
FUNCTION WHAT IT RETURNS
------------------- ------------------------------------------------
AI_COMPLETE Free-form text from a prompt, the most general tool
AI_CLASSIFY The best matching label from a list you provide
AI_FILTER TRUE or FALSE for a yes or no question about text
AI_SENTIMENT Mood of a text, such as positive or negative
AI_SUMMARIZE_AGG One summary across many rows
AI_TRANSLATE Text converted from one language to another
AI_EXTRACT Specific facts pulled from text or documents
AI_EMBED A numeric vector that captures meaning
AI_REDACT Text with personal details masked
AI_PARSE_DOCUMENT Text and layout from PDFs and scanned filesAI_COMPLETE replaces the older COMPLETE function. Snowflake is retiring the older name, so new work should use AI_COMPLETE.
Classifying Text
SELECT id,
message,
AI_CLASSIFY(message, ['billing', 'technical', 'sales']):labels[0]::STRING AS category
FROM support_tickets
LIMIT 10;The function returns a small JSON object with a labels list. The path :labels[0] picks the best label, and the double colon casts it to text.
Answering Yes or No Questions
SELECT id, message
FROM support_tickets
WHERE AI_FILTER('Does this message describe a payment problem? ' || message);AI_FILTER works inside a WHERE clause and keeps rows where the model answers yes.
Free-Form Prompts
SELECT id,
AI_COMPLETE(
'llama3.1-8b',
'Write a polite one-sentence reply to this customer message: ' || message
) AS draft_reply
FROM support_tickets
LIMIT 5;Models in the list change over time, so confirm the available model names in your region.
Summaries and Translation
-- One summary for all reviews of each product
SELECT product_id,
AI_SUMMARIZE_AGG(review_text) AS review_summary
FROM product_reviews
GROUP BY product_id;
-- Translate feedback to English
SELECT AI_TRANSLATE(feedback_text, 'es', 'en') AS english_text
FROM customer_feedback;Writing Good Prompts
- State the task in one clear sentence.
- Name the allowed answers when you need a fixed set of labels.
- Give a short example when the task is unusual.
- Ask for a specific format, such as JSON with named fields, when later steps parse the answer.
- Keep input text short, and strip signatures or repeated headers first.
Storing Results
Run a function once and save the output. Repeating the call in every dashboard query wastes money and gives slightly different answers each time.
CREATE TABLE ticket_labels AS
SELECT id,
AI_CLASSIFY(message, ['billing', 'technical', 'sales']):labels[0]::STRING AS category,
CURRENT_TIMESTAMP() AS labeled_at
FROM support_tickets;Checking Quality
Sample a few hundred results and compare them with human judgment. Track the share of matches and adjust the prompt until accuracy suits the use case. Keep a human review step for decisions that affect customers directly.
A Practical Scenario
A travel company receives thousands of feedback comments in several languages. An analyst translates every comment to English, classifies each one by topic, and measures sentiment. A monthly summary per destination condenses the findings for managers. The whole pipeline is four SQL statements that run in a few minutes.
Frequently Asked Questions
Do AI functions give the same answer every time?
Language models can vary slightly between calls. Store results in a table when stable answers matter for reports, and lower the model's randomness setting when the function offers one.
Which model should I pick?
Smaller models cost less and answer simple tasks well. Larger models handle subtle reasoning. Test two or three models on a sample and compare accuracy against cost.
Rollout Advice
Pick one concrete use case, such as ticket categories, and measure results against a human-labeled sample. Share accuracy numbers with business owners before expanding to other text columns. Clear evidence builds trust in the output.
Key Points
- AI SQL functions run language tasks directly on table columns.
- AI_COMPLETE handles open prompts; AI_CLASSIFY and AI_FILTER handle labels and yes or no checks.
- AI_SUMMARIZE_AGG, AI_TRANSLATE, AI_EXTRACT, and AI_REDACT cover common text jobs.
- Test on small samples and save results to avoid repeat costs.
- Clear prompts and sampled reviews keep quality high.
