Categories:

String & binary functions (AI Functions) , File functions (AI Functions)

AI_COMPLETE

Note

AI_COMPLETE is the updated version of COMPLETE (SNOWFLAKE.CORTEX). For the latest functionality, use AI_COMPLETE.

Generates a response (completion) from text or an image using a supported language model. You can provide:

Syntax

The syntax for the function depends on the type of input that you provide. For information about the syntax, see the following sections:

All syntax variations accept an optional return_error_details BOOLEAN argument as the final parameter. When set to TRUE, the function returns an OBJECT that contains the value and the error message, one of which is NULL depending on whether the function succeeded or failed. See Error behavior for details.

Error behavior

By default, if AI_COMPLETE can’t process the input, the function returns NULL. If the query processes multiple rows, rows with errors return NULL and don’t prevent the query from completing.

The return value on error depends on the return_error_details argument. The following table shows the return value based on the return_error_details argument:

return_error_details

Return value

Description

FALSE

Not passed

NULL

TRUE

OBJECT with value and error fields

value: The completion response (same type as the normal return value), or NULL if an error occurred.

error: A VARCHAR value that contains the error message if an error occurred, or NULL if the function succeeded.

For more information about error handling for AI functions, see Snowflake Cortex AI Function: Multirow error handling improvements.

Access control requirements

Users must use a role that has been granted the SNOWFLAKE.CORTEX_USER database role. See Cortex LLM privileges for more information on this privilege.

Limitations

Snowflake Cortex functions do not support dynamic tables.