---
updatedAt: 2026-10-25T15:46:36.000Z
agentTools:
  projectIndex: https://docs.superwise.ai/llms.txt
---

# Create Policy

Creates a new Policy

- **payload** (PolicySchema): Required. The policy data to be created:
    - **name** (str): A descriptive name for this policy.
    - **data_config**: Configuration relevant to the retrieval of data for this policy:
        for compare distribution policy:
        - **query_a** (Query): Cube.js query.
        - **query_b** (Query): Cube.js query.
        - **query_a_time_range_config**: (TimeRangeConfig or None): Time range configuration for query A.
        - **query_b_time_range_config**: (TimeRangeConfig or None): Time range configuration for query B.
        - **distance_function** (DistanceFunction): Distance function to use.
        for statistics policy:
        - **query** (Query): Cube.js query.
        - **time_range_config**: (TimeRangeConfig): Time range configuration for the query.
    - **cron_expression** (str): Cron expression for policy evaluation.
    - **condition_above_value** (float or None): Condition above value.
    - **condition_below_value** (float or None): Condition below value.
    - **destination_ids** (list of UUID): List of communication channels to get notified through.
    - **alert_on_status** (AlertOnStatusDirection): Trigger policy action if the value is above/below.
    - **alert_on_policy_level** (bool): Trigger policy action on a single group/entire groups.
    - **dataset_id** (str): The dataset this policy is monitoring.

Creates a policy that monitors a dataset. A policy defines a metric, as a statistics query or a comparison of two distributions; a condition, as a static threshold or a moving average; how often it is evaluated; and where alerts are sent.

## When to use it

Use it to detect issues automatically, such as a metric crossing a threshold or drifting from its history. To start from a predefined policy for an agent, use [Create a policy from a template](https://docs.superwise.ai/reference/create_policy_template).

## Required parameters

* `alert_on_policy_level` (body): whether the policy action triggers on a single group or on the entire set of groups.
* `name` (body): a descriptive name for the policy.
* `dataset_id` (body): the ID of the dataset the policy monitors.
* `destination_ids` (body): the IDs of the destinations to notify.
* `cron_expression` (body): a cron expression that sets when the policy is evaluated.
* `threshold_settings` (body): the condition: a static threshold with `condition_above_value` or `condition_below_value`, or a moving average with `window_size` and `violation_deviation`.
* `alert_on_status` (body): when to alert: `HEALTHY_TO_UNHEALTHY`, `UNHEALTHY_TO_HEALTHY`, or `BOTH`.
* `data_config` (body): the metric: a statistics query with a time range, or a comparison of two distribution queries with a distance function.

Optional body fields: `dataset_b_id`, `description`, `initialize_with_historic_data`.

## Response

A successful call returns `201 Created` with the `PolicyResponse` object, including `id`, `name`, `status`, `data_config`, `threshold_settings`, `cron_expression`, `destination_ids`, `last_evaluation`, and `next_evaluation`.

**Related:** [Create a policy from a template](https://docs.superwise.ai/reference/create_policy_template), [List policies](https://docs.superwise.ai/reference/get_policies), [Trigger a policy](https://docs.superwise.ai/reference/trigger_policy), [Create a destination](https://docs.superwise.ai/reference/create_destination)

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "paths": {
    "/v1/policies": {
      "post": {
        "tags": [
          "Policies"
        ],
        "summary": "Create Policy",
        "description": "Creates a new Policy\n\n- **payload** (PolicySchema): Required. The policy data to be created:\n    - **name** (str): A descriptive name for this policy.\n    - **data_config**: Configuration relevant to the retrieval of data for this policy:\n        for compare distribution policy:\n        - **query_a** (Query): Cube.js query.\n        - **query_b** (Query): Cube.js query.\n        - **query_a_time_range_config**: (TimeRangeConfig or None): Time range configuration for query A.\n        - **query_b_time_range_config**: (TimeRangeConfig or None): Time range configuration for query B.\n        - **distance_function** (DistanceFunction): Distance function to use.\n        for statistics policy:\n        - **query** (Query): Cube.js query.\n        - **time_range_config**: (TimeRangeConfig): Time range configuration for the query.\n    - **cron_expression** (str): Cron expression for policy evaluation.\n    - **condition_above_value** (float or None): Condition above value.\n    - **condition_below_value** (float or None): Condition below value.\n    - **destination_ids** (list of UUID): List of communication channels to get notified through.\n    - **alert_on_status** (AlertOnStatusDirection): Trigger policy action if the value is above/below.\n    - **alert_on_policy_level** (bool): Trigger policy action on a single group/entire groups.\n    - **dataset_id** (str): The dataset this policy is monitoring.",
        "operationId": "create_policy",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PolicyCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PolicyResponse"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity"
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    }
  },
  "info": {
    "title": "Superwise Main Entities",
    "description": "API reference",
    "version": "0.1.0"
  },
  "components": {
    "schemas": {
      "AlertOnStatusDirection": {
        "type": "string",
        "enum": [
          "HEALTHY_TO_UNHEALTHY",
          "UNHEALTHY_TO_HEALTHY",
          "BOTH"
        ],
        "title": "AlertOnStatusDirection"
      },
      "DataConfigDistributionCompare-Input": {
        "properties": {
          "type": {
            "type": "string",
            "const": "distribution_compare",
            "title": "Type",
            "default": "distribution_compare"
          },
          "query_a": {
            "$ref": "#/components/schemas/DashboardItemDistributionCompareQuery-Input"
          },
          "query_b": {
            "$ref": "#/components/schemas/DashboardItemDistributionCompareQuery-Input"
          },
          "distance_function": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DistanceFunction"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "type": "object",
        "required": [
          "query_a",
          "query_b"
        ],
        "title": "DataConfigDistributionCompare"
      },
      "DataConfigDistributionCompare-Output": {
        "properties": {
          "type": {
            "type": "string",
            "const": "distribution_compare",
            "title": "Type",
            "default": "distribution_compare"
          },
          "query_a": {
            "$ref": "#/components/schemas/DashboardItemDistributionCompareQuery-Output"
          },
          "query_b": {
            "$ref": "#/components/schemas/DashboardItemDistributionCompareQuery-Output"
          },
          "distance_function": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DistanceFunction"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "type": "object",
        "required": [
          "query_a",
          "query_b"
        ],
        "title": "DataConfigDistributionCompare"
      },
      "DataConfigStatistics-Input": {
        "properties": {
          "type": {
            "type": "string",
            "const": "statistics",
            "title": "Type",
            "default": "statistics"
          },
          "query": {
            "$ref": "#/components/schemas/PolicyQuery"
          },
          "time_range_config": {
            "$ref": "#/components/schemas/TimeRangeConfig"
          }
        },
        "type": "object",
        "required": [
          "query",
          "time_range_config"
        ],
        "title": "DataConfigStatistics"
      },
      "DataConfigStatistics-Output": {
        "properties": {
          "type": {
            "type": "string",
            "const": "statistics",
            "title": "Type",
            "default": "statistics"
          },
          "query": {
            "$ref": "#/components/schemas/PolicyQuery"
          },
          "time_range_config": {
            "$ref": "#/components/schemas/TimeRangeConfig"
          }
        },
        "type": "object",
        "required": [
          "query",
          "time_range_config"
        ],
        "title": "DataConfigStatistics"
      },
      "DistanceFunction": {
        "type": "string",
        "enum": [
          "wasserstein_distance",
          "jensen_shannon_divergence"
        ],
        "title": "DistanceFunction"
      },
      "MovingAverageThresholdSettings": {
        "properties": {
          "is_violation_above": {
            "type": "boolean",
            "title": "Is Violation Above",
            "default": true
          },
          "is_violation_below": {
            "type": "boolean",
            "title": "Is Violation Below",
            "default": true
          },
          "violation_deviation": {
            "type": "number",
            "exclusiveMinimum": 0,
            "title": "Violation Deviation"
          },
          "threshold_type": {
            "type": "string",
            "const": "moving_average",
            "title": "Threshold Type",
            "default": "moving_average"
          },
          "window_size": {
            "type": "integer",
            "exclusiveMinimum": 0,
            "title": "Window Size"
          }
        },
        "type": "object",
        "required": [
          "violation_deviation",
          "window_size"
        ],
        "title": "MovingAverageThresholdSettings"
      },
      "PolicyCreate": {
        "properties": {
          "alert_on_policy_level": {
            "type": "boolean",
            "title": "Alert On Policy Level",
            "description": "Trigger policy action on a single group/entire groups"
          },
          "name": {
            "type": "string",
            "title": "Policy Name",
            "description": "A descriptive name for this policy"
          },
          "dataset_id": {
            "type": "string",
            "title": "Dataset Id",
            "description": "The dataset this policy is monitoring"
          },
          "destination_ids": {
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "type": "array",
            "title": "Destination Ids",
            "description": "List of communication channels to get notified through"
          },
          "cron_expression": {
            "type": "string",
            "title": "Cron Expression",
            "description": "Cron expression for policy evaluation"
          },
          "threshold_settings": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/StaticThresholdSettings"
              },
              {
                "$ref": "#/components/schemas/MovingAverageThresholdSettings"
              }
            ],
            "title": "Threshold Settings",
            "discriminator": {
              "propertyName": "threshold_type",
              "mapping": {
                "moving_average": "#/components/schemas/MovingAverageThresholdSettings",
                "static": "#/components/schemas/StaticThresholdSettings"
              }
            }
          },
          "alert_on_status": {
            "$ref": "#/components/schemas/AlertOnStatusDirection",
            "description": "Trigger policy action if the value is above/below"
          },
          "data_config": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DataConfigStatistics-Input"
              },
              {
                "$ref": "#/components/schemas/DataConfigDistributionCompare-Input"
              }
            ],
            "title": "Data Config"
          },
          "dataset_b_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Dataset B Id",
            "description": "The second dataset this policy is monitoring"
          },
          "description": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Description",
            "description": "A description for this policy"
          },
          "initialize_with_historic_data": {
            "type": "boolean",
            "title": "Initialize With Historic Data",
            "description": "If true, the policy will be initialized with historic data",
            "default": false
          }
        },
        "type": "object",
        "required": [
          "alert_on_policy_level",
          "name",
          "dataset_id",
          "destination_ids",
          "cron_expression",
          "threshold_settings",
          "alert_on_status",
          "data_config"
        ],
        "title": "PolicyCreate"
      },
      "PolicyQuery": {
        "properties": {
          "measures": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Measures"
          },
          "order": {
            "anyOf": [
              {
                "items": {
                  "$ref": "#/components/schemas/PolicyQueryOrder"
                },
                "type": "array"
              },
              {
                "$ref": "#/components/schemas/PolicyQueryOrder"
              },
              {
                "type": "null"
              }
            ],
            "title": "Order"
          },
          "dimensions": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Dimensions"
          },
          "timezone": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Timezone",
            "default": "UTC"
          },
          "filters": {
            "items": {
              "anyOf": [
                {
                  "$ref": "#/components/schemas/PolicyQueryFilter"
                },
                {
                  "$ref": "#/components/schemas/PolicyQueryFilterWithoutNoneValues"
                }
              ]
            },
            "type": "array",
            "title": "Filters"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "measures"
        ],
        "title": "PolicyQuery",
        "example": {
          "dimensions": [
            "Orders.status"
          ],
          "filters": [
            {
              "member": "Orders.status",
              "operator": "equals",
              "values": [
                "processing"
              ]
            }
          ],
          "measures": [
            "Orders.count"
          ],
          "order": [
            {
              "desc": true,
              "id": "Orders.count"
            }
          ],
          "timezone": "UTC"
        }
      },
      "PolicyQueryFilter": {
        "properties": {
          "member": {
            "type": "string",
            "title": "Member"
          },
          "operator": {
            "type": "string",
            "title": "Operator"
          },
          "values": {
            "anyOf": [
              {
                "items": {
                  "type": "string"
                },
                "type": "array"
              },
              {
                "type": "string"
              }
            ],
            "title": "Values"
          }
        },
        "type": "object",
        "required": [
          "member",
          "operator",
          "values"
        ],
        "title": "PolicyQueryFilter"
      },
      "PolicyQueryFilterWithoutNoneValues": {
        "properties": {
          "member": {
            "type": "string",
            "title": "Member"
          },
          "operator": {
            "type": "string",
            "title": "Operator"
          }
        },
        "type": "object",
        "required": [
          "member",
          "operator"
        ],
        "title": "PolicyQueryFilterWithoutNoneValues"
      },
      "PolicyQueryOrder": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "desc": {
            "type": "boolean",
            "title": "Desc"
          }
        },
        "type": "object",
        "required": [
          "id",
          "desc"
        ],
        "title": "PolicyQueryOrder"
      },
      "PolicyResponse": {
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "title": "Id"
          },
          "name": {
            "type": "string",
            "title": "Policy Name",
            "description": "A descriptive name for this policy"
          },
          "data_config": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DataConfigStatistics-Output"
              },
              {
                "$ref": "#/components/schemas/DataConfigDistributionCompare-Output"
              }
            ],
            "title": "Data Config"
          },
          "created_by": {
            "type": "string",
            "title": "Created By"
          },
          "updated_by": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Updated By"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "title": "Created At"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "title": "Updated At"
          },
          "last_evaluation": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Last Evaluation"
          },
          "next_evaluation": {
            "type": "string",
            "format": "date-time",
            "title": "Next Evaluation"
          },
          "status": {
            "$ref": "#/components/schemas/PolicyStatus",
            "default": "pending"
          },
          "threshold_settings": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/StaticThresholdSettings"
              },
              {
                "$ref": "#/components/schemas/MovingAverageThresholdSettings"
              }
            ],
            "title": "Threshold Settings",
            "discriminator": {
              "propertyName": "threshold_type",
              "mapping": {
                "moving_average": "#/components/schemas/MovingAverageThresholdSettings",
                "static": "#/components/schemas/StaticThresholdSettings"
              }
            }
          },
          "cron_expression": {
            "type": "string",
            "title": "Cron Expression"
          },
          "destination_ids": {
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "type": "array",
            "title": "Destination Ids",
            "default": []
          },
          "alert_on_status": {
            "$ref": "#/components/schemas/AlertOnStatusDirection"
          },
          "alert_on_policy_level": {
            "type": "boolean",
            "title": "Alert On Policy Level"
          },
          "tenant_id": {
            "type": "string",
            "title": "Tenant Id"
          },
          "dataset_id": {
            "type": "string",
            "title": "Dataset Id"
          },
          "dataset_b_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Dataset B Id"
          },
          "status_reason": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ValidationResult"
              },
              {
                "type": "null"
              }
            ]
          },
          "is_running": {
            "type": "boolean",
            "title": "Is Running"
          },
          "is_triggered": {
            "type": "boolean",
            "title": "Is Triggered"
          },
          "initialize_with_historic_data": {
            "type": "boolean",
            "title": "Initialize With Historic Data"
          },
          "description": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Description"
          },
          "tags": {
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "type": "array",
            "title": "Tags"
          },
          "archived_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Archived At"
          }
        },
        "type": "object",
        "required": [
          "id",
          "name",
          "data_config",
          "created_by",
          "created_at",
          "updated_at",
          "next_evaluation",
          "threshold_settings",
          "cron_expression",
          "alert_on_status",
          "alert_on_policy_level",
          "tenant_id",
          "dataset_id",
          "is_running",
          "is_triggered",
          "initialize_with_historic_data"
        ],
        "title": "PolicyResponse"
      },
      "PolicyStatus": {
        "type": "string",
        "enum": [
          "pending",
          "healthy",
          "unhealthy",
          "error",
          "no_data"
        ],
        "title": "PolicyStatus"
      },
      "StaticThresholdSettings": {
        "properties": {
          "condition_above_value": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Condition Above Value",
            "description": "Condition above value"
          },
          "condition_below_value": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Condition Below Value",
            "description": "Condition below value"
          },
          "threshold_type": {
            "type": "string",
            "const": "static",
            "title": "Threshold Type",
            "default": "static"
          }
        },
        "type": "object",
        "title": "StaticThresholdSettings"
      },
      "TimeRangeConfig": {
        "properties": {
          "field_name": {
            "type": "string",
            "title": "Field Name"
          },
          "unit": {
            "$ref": "#/components/schemas/TimeRangeUnit"
          },
          "value": {
            "type": "integer",
            "title": "Value"
          }
        },
        "type": "object",
        "required": [
          "field_name",
          "unit",
          "value"
        ],
        "title": "TimeRangeConfig"
      },
      "TimeRangeUnit": {
        "type": "string",
        "enum": [
          "MINUTE",
          "HOUR",
          "DAY",
          "WEEK",
          "MONTH"
        ],
        "title": "TimeRangeUnit"
      },
      "ValidationErrorDetail": {
        "properties": {
          "type": {
            "type": "string",
            "title": "Type"
          },
          "detail": {
            "type": "string",
            "title": "Detail"
          },
          "invalid_key": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Invalid Key"
          }
        },
        "type": "object",
        "required": [
          "type",
          "detail"
        ],
        "title": "ValidationErrorDetail"
      },
      "ValidationResult": {
        "properties": {
          "is_valid": {
            "type": "boolean",
            "title": "Is Valid",
            "default": false
          },
          "errors": {
            "items": {
              "$ref": "#/components/schemas/ValidationErrorDetail"
            },
            "type": "array",
            "title": "Errors"
          }
        },
        "type": "object",
        "title": "ValidationResult"
      },
      "DashboardItemDistributionCompareQuery-Input": {
        "properties": {
          "measures": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Measures"
          },
          "order": {
            "anyOf": [
              {
                "items": {
                  "items": {},
                  "type": "array"
                },
                "type": "array"
              },
              {
                "items": {},
                "type": "array"
              },
              {
                "type": "null"
              }
            ],
            "title": "Order"
          },
          "dimensions": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Dimensions"
          },
          "timezone": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Timezone",
            "default": "UTC"
          },
          "filters": {
            "items": {
              "$ref": "#/components/schemas/Filter"
            },
            "type": "array",
            "title": "Filters"
          },
          "limit": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Limit"
          },
          "timeDimensions": {
            "items": {
              "$ref": "#/components/schemas/TimeDimension"
            },
            "type": "array",
            "title": "Timedimensions"
          }
        },
        "type": "object",
        "required": [
          "measures"
        ],
        "title": "DashboardItemBaseQuery"
      },
      "DashboardItemDistributionCompareQuery-Output": {
        "properties": {
          "measures": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Measures"
          },
          "order": {
            "anyOf": [
              {
                "items": {
                  "items": {},
                  "type": "array"
                },
                "type": "array"
              },
              {
                "items": {},
                "type": "array"
              },
              {
                "type": "null"
              }
            ],
            "title": "Order"
          },
          "dimensions": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Dimensions"
          },
          "timezone": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Timezone",
            "default": "UTC"
          },
          "filters": {
            "items": {
              "$ref": "#/components/schemas/Filter"
            },
            "type": "array",
            "title": "Filters"
          },
          "limit": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Limit"
          },
          "timeDimensions": {
            "items": {
              "$ref": "#/components/schemas/TimeDimension"
            },
            "type": "array",
            "title": "Timedimensions"
          }
        },
        "type": "object",
        "required": [
          "measures"
        ],
        "title": "DashboardItemBaseQuery"
      },
      "Filter": {
        "properties": {
          "member": {
            "type": "string",
            "title": "Member"
          },
          "operator": {
            "type": "string",
            "title": "Operator"
          },
          "values": {
            "anyOf": [
              {
                "items": {
                  "type": "string"
                },
                "type": "array"
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Values"
          }
        },
        "type": "object",
        "required": [
          "member",
          "operator"
        ],
        "title": "DashboardItemQueryFilter"
      },
      "Granularity": {
        "type": "string",
        "enum": [
          "minute",
          "hour",
          "day",
          "week",
          "month",
          "quarter",
          "year"
        ],
        "title": "Granularity"
      },
      "TimeDimension": {
        "properties": {
          "dimension": {
            "type": "string",
            "title": "Dimension"
          },
          "granularity": {
            "$ref": "#/components/schemas/Granularity"
          }
        },
        "type": "object",
        "required": [
          "dimension",
          "granularity"
        ],
        "title": "DashboardItemQueryTimeDimension"
      }
    },
    "securitySchemes": {
      "implicit": {
        "type": "oauth2",
        "flows": {
          "implicit": {
            "authorizationUrl": "https://authentication.superwise.ai/identity/resources/auth/v1/api-token",
            "scopes": {}
          }
        }
      }
    }
  },
  "security": [
    {
      "implicit": []
    }
  ],
  "servers": [
    {
      "url": "api.superwise.ai",
      "description": "Superwise Api Gateway"
    }
  ]
}
```