AI functions
Igloo runs Snowflake’s AI functions (Cortex AI SQL) in SQL, with your own
model providers’ keys: AI_COMPLETE, AI_CLASSIFY, AI_FILTER,
AI_SENTIMENT, AI_EXTRACT, AI_SUMMARIZE, AI_TRANSLATE, AI_REDACT,
AI_EMBED, AI_SIMILARITY, AI_AGG, AI_SUMMARIZE_AGG, PROMPT,
AI_COUNT_TOKENS, SNOWFLAKE.CORTEX‘s older forms of them, and
Databricks’ AI_DECIDE. They call OpenAI or any server that speaks its API
(Azure OpenAI, vLLM, llama.cpp, Ollama, OpenRouter), Anthropic, Gemini,
Vertex AI, Amazon Bedrock, or a decision endpoint, through an AI
integration an admin creates. Igloo never resells inference: each call is
made with the integration’s keys, and the provider bills you at its own
prices.
-- Admins: a provider, the models SQL may name, and who may use it.CREATE AI INTEGRATION models PROVIDER = anthropic API_KEY = 'sk-ant-...' MODELS = ('claude-4-sonnet' = 'claude-sonnet-4-5-20250929', 'claude-haiku' = 'claude-haiku-4-5-20251001') DEFAULT_MODEL = 'claude-haiku' PRICES = ('claude-sonnet-4-5-20250929' = (3, 15), 'claude-haiku-4-5-20251001' = (1, 5));GRANT USAGE ON INTEGRATION models TO ROLE analysts;
-- Analysts, in Snowflake's dialect: a one-line summary of each campaign's brief.SELECT campaign_id, AI_COMPLETE(model => 'claude-4-sonnet', prompt => PROMPT('Summarize this campaign brief in one line: {0}', brief)) AS summaryFROM demo.campaigns;Each distinct prompt is sent once, however many rows hold it, and its answer is kept: running the statement again, or another that asks the same of the same model, calls no provider and costs nothing.
AI integrations
Section titled “AI integrations”CREATE [OR REPLACE] AI INTEGRATION [IF NOT EXISTS] name PROVIDER [=] provider [option ...]ALTER AI INTEGRATION [IF EXISTS] name SET option ... | UNSET name, ...DROP [AI] INTEGRATION [IF EXISTS] nameSHOW AI INTEGRATIONSGRANT USAGE ON INTEGRATION name TO [ROLE | USER] nameREVOKE USAGE ON INTEGRATION name FROM [ROLE | USER] nameOnly admins create, change, drop and grant integrations; a user needs
USAGE on one, directly or through a role, to call it. AI and
notification integrations share one set of names, as
Snowflake’s integrations do. AI functions are off, and fail with SQLSTATE
55000, until an integration exists.
PROVIDER |
What it reaches | Needs |
|---|---|---|
openai |
OpenAI’s API, https://, or any server that speaks it at BASE_: vLLM, llama.cpp, Ollama (http://), OpenRouter |
API_, unless BASE_ is a server without one |
azure_ |
Azure OpenAI’s v1 API at BASE_, https://; models are deployments |
BASE_, API_ (sent as api-key); API_ adds ?api-version= |
anthropic |
Anthropic’s Messages API | API_ |
gemini |
Google’s Gemini API | API_ |
vertex |
Gemini on Vertex AI | SERVICE_ (a service account’s JSON key) with PROJECT and REGION, or an express-mode API_ |
bedrock |
Amazon Bedrock’s Converse API | REGION, and AWS_ and AWS_ (requests are signed, SigV4) or a Bedrock API_ |
decisions |
A decision endpoint that takes a state and named questions, at BASE_/decisions |
BASE_, DECISION_ |
nixtla |
Nixtla’s TimeGPT API, https://, or a deployment of it at BASE_ (Microsoft Foundry’s TimeGPT): time series models alone |
API_ |
sagemaker |
SageMaker endpoints of Chronos models (Chronos-2, Chronos-Bolt from JumpStart): time series models alone | REGION, AWS_ and AWS_ (SigV4) |
bigquery |
BigQuery’s AI., run as a query in your project, TimesFM 3.0 among its models: time series models alone |
SERVICE_, PROJECT, and REGION for the query’s location ('US') if it must run in one |
| Option | Meaning |
|---|---|
BASE_ |
Where the provider’s API is; by default the provider’s own. HTTPS only, and only public addresses, unless IGLOO_ names the host (configuration). |
API_, HEADERS (‘name’ = ‘value’,, AWS_, AWS_, AWS_, SERVICE_ |
Credentials, stored encrypted in the metadata database under a key every replica shares, and never shown: not by SHOW AI INTEGRATIONS, not in errors, not in the query history. HEADERS are sent with every request, as a gateway’s own key. |
API_ |
Anthropic’s anthropic-version (by default 2023-06-01), or Azure’s api-version. |
REGION ‘…, PROJECT ‘… |
Bedrock’s region; Vertex AI’s location and project. |
MODELS (‘name’ = ‘provider model’, |
The model names SQL may use, Snowflake’s among them, and the provider’s model each stands for. A name no usable integration maps fails with SQLSTATE 42704 and says how to map it; nothing falls back to another model. Map to dated snapshots (claude-sonnet-4-5-20250929, not claude-sonnet-4-5) so the same name means the same model tomorrow. |
DEFAULT_ |
The model of the functions whose model Snowflake chooses. A name in MODELS or the provider’s own. |
EMBEDDING_, DECISION_ |
The models of embeddings and of decisions. |
PRICES (‘provider model’ = (input, |
US dollars per million input and output tokens, for the cost cap, EXPLAIN and igloo.. A model without a price is called, and counted, at no cost. |
MAX_ |
Requests in flight to the provider from each replica, 8 by default, at most 256. |
ENABLED TRUE | FALSE |
A disabled integration is refused. |
COMMENT ‘… |
When several integrations a user may use map the same model, or have a
default model, the session chooses with SET ai_integration = 'name'.
Integrations also serve hosted time series models to BigQuery’s
AI.FORECAST and AI.DETECT_ANOMALIES and Databricks’ ai_forecast and
ai_detect_anomalies: a nixtla, sagemaker or bigquery integration,
a vertex integration mapping a TimesFM endpoint, or a bedrock one
mapping a Marketplace endpoint of Chronos (see
ML functions).
Functions
Section titled “Functions”| Snowflake | Igloo, as DuckDB’s dialect calls it | Returns |
|---|---|---|
AI_ |
ai_; with response_ or show_, ai_ |
Text; with response_, an OBJECT of its schema; with show_, {“choices”: [{“messages”: … (structured_ in place of choices with a response_) |
SNOWFLAKE. and (model, |
ai_, ai_ |
Text; with a conversation, a string holding the answer’s JSON, as Snowflake’s |
PROMPT(‘… |
json_ |
An OBJECT {“template”,, which the AI functions read as the template with the arguments in place, as text (NULL as empty) |
AI_, SNOWFLAKE. |
ai_ |
The input’s tokens for the model that would serve function: Anthropic and Gemini count them, at no cost; for other providers Igloo estimates them, about four bytes a token |
AI_ |
ai_ |
{“labels”: […: the one category that fits best, or with {‘output_ every one that applies. Categories are labels or {‘label’, objects; the config takes task_, examples ([{‘input’,) and model |
SNOWFLAKE. |
ai_ |
{“label”: … |
AI_, the predicate as text or PROMPT(… |
ai_ |
BOOLEAN: whether the statement is true, or the question’s answer yes. See plain predicates first |
AI_ |
ai_ |
{“categories”: [{“name”: “overall”,, each positive, negative, neutral, mixed or unknown (the text does not speak of it); at most 10 categories of 30 characters |
SNOWFLAKE. |
ai_ |
A FLOAT from -1 to 1 |
AI_ |
ai_ |
{“error”: null,, or {“error”: “… for a row the model could not answer. responseFormat is {‘key’: ‘question’,, [‘question’,, [[‘key’, or {‘schema’: {…, a JSON schema of an object |
SNOWFLAKE. |
ai_ |
[{“answer”: …,, or [] where the text does not answer it |
AI_, SNOWFLAKE. |
ai_ |
Text: a summary of a few sentences, or text of at most 110 characters as it is, with no call |
AI_, SNOWFLAKE. |
ai_ |
Text. Languages are Snowflake’s codes (en, de, ja, …); '' as the source is the text’s own |
AI_ |
ai_, ai_ |
Text with each piece of personal information replaced by its category, as [NAME]; with mode 'detect', {“spans”: [{“category”,, offsets in characters. Categories are Snowflake’s 13: NAME, EMAIL, PHONE_, DATE_, GENDER, AGE, ADDRESS, NATIONAL_, PASSPORT, TAX_, PAYMENT_, DRIVERS_, IP_ |
AI_ |
ai_ |
The input’s vector, a list of FLOATs, which VECTOR_ and the other vector functions take and a VECTOR column stores |
SNOWFLAKE., EMBED_ |
ai_ |
A VECTOR(FLOAT, or (FLOAT,; a model whose vectors have other dimensions fails the statement |
AI_ |
ai_ |
The cosine similarity of the two inputs’ vectors, from the config’s model or the integration’s EMBEDDING_ |
AI_, AI_ |
ai_ |
Aggregates: the answer to the task, or a summary, over each group’s values, however many; NULL for a group of none. See AI_AGG |
AI_, as Databricks’ ai_ |
ai_ |
{“response”: {“answers”: {…; see decision models |
Arguments are by position or by name (model => ...), as in Snowflake.
model_parameters takes temperature, top_p and max_tokens (4,096 by
default); Anthropic’s newer API refuses sampling settings, so Igloo never
sends them to Anthropic. guardrails => TRUE (Cortex Guard) is refused.
Igloo adds refresh => TRUE, which asks the provider again rather than
reading the cache, and keeps the new answer.
Errors. As in Snowflake since its 2026_02 behavior change, a row whose
own input the provider refuses or answers with something unreadable gets
NULL, and return_error_details => TRUE returns {"value": ..., "error": ...} instead; the statement then sends a NOTICE saying how many rows did.
AI_EXTRACT puts a row’s error in its own error field. AI_REDACT,
AI_AGG and SNOWFLAKE.CORTEX’s functions fail the statement instead, as
Snowflake’s do. A failure that is not the row’s fails the statement with the
integration’s name and the provider’s message, its keys scrubbed: a key the
provider refuses (401, 403), a model or endpoint it does not have (404), a
spend limit it enforces, or a provider that does not answer: requests
refused for their rate (429, with retry-after honored) or failing on the
provider’s side (5xx, 529) or timing out are sent again, five times in all
over about 8 seconds plus what retry-after asks, before they fail it.
How the task functions ask. AI_CLASSIFY, AI_FILTER, AI_SENTIMENT,
AI_EXTRACT, AI_SUMMARIZE, AI_TRANSLATE and AI_REDACT ask the
integration’s DEFAULT_MODEL (or the model their config names), with
Igloo’s instructions for the function as the system prompt and the row’s
text as the user’s message, and ask for JSON of a schema where the answer
has a shape (OpenAI enforces it; Gemini answers JSON; Anthropic and Bedrock
are given the schema in the instructions). The instructions are the same
for every row, which providers’ prompt caches bill for less, and are
versioned in the cache’s key. AI_CLASSIFY’s categories, like Snowflake’s,
are sent with every row. AI_EMBED and AI_SIMILARITY send up to 64
distinct texts per request, and share what the cache keeps of each text’s
vector.
AI_AGG
Section titled “AI_AGG”AI_AGG(expr, task) and AI_SUMMARIZE_AGG(expr) are aggregates, with
GROUP BY or over the whole result, not window functions:
SELECT campaign_id, AI_AGG(comment, 'What do viewers say about the creative?') AS feedbackFROM demo.ad_comments GROUP BY campaign_id;Igloo collects a group’s values, without NULLs, and sorts them, so the
same group makes the same requests. Values that fit one request (about
16,000 tokens) are sent at once. More are sent in chunks of that size, each
answered with an intermediate result, and the intermediate results are
combined, a request per chunk of them, until one request holds them all and
gives the answer. Each request is cached by its chunk: a group that gained
rows asks again only for the chunks that changed and the requests that
combine them. As Snowflake’s, AI_AGG fails the statement on an error.
EXPLAIN counts the first round of requests.
Decision models
Section titled “Decision models”A decision model answers questions about a state with probabilities, in
one pass and without writing text, which costs far less per row than a
generative model. An integration names one with DECISION_MODEL: an
OpenAI integration’s is asked through OpenAI’s POST /decisions, and a
decisions integration’s through the state-and-questions shape that
Snowflake’s snowflake-decision and Databricks’ ai_decide share.
Where an integration a user may use has a decision model, it answers:
AI_FILTER, as a yes-or-no question about the predicate: TRUE where its probability reaches the session’sai_decision_threshold(0.5 by default;SET ai_decision_threshold = 0.8).AI_CLASSIFY, as a choice of the categories, or withoutput_modemultia yes-or-no question for each category, kept from the threshold.task_descriptionandexamplesgo in the questions’ instructions.AI_DECIDE(state, questions), whose questions are{'name': {'type': 'noul' | 'choice' | 'score', 'instructions': ..., 'criteria': ...}}: a yes-or-no question’s criteria{'true': ..., 'false': ...}, a choice’s{'option': 'description', ...}or['option', ...], a score’s levels, lowest first. Each answer has itsprobability, or itschoice,score,probabilitiesandconfidence, or is{"type": "refusal"}.AI_COMPLETEwith a modelMODELSmaps to the decision model, as Snowflake’ssnowflake-decision, whose prompt isTO_JSON({'state': ..., 'questions': {...}}):{"answers": {...}}, a yes-or-no question’s probability asnoul.
AI_FILTER and AI_CLASSIFY whose config names a model ask that model
instead, and SET ai_integration chooses another integration.
Plain predicates first
Section titled “Plain predicates first”DuckDB orders a filter’s conditions by its own estimate of their cost, in
which a call of an AI function is cheap, so it would call the provider for
rows the plain conditions beside it then drop. Igloo’s translation of a
WHERE, HAVING, QUALIFY or ON that is a conjunction tests the plain
conditions first:
SELECT ticket_id FROM demo.ticketsWHERE AI_FILTER(PROMPT('Does this ask for a refund? {0}', body)) AND created_at > '2026-10-01';-- runs as-- WHERE created_at > '2026-10-01'-- AND CASE WHEN (created_at > '2026-10-01') THEN (ai_filter(...)) ELSE FALSE ENDwhich keeps the same rows. A clause with OR between an AI predicate and
others, or whose plain conditions call RANDOM() or the like, stays as it
is written. In DuckDB’s own dialect, write the CASE yourself.
EXPLAIN counts AI_FILTER as keeping every row the cache does not
answer, so that the functions after it are counted for every row it might
keep.
A statement makes at most IGLOO_AI_MAX_CALLS calls to providers (1,000
by default) whose estimated cost at the integrations’ prices stays under
IGLOO_AI_MAX_COST_USD ($1 by default). One that would go over fails
before it sends the call (SQLSTATE 54000), naming the cap; distinct
inputs the cache answers are not calls. An admin raises a role’s caps, or
lifts them with 0, as with statement_timeout; a session can lower its
own:
ALTER ROLE analysts SET ai_max_calls = 50000;ALTER ROLE analysts SET ai_max_cost_usd = 25;SET ai_max_calls = 100; -- this session's statements, never above the role'sSHOW ai_max_calls;Where several of a user’s roles set a cap, the most generous applies.
Cost and usage
Section titled “Cost and usage”EXPLAIN of a query that calls AI functions says what they would send,
without sending it: Igloo runs the query with each call counted rather
than made, and adds rows such as
ai calls | models/claude-sonnet-4-5-20250929: 1240 distinct inputs to send, about 186000 input and at most 1269760 output tokens, about $19.6044ai cache | 310 distinct inputs answered from the cache, at no costai caps | at most 1000 calls and $1 a statement (0 is no cap)so that a statement over its caps can be found before it runs. Output
tokens are bounded by max_tokens, which is why their estimate is high.
The query history records each statement’s calls, cache hits, tokens and
estimated cost (ai_calls, ai_cache_hits, ai_input_tokens,
ai_output_tokens, ai_cost_usd, ai_models in igloo.query_history),
and igloo.usage sums them by day, user, role and query tag, for
chargeback to clients and campaigns.
The cache
Section titled “The cache”Answers are kept in the metadata database, for every replica, for
IGLOO_AI_CACHE_RETENTION (30 days by default), keyed by a SHA-256 of the
function, the integration, its full address and its API version, region
and project, the provider’s model, the version of Igloo’s template for the
function, the options and the input. Integrations never share answers, even
at one address, and an integration dropped and created again starts
afresh; CREATE OR REPLACE and new keys keep its answers. A rerun
returns the same answer and costs nothing, which providers’ sampling
settings cannot promise: repeatability comes from the cache. refresh => TRUE asks again, and IGLOO_AI_CACHE=off keeps nothing.
Each answer is tagged with the tables its statement read: those DuckDB loaded from the catalog, views read through, and every table the statement’s parse names. A statement that may read files, or that Igloo could not analyze, tags its answers as derived from any table. Erasure requests purge every answer derived from a table they erase from, the person’s or not, and keep statements that began before them from keeping anything more; a request does not complete while any such answer remains.
Where they run
Section titled “Where they run”The functions run in Igloo’s own process, as DuckDB scalar functions, and
their calls go out through Igloo’s egress guard: never through a DuckDB
extension, whose HTTP client Igloo’s lockdown of DuckDB would not see.
Calls go out from the coordinator, which holds the integrations’ keys:
with distributed execution, workers read,
filter and aggregate, and the coordinator calls the provider for what they
return; workers hold no provider’s keys. Calls of one statement on DuckDB’s
threads share one request per distinct input, and each integration has at
most MAX_CONCURRENCY requests in flight per replica.
They run in queries, INSERT ... SELECT, CREATE TABLE ... AS and
tasks’ statements, in either dialect. In a cursor, COPY ... TO, or over
Arrow Flight SQL they fail (SQLSTATE 0A000).
Governance
Section titled “Governance”- Policies apply first. Masking and row access policies rewrite a statement before it runs, so a function sees, and a provider receives, only what the user may see: a masked email reaches the provider masked.
- Clean rooms. A statement that calls AI functions and reads a table a clean room confines is refused, admins included: a dataset’s rows are for the room’s approved templates alone.
- Records. The history records each statement’s models, tokens and cost; the log records each change of an integration and who made it.
Known differences
Section titled “Known differences”- Images, documents and audio (
TO_FILE, the file forms of the functions) are not supported, nor are fine-tuned models or Cortex Guard. AI_COUNT_TOKENSestimates tokens for providers that cannot count them.- An Iceberg table’s
VECTORcolumn is a list (see Snowflake SQL). - The task functions’ answers are your models’ and Igloo’s instructions’,
not Snowflake’s: the same shapes, not always the same labels or words.
AI_EXTRACTgives no extraction scores, norEXTRACT_ANSWERitsscore. Vectors fromAI_EMBEDare your embedding model’s, which are not comparable with vectors Snowflake’s models made. - Providers without embeddings (Anthropic, and Bedrock models other than
Amazon Titan’s and Cohere’s) fail
AI_EMBEDandAI_SIMILARITYwith SQLSTATE22023.