# Generate Snowflake UDF Scoring Code

> Generate Snowflake UDF Scoring Code - Use the DataRobot Scoring Code JAR as a user-defined function
> (UDF) on Snowflake.

This Markdown file sits beside the HTML page at the same path (with a `.md` suffix). It summarizes the topic and lists links for tools and LLM context.

Companion generated at `2026-04-24T16:03:56.552939+00:00` (UTC).

## Primary page

- [Generate Snowflake UDF Scoring Code](https://docs.datarobot.com/en/docs/classic-ui/integrations/snowflake/snowflake-sc.html): Full documentation for this topic (HTML).

## Sections on this page

- [Access Scoring Code](https://docs.datarobot.com/en/docs/classic-ui/integrations/snowflake/snowflake-sc.html#access-scoring-code): In-page section heading.
- [Feature Considerations](https://docs.datarobot.com/en/docs/classic-ui/integrations/snowflake/snowflake-sc.html#feature-considerations): In-page section heading.

## Related documentation

- [Classic UI documentation](https://docs.datarobot.com/en/docs/classic-ui/index.html): Linked from this page.
- [Integrations](https://docs.datarobot.com/en/docs/classic-ui/integrations/index.html): Linked from this page.
- [Snowflake](https://docs.datarobot.com/en/docs/classic-ui/integrations/snowflake/index.html): Linked from this page.
- [Automated deployment and replacement of Scoring Code in Snowflake](https://docs.datarobot.com/en/docs/workbench/nxt-console/nxt-prediction-environments/nxt-prediction-environment-integrations/nxt-snowflake-pred-env-integration.html): Linked from this page.
- [create a model package](https://docs.datarobot.com/en/docs/classic-ui/mlops/deployment/registry/reg-create.html): Linked from this page.
- [configure the deployment](https://docs.datarobot.com/en/docs/classic-ui/mlops/deployment/deploy-methods/deploy-external-model.html#deploy-an-external-model-package): Linked from this page.
- [upload actuals via the Settings tab](https://docs.datarobot.com/en/docs/classic-ui/mlops/deployment-settings/accuracy-settings.html): Linked from this page.

## Documentation content

# Generate Snowflake UDF Scoring Code

> [!NOTE] Managed DataRobot installations
> The information on this page is intended for Self-Managed DataRobot installations. For DataRobot-managed Snowflake prediction environments, see [Automated deployment and replacement of Scoring Code in Snowflake](https://docs.datarobot.com/en/docs/workbench/nxt-console/nxt-prediction-environments/nxt-prediction-environment-integrations/nxt-snowflake-pred-env-integration.html).

Scoring Code makes it easy for you to perform predictions on DataRobot models anywhere you want by exporting a model to a Java JAR file. Snowflake user-defined functions (UDFs) allow you to execute arbitrary Java code on Snowflake. DataRobot provides an API to Scoring Code for you to use Scoring Code as a UDF on Snowflake without writing any additional code.

To download and execute scoring code with Snowflake UDFs, you must meet the following prerequisites:

- Prepare a DataRobot model that supports Scoring Code for deployment andcreate a model packagewith it.
- Register your Snowflake prediction environment to use with the model.

## Access Scoring Code

When you have your model package and prediction environment prepared in DataRobot, you can deploy the model in order to access the Scoring Code for use with Snowflake.

1. Navigate to theModel Registryand select your model package. On theDeploymentstab, selectCreate new deployment.
2. Complete the fields andconfigure the deploymentas desired. To generate Snowflake UDF Scoring Code, specify your Snowflake prediction environment under theInferenceheader.
3. Once fully configured, selectCreate deploymentat the top of the screen.
4. After deploying the model, access the deployment from the inventory and navigate to thePredictions > Portable Predictionstab. This is where DataRobot hosts the Scoring Code for the model.
5. (Optional) Toggle onInclude prediction explanationsto include prediction explanations with the prediction results, then clickDownload. The Scoring Code JAR file appears in your browser bar.
6. When the Scoring Code download completes, copy the installation script and update it with your Snowflake warehouse, database, schema, and the path to the Scoring Code JAR file, then execute the script. Copy and paste (for regression)-- Replace with the warehouse to use
USE WAREHOUSE my_warehouse;
-- Replace with the database to use
USE DATABASE my_database;

-- Replace with the schema to use
CREATE SCHEMA IF NOT EXISTS scoring_code_udf_schema;
USE SCHEMA scoring_code_udf_schema;

-- Update this path to match the Scoring Code JAR location
PUT 'file:///path/to/downloaded_scoring_code.jar' '@~/jars/' AUTO_COMPRESS=FALSE;

-- Create the UDF
CREATE OR REPLACE FUNCTION datarobot_udf(RowValue OBJECT)
    RETURNS FLOAT
    LANGUAGE JAVA
    IMPORTS=('@~/jars/downloaded_scoring_code.jar')
    HANDLER='com.datarobot.prediction.simple.RegressionPredictor.score'; Copy and paste (for classification)-- Replace with the warehouse to use
USE WAREHOUSE my_warehouse;
-- Replace with the database to use
USE DATABASE my_database;

-- Replace with the schema to use
CREATE SCHEMA IF NOT EXISTS scoring_code_udf_schema;
USE SCHEMA scoring_code_udf_schema;

-- Update this path to match the Scoring Code JAR location
PUT 'file:///path/to/downloaded_scoring_code.jar' '@~/jars/' AUTO_COMPRESS=FALSE;

-- Create the UDF
CREATE OR REPLACE FUNCTION datarobot_udf(RowValue OBJECT)
    RETURNS OBJECT
    LANGUAGE JAVA
    IMPORTS=('@~/jars/downloaded_scoring_code.jar')
    HANDLER='com.datarobot.prediction.simple.ClassificationPredictor.score'; The script uploads the JAR file to a Snowflake stage and creates a UDF for making predictions with Scoring Code. NoteTo run these scripts, youmustuse the SnowSQL command provided in the next step (7). You can't execute these scripts in Snowflake's UI.
7. Execute the script in SnowSQL by providing your credentials and the script location: Copy and pastesnowsql --accountname $ACCOUNT_NAME --username $USERNAME --filename $SCRIPT_PATH
8. With your UDF successfully created, you can now use Snowflake to score data. Use the UDF in any manner supported by SQL. Copy and paste/*
Scoring your data

The Scoring Code UDF accepts rows of data as objects. The OBJECT_CONSTRUCT_KEEP_NULL method can be used to turn a table row into an object.
*/

-- Scoring without specifying columns. Data can contain nulls
SELECT my_datarobot_model(OBJECT_CONSTRUCT_KEEP_NULL(*)) FROM source_table;
9. After scoring data, you canupload actuals via the Settings tabin order to enable accuracy monitoring and more.

## Feature Considerations

Consider the following when using Scoring Code as a UDF on Snowflake.

- Keras models cannot be executed in Snowflake.
- Time series Scoring Code is not supported for Snowflake.
- Scoring Code JARs created prior to the release of the Snowflake Scoring Code feature cannot be run in Snowflake.
- To retrieve Prediction Explanations for Snowflake UDF Scoring Code, first toggle onInclude Prediction Explanationsin the deployment'sPortable Predictionstab. This tab includes code snipppets you can use to retrieve Prediction Explanations. You can use thescoreWithExplanations()method and customize the number of explanations that are returned. For example, configure the function like so:scoreWithExplanations(Map<String, Object> row, Integer maxCodes, Double thresholdLow, Double thresholdHigh)
