snowflake.snowpark.functions.prompt¶

snowflake.snowpark.functions.prompt(template_string: str, *exprs: Union[Column, str]) → Column[source]¶

Constructs a structured OBJECT containing a template string and a list of arguments. This object is useful for dynamically formatting messages, constructing structured prompts, or storing formatted data for further processing, such as by Cortex AI functions.

Parameters:
  • template_string – A string containing numbered placeholders like {0} where the number is at least 0 and less than the number of expressions specified. The first expression is substituted for {0}, the second for {1}, and so on.

  • *exprs – Expressions whose values will eventually be substituted into the template string in place of the numbered placeholders. These can be column names or other expressions. Values can be of any type coercible to a string (for example, VARCHAR, NUMBER, etc.), or FILE.

Returns:

{ 'template': '<template_string>', 'args': ARRAY(<value_1>, <value_2>, ...) }

The args array contains the value of the expressions specified in the PROMPT function call.

Return type:

A SQL OBJECT with the following structure

Note

  • This function does not perform any string formatting itself. It is intended to construct an object to be consumed by Cortex AI functions.

  • It is an error to use a placeholder in the template string that does not have a corresponding expression, but it is not an error to have expressions that are not used in the template string.

Examples:

>>> df = session.create_dataframe([["Alice", "Monday"], ["Bob", "Tuesday"]], schema=["name", "day"])
>>> df.select(prompt("Hello, {0}. Today is {1}", col("name"), col("day")).alias("greeting")).show()
--------------------------------------------
|"GREETING"                                |
--------------------------------------------
|{                                         |
|  "args": [                               |
|    "Alice",                              |
|    "Monday"                              |
|  ],                                      |
|  "template": "Hello, {0}. Today is {1}"  |
|}                                         |
|{                                         |
|  "args": [                               |
|    "Bob",                                |
|    "Tuesday"                             |
|  ],                                      |
|  "template": "Hello, {0}. Today is {1}"  |
|}                                         |
--------------------------------------------



This function or method is in private preview since 1.31.0.
Copy