Skip to main content

AI and ML functions

These functions run AI and machine learning operations directly within your query, enabling LLM inference, custom model predictions, and AI-powered data enrichment at scale.
AI and ML functions are currently available on Snowflake data planes only. They are not supported on AWS-hosted data planes.

AI_COMPLETE

Sends a prompt to a large language model and returns the response as a JSON string. Use AI_COMPLETE to enrich, classify, or extract structured data from text columns without leaving NQL. Syntax:
Parameters: Returns: STRING — A JSON string containing the model’s response. When show_details is TRUE, the returned JSON has this structure:
Examples: Classify a text column using structured output:
Parse the structured output into individual columns:
Use model parameters to control response behavior:
The prompt parameter must be a column reference. To build dynamic prompts from multiple columns, use a CTE to concatenate values into a single prompt column, then pass that column to AI_COMPLETE. See the data enrichment cookbook for a complete example.
Because AI_COMPLETE runs within your Snowflake data plane, your data never leaves your infrastructure. No external API calls are made to model providers. See Data Privacy in Model Inference for details.
Setup requirements: Before AI_COMPLETE can run, the customer’s Snowflake account must grant the Cortex role to the Narrative application and enable cross-region model access. See the data enrichment cookbook for the exact GRANT statements. Common errors: When to use AI_COMPLETE vs a Model Inference job: Related: Model Inference Overview, Structured Output, Data Enrichment Cookbook

CALL_MODEL_FUNCTION

Invokes a function on a custom model registered in the Snowflake ML Model Registry. Use CALL_MODEL_FUNCTION to run predictions, embeddings, or other operations from your own trained models directly within NQL. Syntax:
Parameters: Returns: STRING — A JSON string containing the model function’s output. The return format depends on the model’s function signature. Custom models typically return JSON objects:
Examples: Call a custom model’s predict function with a single input column:
Use the default model version by passing NULL:
Parse the model output into typed columns:
Compare outputs across model versions:
When no schema is specified in the model name, the function defaults to the MODELS schema. To reference a model in a different schema, use dot notation: 'my_schema.model_name' or quoted identifiers: '"MY_SCHEMA"."MODEL_NAME"'.
Related: AI_COMPLETE, Model Inference Overview

Data Enrichment with AI

Complete cookbook for enriching data using AI_COMPLETE

Model Inference

How AI inference works within your data plane

Structured Output

JSON Schema for predictable AI responses

All Functions

Browse all function categories