- Categories:
String & binary functions (AI Functions)
Evaluate an AI function (AI_ FUNCTION_ EVALUATION)¶
AI_FUNCTION_EVALUATION measures the output quality of an AI function or Cortex AI call against a labeled dataset. You specify the expression to evaluate, a dataset containing expected outputs, and a scoring metric. Snowflake executes the expression for each row, compares the generated output with the expected output, and reports an aggregate quality score together with cost and token usage.
Use evaluation to compare prompts, models, or function implementations using the same dataset and metric. AI function optimization uses the same evaluation model to measure candidate implementations.
Evaluation is implemented as an AI_FUNCTION_EVALUATION experiment. This page describes the evaluation specification and workflow. For details about the EXPERIMENT object and related commands, see Experiments.
Syntax¶
Evaluation runs in two statements: create the experiment with an evaluation specification, then execute it.
The evaluation specification is a YAML document with this shape:
Arguments¶
The specification is validated at CREATE EXPERIMENT time. Unknown or misspelled keys are rejected.
Required¶
query_textThe AI call to evaluate, written as a SQL scalar expression that references the dataset’s columns by name. This can be a Cortex built-in, for example:
or a user-defined AI function invoked inline:
Evaluation does not use the nested
function:block (that block is optimization-only). The call is named directly asquery_text, and it references dataset columns directly — there is noargument_mapping.metricsExactly one scoring metric — either a single mapping or a one-element list.
namemust be one of:Metric Scores a row as correct when… exact_matchOutput equals the ground-truth label exactly. fuzzy_matchOutput approximately matches (normalized string similarity). contains_matchThe label is contained in the output (or vice versa). redaction_matchOutput matches the expected redaction (redaction/PII tasks). llm_judgeAn LLM grades the output against the label. Optional judge_modelpicks the grader.customA user UDF scores each row. Requires custom_udf: <udf_name>.A metric list with more than one entry is rejected — one metric per evaluation.
datasetThe labeled data. Must be a Snowflake dataset (
SNOWFLAKE.ML.DATASET); plain tables and views are not accepted.name— fully-qualified dataset name.version— dataset version (for examplev1). Required.ground_truth— the column holding the correct/label value each output is scored against.
Optional¶
evaluation.num_eval_runsNumber of times to repeat the evaluation (integer, 1–20; default 1). Repeat runs let you measure variance across identical evaluations (AI outputs are non-deterministic). Each repeat is reported as a separate run (
EVAL_1,EVAL_2, …).
Returns¶
CREATE EXPERIMENT and EXECUTE EXPERIMENT return status rows. EXECUTE EXPERIMENT runs asynchronously on serverless compute and returns immediately. Read results once the runs finish:
Each EVAL_<N> run reports:
- Metric:
score— the aggregate metric value (0–1). - Parameters:
model,function_name,rows_evaluated(rows scored), andcustom_metric_udfwhen a custom metric is used. The lifecycle status (FINISHED/FAILED/RUNNING) is inside the metadata JSON column ofSHOW RUNS, not a top-level column. See Experiments → Reading results.
Usage notes¶
- Evaluation is implemented as an AI_FUNCTION_EVALUATION experiment. This page describes the evaluation specification and workflow. For details about the EXPERIMENT object and related commands, see Experiments.
- Evaluation does not modify your function. It only measures. To improve a function, use AI_FUNCTION_OPTIMIZATION.
query_textreferences dataset columns by name. The columns referenced in the expression must exist in the dataset version; theground_truthcolumn supplies the labels.- Dataset size. A labeled dataset of about 50–200 rows is recommended. The maximum is 1,000 rows.
- One metric per evaluation. To compare metrics, run separate evaluations.
num_eval_runsfor stability. Because model outputs vary, a single run can over- or under-state quality. Usenum_eval_runs: 3–5to see the spread before trusting a number.llm_judgedefault model. Whenjudge_modelis omitted, the default judge isclaude-sonnet-4-5. The judge scores each output on a semantic-correctness rubric.- Custom metric UDF contract. A custom metric calls the UDF named by
custom_udfonce per row ascustom_udf(EXPECTED, PREDICTED)— two VARCHAR arguments (ground truth first, model output second). It must return a VARIANT/OBJECT with a numericscorein 0–1 (optionally afeedbackstring). Create it as a normal scalar UDF, not an AI function. - Cost. The experiment runs on serverless compute (metered as
SERVERLESS_EXPERIMENTS); the underlying AI calls are metered as Cortex inference tokens.
Access control requirements¶
| Privilege / role | Object | Notes |
|---|---|---|
| CREATE EXPERIMENT | Schema | To create the experiment. |
Database role SNOWFLAKE.CORTEX_USER (or SNOWFLAKE.AI_FUNCTIONS_USER) | — | Required to EXECUTE EXPERIMENT. |
| USAGE | Dataset’s database + schema | To read the labeled data. |
Examples¶
Evaluate a built-in call with exact match¶
Evaluate a user AI function with an LLM judge, repeated 3x¶
Score with a custom metric UDF¶
Create a scalar UDF that returns a score (and optional feedback), then reference it with the custom metric:
Read the results¶
Limitations¶
- Dataset size limit. The dataset can contain at most 1,000 rows (about 50–200 recommended).
- One metric per evaluation.
num_eval_runsrange is 1–20.- Model availability. Models named in
query_text(and anyjudge_model) must be authorized and served in your region. - Execution time limit. An experiment run is limited to 20 hours.
Legal¶
The data classification of inputs and outputs are as set forth in the following table.
| Input data classification | Output data classification | Designation |
|---|---|---|
| Usage Data | Customer Data | Generally available functions are Covered AI Features. Preview functions are Preview AI Features. [1] |
For additional information, refer to Snowflake AI and ML.