# Custom Metrics tab
URL: https://docs.datarobot.com/en/docs/classic-ui/mlops/monitor/custom-metrics.html

> Create and monitor custom business or performance metrics in a deployment.

# Custom Metrics tab

On a deployment's Custom Metrics tab, you can use the data you collect from the [Data Explorationtab](https://docs.datarobot.com/en/docs/api/reference/sdk/data-exploration.html) (or data calculated through other custom metrics) to compute and monitor custom business or performance metrics. These metrics are recorded on the configurable Custom Metric Summary dashboard, where you monitor, visualize, and export each metric's change over time. This feature allows you to implement your organization's specialized metrics, expanding on the insights provided by built-in [Service Health](https://docs.datarobot.com/en/docs/classic-ui/mlops/monitor/service-health.html), [Data Drift](https://docs.datarobot.com/en/docs/classic-ui/mlops/monitor/data-drift.html), and [Accuracy](https://docs.datarobot.com/en/docs/classic-ui/mlops/monitor/deploy-accuracy.html) metrics.

> [!NOTE] Custom metrics limits
> You can have up to 50 custom metrics per deployment, and of those 50, 5 can be hosted custom metrics.

To access custom metrics, in the top navigation bar, click Deployments and, on the Deployments tab, click on the deployment for which you want to create custom metrics. Then, in the deployment, click the Custom Metrics tab. The Summary tab opens:

## Add external custom metrics

The Custom Metrics tab can track up to 50 metrics. To add custom metrics:

1. On theCustom Metrics > Summarytab, click+ Add Custom Metric.
2. In theAdd Custom Metricdialog box, clickCreate new external metric, then clickNext:
3. Configure the metric settings in theAdd custom metric dialog box: FieldDescriptionNameA descriptive name for the metric. This name appears on theCustom Metric Summarydashboard.Description(Optional) A description of the custom metric; for example, you could describe the purpose, calculation method, and more.Name of y-axisA descriptive name for the dependent variable. This name appears on the custom metric's chart on theCustom Metric Summarydashboard.Default intervalThe default interval used by the selectedAggregation type. OnlyHOURis supported.Baseline(Optional) The value used as a basis for comparison when calculating thex% betterorx% worsevalues.Aggregation typeIf the metric is calculated as aSum,Average, orGauge—a metric with a distinct value measured at single point in time.Metric directionThe directionality of the metric and changes how changes the metric are visualized. You can selectHigher is betterorLower is better. For example, if you chooseLower is bettera 10% decrease in the calculated value of your custom metric will be considered10% better, displayed in green.Is Model SpecificWhen enabled, links the metric to the model with theModel Package ID(Registered Model Version ID) provided in the dataset. This setting influences when values are aggregated (or uploaded). For example:Model-specific (enabled): Model accuracy metrics are model specific, so the values are aggregated completely separately. When you replace a model, the chart for your custom accuracy metric only shows data for the days after the replacement.Not model-specific (disabled): Revenue metrics aren't model specific, so the values are aggregated together. When you replace a model, the chart for your custom revenue metric doesn't change.This field can't be edited after you create the metric.Column names definitionTimestamp columnThe column in the dataset containing a timestamp.Value columnThe column in the dataset containing the values used for custom metric calculation.Date format(Optional) The date format used by the timestamp column. NoteYou can override theColumn names definitionsettings when youupload data to a custom metric.
4. ClickAdd custom metric.

### Upload data to custom metrics

After you create a custom metric, you can provide data to calculate the metric:

1. On theCustom Metricstab, locate the custom metric for which you want to upload data, and then click theUpload Dataicon.
2. In theUpload Datadialog box, select an upload method, and then clickNext: Upload methodDescriptionUpload data as fileIn theChoose filedialog box, drag and drop file(s) to upload, or clickChoose file > Local fileto browse your local filesystem, and then clickSubmit data. You can upload up to 10GB uploaded in one file.Use AI CatalogIn theSelect a dataset from the AI Catalogdialog box, click a dataset from the list, and then clickSelect a dataset. The AI Catalog includes datasets from theData ExplorationAfter youcreate and configure a deployment, you can use the settings tabs for individual features to add or update deployment functionality: .Use APIIn theUse API Clientdialog box, clickCopy to clipboard, and then modify and use the API snippet to upload a dataset. You can upload up to 10,000 values in one API call.
3. In theSelect dataset columnsdialog box, configure the following: FieldDescriptionTimestamp columnThe column in the dataset containing a timestamp.Value columnThe column in the dataset containing the values used for custom metric calculation.Association IDThe row containing the association ID required by the custom metric to link predicted values to actuals.Date formatThe date format used by the timestamp column.
4. ClickUpload data.

### Report custom metrics via chat requests

For DataRobot-deployed text generation and agentic workflow custom models that implement the `chat()` hook, custom metric values can be reported directly in chat completion requests using the `extra_body` field. This allows reporting custom metrics at the same time as making chat requests, without needing to upload data separately.

> [!TIP] Manual chat request construction
> The OpenAI client converts the `extra_body` parameter contents to top-level fields in the JSON payload of the chat `POST` request. When manually constructing a chat payload, without the OpenAI client, include `“datarobot_metrics": {...}` in the top level of the payload.

To report custom metrics via chat requests:

1. Ensure the deployment has an association ID column defined and moderation configured. These are required for custom metrics to be processed.
2. Define custom metrics on theCustom Metricstab as described inAdd external custom metrics.
3. When making a chat completion request using the OpenAI client, includedatarobot_metricsin theextra_bodyfield with the metric names and values to report:

```
from openai import OpenAI

openai_client = OpenAI(
    base_url="https://<your-datarobot-instance>/api/v2/deployments/{deployment_id}/",
    api_key="<your_api_key>",
)

extra_body = {
    # These values pass through to the LLM
    "llm_id": "azure-gpt-6",
    # If set here, replaces the auto-generated association ID
    "datarobot_association_id": "my_association_id_0001",
    # DataRobot captures these for custom metrics
    "datarobot_metrics": {
        "field1": 24,
        "field2": 25
    }
}

completion = openai_client.chat.completions.create(
    model="datarobot-deployed-llm",
    messages=[
        {"role": "system", "content": "Explain your thoughts using at least 100 words."},
        {"role": "user", "content": "What would it take to colonize Mars?"},
    ],
    max_tokens=512,
    extra_body=extra_body
)

print(completion.choices[0].message.content)
```

> [!NOTE] Custom metric requirements
> A matching custom metric for each name in
> datarobot_metrics
> must already be defined for the deployment.
> Custom metric values reported this way must be numeric.
> The deployed custom model must have an association ID column defined and moderation configured for the metrics to be processed.

For more information about using `extra_body` with chat requests, including how to specify association IDs, see the [chat()hook documentation](https://docs.datarobot.com/en/docs/api/code-first-tools/drum/structured-custom-models.html#association-id).

## Add hosted custom metrics

DataRobot offers [custom metrics](https://docs.datarobot.com/en/docs/api/reference/sdk/custom-metrics.html) for deployments to compute and monitor custom business or performance metrics. With hosted custom metrics, not only can you implement up to five of your organization's specialized metrics in a deployment, but also upload and host code using DataRobot Notebooks to easily add custom metrics to other deployments.

> [!NOTE] Custom metrics limits
> You can have up to 50 custom metrics per deployment, and of those 50, 5 can be hosted custom metrics.

> [!WARNING] Time series support
> The [DataRobot Model Metrics (DMM)](https://docs.datarobot.com/en/docs/api/code-first-tools/dr-model-metrics/index.html) library does not support time series models, specifically [data export](https://docs.datarobot.com/en/docs/api/code-first-tools/dr-model-metrics/dmm-data-sources.html#export-prediction-data) for time series models. To export and retrieve data, use the [DataRobot API client](https://datarobot-public-api-client.readthedocs-hosted.com/en/latest-release/reference/mlops/data_exports.html).

To begin hosting custom metrics:

1. On theCustom Metricstab, click+ Add Custom Metric.
2. In theAdd Custom Metricdialog box, clickCreate new hosted metric, clickNext:
3. Configure the metric settings in theAdd custom metric dialog box: FieldDescriptionName(Required) A descriptive name for the metric. This name appears on theCustom Metric Summarydashboard.DescriptionA description of the custom metric; for example, you could describe the purpose, calculation method, and more.Name of y-axis(Required) A descriptive name for the dependent variable. This name appears on the custom metric's chart on theCustom Metric Summarydashboard.Default intervalDetermines the default interval used by the selectedAggregation type. OnlyHOURis supported.BaselineDetermines the value used as a basis for comparison when calculating thex% betterorx% worsevalues.Aggregation typeDetermines if the metric is calculated as aSum,Average, orGauge—a metric with a distinct value measured at single point in time.Metric directionDetermines the directionality of the metric, which controls how changes to the metric are visualized. You can selectHigher is betterorLower is better. For example, if you chooseLower is better, a 10% decrease in the calculated value of your custom metric will be considered10% better, displayed in green.Is model-specificWhen enabled, this setting links the metric to the model with theModel Package ID(Registered Model Version ID) provided in the dataset. This setting influences when values are aggregated (or uploaded). For example:Model-specific (enabled): Model accuracy metrics are model specific, so the values are aggregated separately. When you replace a model, the chart for your custom accuracy metric only shows data for the days after the replacement.Not model-specific (disabled): Revenue metrics aren't model specific, so the values are aggregated together. When you replace a model, the chart for your custom revenue metric doesn't change.This field can't be edited after you create the metric.ScheduleDefines when the custom metrics are populated. Select a frequency (hourly, daily, monthly, etc.) and a time. SelectAdvanced schedulefor more precise scheduling options.
4. ClickAdd custom metric from notebook.

### Test custom metrics with custom jobs

> [!NOTE] Availability information
> Notebooks for hosted custom metrics are off by default. Contact your DataRobot representative or administrator for information on enabling this feature.
> 
> Feature flag: Enable Notebooks Custom Environments

After configuring a custom metric, DataRobot loads the notebook that contains the code for it. The notebook contains one custom metric cell, a unique type of notebook cell that contains Python code defining how the metric is exported and calculated, code for scoring, and code to populate the metric.

Modify the code in the custom metric cell as needed. Then, test the code by clicking Test custom metric code at the bottom of the cell. The test creates a custom job.

- If the test runs successfully, click Deploy custom metric code to add the custom metric to your deployment.
- If the code does not run properly, you will receive the Testing custom metric code failed warning after testing completes:

### Troubleshoot custom metric code

To troubleshoot a custom metric's code, navigate to the Model Registry, select the Custom Jobs tab, and access the custom job that ran for testing. The job's Runs tab contains a log of the failed test, which you can browse by selecting View full logs.

To troubleshoot failed tests, DataRobot recommends browsing the logs for each failed test. Additionally, the custom jobs interface allows you to modify the schedule for the custom metric from the Workshop tab by selecting Schedule run.

## Manage custom metrics

On the Custom Metrics dashboard, after you've added your custom metrics, you can edit, arrange, or delete them.

### Edit or delete metrics

To edit or delete a metric, on the Custom Metrics tab, locate the custom metric you want to manage, and then click the Actions menu:

- To edit a metric, clickEdit, update any configurable settings, and clickUpdate custom metric.
- To delete a metric, clickDelete.

### Arrange or hide metrics

To arrange or hide metrics on the Custom Metric Summary dashboard, locate the custom metric you want to move or hide:

- To move a metric, click the grid icon () on the left side of the metric tile and then drag the metric to a new location.
- To hide a metric's chart, clear the checkbox next to the metric name.

## Configure the custom metric dashboard display settings

Configure the following settings to specify the custom metric calculations you want to view on the dashboard:

> [!TIP] Custom metrics for evaluation and moderation require an association ID
> For the metrics added when you configure evaluations and moderations, to view data on the Custom metrics tab, ensure that you set an association ID and enable prediction storage before you start making predictions through the deployed LLM.If you don't set an association ID and provide association IDs alongside the LLM's predictions, the metrics for the moderations won't be calculated on the [Custom metrics](https://docs.datarobot.com/en/docs/workbench/nxt-console/nxt-monitoring/nxt-custom-metrics.html) tab.After you define the association ID, you can enable automatic association ID generation to ensure these metrics appear on the Custom metrics tab. You can enable this setting [during](https://docs.datarobot.com/en/docs/workbench/nxt-registry/nxt-model-directory/nxt-deploy-models.html#custom-metrics) or [after](https://docs.datarobot.com/en/docs/workbench/nxt-console/nxt-settings/nxt-custom-metrics-settings.html) deployment.

|  | Setting | Description |
| --- | --- | --- |
| (1) | Model | Select the deployment's model, current or previous, to show custom metrics for. |
| (2) | Range (UTC) | Select the start and end dates of the period from which you want to view custom metrics. |
| (3) | Resolution | Select the granularity of the date slider. Select from hourly, daily, weekly, and monthly granularity based on the time range selected. If the time range is longer than 7 days, hourly granularity is not available. |
| (4) | Refresh | Refresh the custom metric dashboard. |
| (5) | Reset | Reset the custom metric dashboard's display settings to the default. |

---
