CREATE MODEL MONITOR
statementpartialAI & MLCreate or replace a model monitor in the current or specified schema. Snowflake currently supports two types of model monitors. See ML Observability for model version monitors and Gateway Monitoring & A/B Testing for gateway model monitors.
Syntax
supportedpartialnot supportednot scored
CREATE [ OR REPLACE ] MODEL MONITOR [ IF NOT EXISTS ] <monitor_name> WITH
MODEL = <model_name>
VERSION = '<version_name>'
FUNCTION = '<function_name>'
WAREHOUSE = <warehouse_name>
REFRESH_INTERVAL = '<num> { seconds | minutes | hours | days }'
AGGREGATION_WINDOW = '<num> days'
[ SOURCE = <source_name> ]
[ TIMESTAMP_COLUMN = <timestamp_name> ]
[ BASELINE = <baseline_name> ]
[ GROUND_TRUTH = <ground_truth_table> ]
[ ID_COLUMNS = <id_column_name_array> ]
[ PREDICTION_CLASS_COLUMNS = <prediction_class_column_name_array> ]
[ PREDICTION_SCORE_COLUMNS = <prediction_column-name_array> ]
[ ACTUAL_CLASS_COLUMNS = <actual_class_column_name_array> ]
[ ACTUAL_SCORE_COLUMNS = <actual_column_name_array> ]
[ SEGMENT_COLUMNS = <segment_column_name_array> ]
[ CUSTOM_METRIC_COLUMNS = <custom_metric_column_name_array> ]
[ COMMENT = '<string_literal>' ]
CREATE [ OR REPLACE ] MODEL MONITOR [ IF NOT EXISTS ] <monitor_name> WITH
MODEL = <model_name>
GATEWAY = <gateway_name>
FUNCTION = '<function_name>'
WAREHOUSE = <warehouse_name>
REFRESH_INTERVAL = '<num> { seconds | minutes | hours | days }'
AGGREGATION_WINDOW = '<num> { hours | days }'
[ GROUND_TRUTH = <ground_truth_table> ]
[ ID_COLUMNS = <id_column_name_array> ]
[ PREDICTION_CLASS_COLUMNS = <prediction_class_column_name_array> ]
[ PREDICTION_SCORE_COLUMNS = <prediction_score_column_name_array> ]
[ ACTUAL_CLASS_COLUMNS = <actual_class_column_name_array> ]
[ ACTUAL_SCORE_COLUMNS = <actual_score_column_name_array> ]
[ COMMENT = '<string_literal>' ]
Parameters
| Name | Required | Description |
|---|---|---|
monitor_name | required | Specifies the identifier for the model monitor; must be unique in the schema where the monitor is created. If the monitor identifier is not fully qualified (in the form of db_name.schema_name.name or schema_name.name), the command creates the model in the current schema for the session. In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case-sensitive. For more information, see Identifier requirements. |
MODEL = model_name | required | The name of the model to be monitored. |
FUNCTION = 'function_name' | required | The name of the model function to monitor. For model version monitors, must be a function in the specified model version. For gateway model monitors, must match a function exposed by each active inference service behind the gateway that backs the specified model. |
WAREHOUSE = warehouse_name | required | The name of the Snowflake warehouse to use for the monitor’s internal compute operations. |
REFRESH_INTERVAL = 'num { seconds | minutes | hours | days }' | required | The interval at which the monitor refreshes its internal state. The value must be a string representing a time period, such as '1 day'. The minimum refresh interval is '60 seconds'. Supported units include seconds, minutes, hours, and days. You may use singular (“hour”) or plural (“hours”) for the interval name. |
AGGREGATION_WINDOW = 'num { hours | days }' | required | The window over which the monitor aggregates data. The value must be a string representing a time period, such as '1 day'. For model version monitors, only days are supported. For gateway model monitors, both hours and days are supported. You may use singular (“day”) or plural (“days”) for the interval name. |
VERSION = 'version_name' | required | Name of the model version to be monitored. |
GATEWAY = gateway_name | required | Name of the Snowflake Gateway whose routed inference services you want to monitor. |
GROUND_TRUTH = ground_truth_table | optional | Name of the ground truth table that contains labels for performance metrics. The table must include every column in ID_COLUMNS (type STRING) and exactly one additional column for the actual label or score, unless you specify ACTUAL_CLASS_COLUMNS or ACTUAL_SCORE_COLUMNS explicitly. Not supported for model version monitors that use a user-provided SOURCE. |
ID_COLUMNS = id_column_name_array | optional | An array of string column names that, together, uniquely identify each row in the source data. See ARRAY constants. For gateway model monitors and model version monitors that use the auto-captured inference table, specify ID_COLUMNS and GROUND_TRUTH together to enable performance metrics monitoring, or omit both. The column names must match the field names listed in extra_columns in inference requests to join the ground truth table with the auto-captured inference logs. |
PREDICTION_CLASS_COLUMNS = prediction_class_column_name_array | optional | An array of strings naming all prediction class columns in the SOURCE table if you provide one, or the output feature names in the auto-captured inference logs when they’re the source. See ARRAY constants. If the model task is TABULAR_BINARY_CLASSIFICATION or TABULAR_REGRESSION, the columns must be of type NUMBER. If the model task is TABULAR_MULTI_CLASSIFICATION, the columns must be of type STRING. |
PREDICTION_SCORE_COLUMNS = prediction_column_name_array | optional | An array of strings naming all prediction score columns in the SOURCE table if you provide one, or the output feature names in the auto-captured inference logs when they’re the source. See ARRAY constants. Columns must be of type NUMBER. |
ACTUAL_CLASS_COLUMNS = actual_class_column_name_array | optional | An array of strings naming all actual class columns in the SOURCE table if you provide one, or in the GROUND_TRUTH table when the auto-captured inference logs are the source. See ARRAY constants. If the model task is TABULAR_BINARY_CLASSIFICATION or TABULAR_REGRESSION, the columns must be of type NUMBER. If the model task is TABULAR_MULTI_CLASSIFICATION, the columns must be of type STRING. |
ACTUAL_SCORE_COLUMNS = actual_column_name_array | optional | An array of strings naming all actual score columns in the SOURCE table if you provide one, or in the GROUND_TRUTH table when the auto-captured inference logs are the source. See ARRAY constants. Columns must be of type NUMBER. |
COMMENT = 'string_literal' | optional | Specifies a comment for the model monitor. |
SOURCE = source_name | optional | Name of the source table or view that contains the features, inference results, and actual labels. If you omit SOURCE, the monitor reads the model’s auto-captured inference table for the features and inference results, and the optional ground truth table for the actual labels. |
TIMESTAMP_COLUMN = timestamp_name | optional | Name of the column in the source data that contains the timestamps. Must be of type TIMESTAMP_NTZ. Required if you specify SOURCE. Don’t specify it when the source is the auto-captured inference table. |
BASELINE = baseline_name | optional | Name of the baseline table that contains a snapshot of data similar to SOURCE, which is used to compute drift. A snapshot of this data is embedded within the monitor object. Although this parameter is optional, if it is not set, the monitor cannot detect drift. For a monitor that uses the auto-captured inference table, the baseline table schema must include the prediction columns, the actual columns if you specify GROUND_TRUTH, and the feature columns from the model function signature. |
SEGMENT_COLUMNS = segment_column_name_array | optional | An array of strings naming all segment columns in the data source. See ARRAY constants. Segment columns must be of type STRING in the source data, or STRING input features if the source is the auto-captured inference table. You can specify up to 5 segment columns per monitor. Each segment column should have fewer than 25 unique values for optimal performance. For more information about segments, see ML Observability: Monitoring model behavior over time. |
CUSTOM_METRIC_COLUMNS = custom_metric_column_name_array | optional | An array of strings naming columns in the source data that are used for custom metrics. These columns are not treated as features. See ARRAY constants. Columns must be of type NUMBER. Not supported when the source is the auto-captured inference table. |
Usage notes
- You cannot specify both VERSION and GATEWAY in the same statement; specify one to indicate the monitor type.
- Model task must be tabular_binary_classification, tabular_regression, or tabular_multi_classification.
- Multiple-output models are not currently supported. Although the prediction and actual columns are arrays, the arrays must have at most one element.
- A column may be specified once across all parameters (for example, an ID column cannot also be a prediction column).
- The number of monitored features is limited to 500.
- The basic configuration of MODEL MONITOR instances, including the model it monitors and source table or ground truth table it uses, cannot be changed after the monitor is created. You can modify only a few options using ALTER MODEL MONITOR. To change a monitor’s configuration, drop the instance and create a new one.
- Replication is supported only for instances of the CUSTOM_CLASSIFIER class.
- The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement.
- CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.
- With a user-provided SOURCE: At least one of the prediction columns must be specified.
- Actual columns are optional, but accuracy metrics are not computed if they are not specified.
- With the auto-captured inference table as the source: Don’t specify TIMESTAMP_COLUMN or CUSTOM_METRIC_COLUMNS.
- The model must have an inference table. See Autocapture inference logs for realtime inference.
- Prediction columns may be omitted on single-output models, but at least one prediction column must be specified for multi-output models.
- Ground truth and ID columns are optional, but accuracy metrics are not computed if they are not specified.
- Actual columns may be omitted when the ground truth table has a single non-ID column, but must be specified when there are multiple non-ID columns.
- Snowflake monitors auto-captured inference logs from up to 14 days before the monitor is created.
- Segment column requirements: Segment columns must be of type STRING.
- A maximum of 5 segment columns per monitor (hard limit).
- Each segment column should have fewer than 25 unique values (recommended limit).
- Segment values are case sensitive and special characters are not supported for segment queries.
- Feature drift requires the feature columns to be numeric, string, or Boolean. The monitor skips other types, such as VARIANT, ARRAY, and OBJECT, without an error. To see which columns it uses, check DESCRIBE MODEL MONITOR.
- Prediction columns may be omitted on single-output models, but at least one prediction column must be specified for multi-output models.
- Ground truth and ID columns are optional, but accuracy metrics are not computed if they are not specified.
- Actual columns may be omitted when the ground truth table has a single non-ID column, but must be specified when there are multiple non-ID columns.
- You can create multiple monitors for the same model, gateway, and function combination. Each monitor name must still be unique in the schema.
- At least one active service that backs the model must be included in the gateway.
- A representative service will be selected by the order of the endpoint list in the gateway to infer the model task and columns.
- Every service behind the gateway must have the same output feature name for the monitored function, or metrics may be incomplete or incorrect. Input feature names may differ.
Access control requirements
A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes OWNERSHIP | Model monitor | OWNERSHIP is a special privilege on an object that is automatically granted to the role that created the object, but can also be transferred using the GRANT OWNERSHIP command to a different role by the owning role (or any role with the MANAGE GRANTS privilege). CREATE MODEL MONITOR | Schema | SELECT | Table or view specified by the SOURCE parameter | User-provided source only. USAGE | Model specified by the MODEL parameter | User-provided source only. OWNERSHIP | Model specified by the MODEL parameter | Auto-captured inference table source only. SELECT | Table specified by the GROUND_TRUTH parameter | Auto-captured inference table source only. SELECT | Table specified by the BASELINE parameter | USAGE | Warehouse specified by the WAREHOUSE parameter | Privilege | Object | Notes OWNERSHIP | Model monitor | OWNERSHIP is a special privilege on an object that is automatically granted to the role that created the object, but can also be transferred using the GRANT OWNERSHIP command to a different role by the owning role (or any role with the MANAGE GRANTS privilege). CREATE MODEL MONITOR | Schema | SELECT | Table specified by the GROUND_TRUTH parameter | USAGE | Warehouse specified by the WAREHOUSE parameter | OWNERSHIP | Model specified by the MODEL parameter | USAGE | Gateway specified by the GATEWAY parameter | Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.
Known gaps
- WITH MODEL, VERSION, FUNCTION, WAREHOUSE, REFRESH_INTERVAL, AGGREGATION_WINDOW, SOURCE, TIMESTAMP_COLUMN, GROUND_TRUTH, ID_COLUMNS, PREDICTION_CLASS_COLUMNS, PREDICTION_SCORE_COLUMNS, ACTUAL_CLASS_COLUMNS, ACTUAL_SCORE_COLUMNS, GATEWAY are not exercised by any test