- Categories:
String & binary functions (AI Functions)
AI_COMPLETE (Prompt object)¶
Note
AI_COMPLETE is the updated version of COMPLETE (SNOWFLAKE.CORTEX). For the latest functionality, use AI_COMPLETE.
Generates a response (completion) for a prompt object. The prompt can contain FILE objects, which may contain images or documents.
Syntax¶
The function can be used with either positional or named argument syntax.
Arguments¶
modelA string specifying the model to be used. For text only inputs, you can use one of the following models:
claude-4-opusclaude-4-sonnetclaude-3-7-sonnetclaude-3-5-sonnetdeepseek-r1llama3-8bllama3-70bllama3.1-8bllama3.1-70bllama3.1-405bllama3.3-70bllama4-maverickllama4-scoutmistral-largemistral-large2mistral-7bmixtral-8x7bopenai-gpt-4.1openai-o4-minisnowflake-arcticsnowflake-llama-3.1-405bsnowflake-llama-3.3-70b
For image inputs, you can use one of the following models:
claude-4-opusclaude-4-sonnetclaude-3-7-sonnetclaude-haiku-4-5claude-sonnet-4-5claude-opus-4-5claude-sonnet-4-6claude-opus-4-6llama4-maverickllama4-scoutpixtral-largeopenai-o4-miniopenai-gpt-4.1openai-gpt-5openai-gpt-5-chatopenai-gpt-5-miniopenai-gpt-5-nanoopenai-gpt-5.1openai-gpt-5.2gemini-2.5-flashgemini-2.5-flash-litegemini-3-pro
For document inputs, you can use one of the following models:
gemini-3-proclaude-4-opusclaude-4-sonnetclaude-3-7-sonnetclaude-haiku-4-5claude-sonnet-4-5claude-opus-4-5
Supported models might have different costs.
promptA prompt object containing text and, optionally, images or documents.
model_parameters
An object containing zero or more of the following options that affect the model’s
hyperparameters. See LLM Settings (https://www.promptingguide.ai/introduction/settings).
temperature: A value from 0 to 1 (inclusive) that controls the randomness of the output of the language model. A higher temperature (for example, 0.7) results in more diverse and random output, while a lower temperature (such as 0.2) makes the output more deterministic and focused.Default: 0
top_p: A value from 0 to 1 (inclusive) that controls the randomness and diversity of the language model, generally used as an alternative totemperature. The difference is thattop_prestricts the set of possible tokens that the model outputs, whiletemperatureinfluences which tokens are chosen at each step.Default: 0
max_tokens: Sets the maximum number of output tokens in the response. Small values can result in truncated responses.Default: 4096 Maximum allowed value: 8192
guardrails: Filters potentially unsafe and harmful responses from a language model using Cortex Guard. EitherTRUEorFALSE. The default value isFALSE.
Important
If you’re using AI_COMPLETE with a prompt object, you can’t provide a JSON schema to get a structured output as a response.
To get a structured output as the response, use the response_format parameter with AI_COMPLETE (Single string). For more information using structured outputs, see AI_COMPLETE structured outputs.
Example¶
Passing multiple images as the input¶
The following example compares two images by passing both as input to the AI_COMPLETE function and asking whether both are pictures of cats:
Batch processing images from a directory or table¶
For batch processing of multiple images, performing the same operation on each, store the image files in the same stage. Apply the AI_COMPLETE function to each row of the table.
Note
The stage must have a directory table to retrieve the paths to its files.
First, create the table by retrieving the image locations from the directory, convert these to FILE objects, and storing the resulting FILE objects in a column in a table. Use SQL like the following:
Then, apply the AI_COMPLETE function to the column containing the FILE objects. The following example classifies each image in the table:
Response:
If you already have a table with paths to the images, you can use the TO_FILE function to construct the FILE objects within the query:
You can also retrieve the images to be processed directly from a stage’s directory, as shown here:
Providing images and prompts in a table¶
To perform a different operation on each image in a table, provide the images and their corresponding prompts in a
table. In the following example, the table contains the stage path of each image in the img_path column and the
prompt in the prompt column.
Usage notes for processing images¶
To process multiple images, specify a prompt object in the function call that defines a prompt template and the associated image files. You can use the PROMPT function to create this object. The prompt template can contain numbered placeholders (
{0},{1}, etc.) that correspond to the images in the prompt object. Use the TO_FILE function to specify the document files in the prompt object.Only text and images are supported. Video and audio files are not supported.
Supported image formats:
.jpg.jpeg.png.gif.webp
The
pixtralandllama4models also support.bmp.The maximum image size is 10 MB for most models, and 3.75 MB for
claudemodels.claudemodels do not support images with resolutions above 8000x8000.The stage containing the images must have server-side encryption enabled. Client-side encrypted stages are not supported.
The function does not support custom network policies.
Stage names are case-insensitive; paths are case-sensitive.
Usage notes for processing documents¶
To process multiple documents, specify a prompt object in the function call that defines a prompt template and the associated document files. You can use the PROMPT function to create this object. The prompt template can contain numbered placeholders (
{0},{1}, etc.) that correspond to the documents in the prompt object. Use the TO_FILE function to specify the document files in the prompt object.Only text and documents are supported. Video and audio files are not supported.
All models support these formats:
.txt,.md, and.pdf. Claude models also support.txt,.md,.pdf,.doc,.docx,.xls,.xlsx,.csv, and.xhtml.Claude models have a maximum document size of 4.5 MB. Gemini 3 Pro has a maximum document size of 10 MB.
The function does not support custom network policies.
Stage names are case-insensitive; paths are case-sensitive.
