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.
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:
Parse the structured output into individual columns:
SELECT CAST( PARSE_JSON(result)['structured_output'][0]['raw_message']['category'] AS STRING ) AS category, CAST( PARSE_JSON(result)['structured_output'][0]['raw_message']['confidence'] AS DOUBLE ) AS confidenceFROM company_data."enriched_results"
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.
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:
The model identifier, optionally schema-qualified. Use 'schema.model_name' or '"schema"."model_name"' to specify a schema. If no schema is provided, defaults to the MODELS schema.
model_version
STRING or NULL
The model version to invoke. Pass NULL to use the default version.
model_function
STRING
The name of the function to call on the model (e.g., 'PREDICT').
arg0, arg1, ...
any
Zero or more arguments passed to the model function. Typically column references containing the input data.
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:
{"OUTPUT": "predicted_value"}
Examples:Call a custom model’s predict function with a single input column:
SELECT CALL_MODEL_FUNCTION( 'my_schema.product_classifier', 'v2', 'PREDICT', company_data."products".product_name ) AS predictionFROM company_data."products"
Use the default model version by passing NULL:
SELECT CALL_MODEL_FUNCTION( 'sentiment_model', NULL, 'PREDICT', company_data."reviews".review_text ) AS sentimentFROM company_data."reviews"
Parse the model output into typed columns:
WITH predictions AS ( SELECT company_data."products".product_id, CALL_MODEL_FUNCTION( 'my_schema.product_classifier', 'v2', 'PREDICT', company_data."products".product_name ) AS raw_prediction FROM company_data."products")SELECT predictions.product_id, CAST(PARSE_JSON(predictions.raw_prediction)['OUTPUT'] AS STRING) AS predicted_categoryFROM predictions
Compare outputs across model versions:
SELECT company_data."products".product_id, CALL_MODEL_FUNCTION( 'my_schema.classifier', 'v1', 'PREDICT', company_data."products".product_name ) AS v1_prediction, CALL_MODEL_FUNCTION( 'my_schema.classifier', 'v2', 'PREDICT', company_data."products".product_name ) AS v2_predictionFROM company_data."products"
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"'.