Documentation Index
Fetch the complete documentation index at: https://docs.narrative.io/llms.txt
Use this file to discover all available pages before exploring further.
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. UseAI_COMPLETE to enrich, classify, or extract structured data from text columns without leaving NQL.
Syntax:
| Parameter | Type | Description |
|---|---|---|
model | STRING | The model identifier to use (e.g., 'openai-gpt-5'). Available models depend on your Snowflake Cortex configuration. |
prompt | column reference | A column containing the prompt text. Must be a column reference—string literals are not supported. Build prompts in a CTE or subquery first. |
model_parameters | STRING | A JSON string of model configuration options. Use '{}' for defaults. Supports keys like temperature and max_tokens. |
response_format | STRING | A JSON string defining the expected output structure. Contains a type field and a schema field with a standard JSON Schema definition. |
show_details | BOOLEAN | When TRUE, the response includes a structured_output array with the full typed response. When FALSE, returns a plain string response. |
show_details is TRUE, the returned JSON has this structure:
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.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:
| Error | Cause | Resolution |
|---|---|---|
Insufficient privileges to operate on database role 'CORTEX_USER' | The Narrative application has not been granted snowflake.cortex_user. | Run the grant from the cookbook setup. |
Function AI_COMPLETE does not exist | Query was run against a non-Snowflake data plane. | AI_COMPLETE is Snowflake-only. Use a Model Inference job on other data planes. |
Model '<id>' not available in this region | Cross-region Cortex access is not enabled. | Set CORTEX_ENABLED_CROSS_REGION = 'ANY_REGION' on the account (see cookbook setup). |
AI_COMPLETE vs a Model Inference job:
Use AI_COMPLETE when… | Use a Model Inference job when… |
|---|---|
| You need row-level inference inline in NQL | You are calling inference from the SDK or API, not a query |
| Your data plane is Snowflake | You need to run on a non-Snowflake data plane |
| You want to materialize enriched results as a view or table | You need a single on-demand completion (not a batch) |
CALL_MODEL_FUNCTION
Invokes a function on a custom model registered in the Snowflake ML Model Registry. UseCALL_MODEL_FUNCTION to run predictions, embeddings, or other operations from your own trained models directly within NQL.
Syntax:
| Parameter | Type | Description |
|---|---|---|
model_name | STRING | 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. |
NULL:
Related content
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

