{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/microsoft-cognitive-services/json-schema/microsoft-cognitive-services-rai-policy-schema.json",
  "title": "RaiPolicy",
  "description": "Cognitive Services RaiPolicy.",
  "x-generated": "2026-11-12",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_superseded/microsoft-cognitive-services-raipolicies-api-openapi.yml#/components/schemas/RaiPolicy",
  "type": "object",
  "properties": {
    "properties": {
      "$ref": "#/$defs/RaiPolicyProperties",
      "description": "Properties of Cognitive Services RaiPolicy."
    },
    "etag": {
      "type": "string",
      "description": "Resource Etag.",
      "readOnly": true
    },
    "tags": {
      "type": "object",
      "description": "Resource tags.",
      "additionalProperties": {
        "type": "string"
      },
      "x-ms-mutability": [
        "read",
        "update",
        "create"
      ]
    }
  },
  "allOf": [
    {
      "$ref": "../../../../../../common-types/resource-management/v3/types.json#/definitions/ProxyResource"
    }
  ],
  "$defs": {
    "ContentLevel": {
      "type": "string",
      "description": "Level at which content is filtered.",
      "enum": [
        "Low",
        "Medium",
        "High"
      ],
      "x-ms-enum": {
        "name": "ContentLevel",
        "modelAsString": true,
        "values": [
          {
            "name": "Low",
            "value": "Low"
          },
          {
            "name": "Medium",
            "value": "Medium"
          },
          {
            "name": "High",
            "value": "High"
          }
        ]
      }
    },
    "CustomBlocklistConfig": {
      "type": "object",
      "description": "Gets or sets the source to which filter applies.",
      "properties": {
        "source": {
          "$ref": "#/$defs/RaiPolicyContentSource",
          "description": "Content source to apply the Content Filters."
        }
      },
      "allOf": [
        {
          "$ref": "#/$defs/RaiBlocklistConfig"
        }
      ]
    },
    "RaiActionType": {
      "type": "string",
      "description": "The action types to apply to the content filters",
      "enum": [
        "None",
        "BLOCKING",
        "ANNOTATING",
        "HITL",
        "RETRY"
      ],
      "x-ms-enum": {
        "name": "RaiActionType",
        "modelAsString": true,
        "values": [
          {
            "name": "None",
            "value": "None"
          },
          {
            "name": "BLOCKING",
            "value": "BLOCKING"
          },
          {
            "name": "ANNOTATING",
            "value": "ANNOTATING"
          },
          {
            "name": "HITL",
            "value": "HITL"
          },
          {
            "name": "RETRY",
            "value": "RETRY"
          }
        ]
      }
    },
    "RaiBlocklistConfig": {
      "type": "object",
      "description": "Azure OpenAI blocklist config.",
      "properties": {
        "blocklistName": {
          "type": "string",
          "description": "Name of ContentFilter."
        },
        "blocking": {
          "type": "boolean",
          "description": "If blocking would occur."
        }
      }
    },
    "RaiEgressDefaultAction": {
      "type": "string",
      "description": "The default action when no user-defined egress rules match.",
      "enum": [
        "Allow",
        "Deny"
      ],
      "x-ms-enum": {
        "name": "RaiEgressDefaultAction",
        "modelAsString": true,
        "values": [
          {
            "name": "Allow",
            "value": "Allow",
            "description": "Allow traffic by default when no rules match."
          },
          {
            "name": "Deny",
            "value": "Deny",
            "description": "Deny traffic by default when no rules match."
          }
        ]
      }
    },
    "RaiEgressHeaderOperation": {
      "type": "string",
      "description": "The operation to apply to a header in a Transform or Rewrite action.",
      "enum": [
        "Set",
        "Insert",
        "Remove"
      ],
      "x-ms-enum": {
        "name": "RaiEgressHeaderOperation",
        "modelAsString": true,
        "values": [
          {
            "name": "Set",
            "value": "Set",
            "description": "Set or overwrite the header value, creating it if it does not exist."
          },
          {
            "name": "Insert",
            "value": "Insert",
            "description": "Add the header only if it is not already present."
          },
          {
            "name": "Remove",
            "value": "Remove",
            "description": "Remove the header if present."
          }
        ]
      }
    },
    "RaiEgressHeaderTransform": {
      "type": "object",
      "description": "A header transformation applied to matched traffic.\nFor Set or Insert operations, exactly one of value or valueRef must be provided.\nFor Remove operations, neither value nor valueRef should be set.",
      "properties": {
        "operation": {
          "$ref": "#/$defs/RaiEgressHeaderOperation",
          "description": "The operation to perform on this header."
        },
        "name": {
          "type": "string",
          "description": "The HTTP header name (e.g., \"Authorization\", \"X-Custom-Auth\")."
        },
        "value": {
          "type": "string",
          "format": "password",
          "description": "A static header value. Write-only: accepted on create/update, never returned on read.\nIf omitted on update, the existing value is preserved. Use this for non-sensitive values;\nfor credentials, use valueRef instead.",
          "x-ms-mutability": [
            "update",
            "create"
          ],
          "x-ms-secret": true
        },
        "valueRef": {
          "$ref": "#/$defs/RaiEgressHeaderValueRef",
          "description": "A dynamic header value resolved at request time from a secret or managed identity."
        }
      },
      "required": [
        "operation",
        "name"
      ]
    },
    "RaiEgressHeaderValueRef": {
      "type": "object",
      "description": "A dynamic source for a header value. Exactly one of secretRef or managedIdentityRef must be set.",
      "properties": {
        "secretRef": {
          "$ref": "#/$defs/RaiEgressSecretRef",
          "description": "Resolve the value from a stored secret."
        },
        "managedIdentityRef": {
          "$ref": "#/$defs/RaiEgressManagedIdentityRef",
          "description": "Resolve the value from a managed-identity token."
        }
      }
    },
    "RaiEgressManagedIdentityRef": {
      "type": "object",
      "description": "A reference to a managed-identity token used as a header value.",
      "properties": {
        "resource": {
          "type": "string",
          "description": "The resource/audience the token is requested for."
        },
        "format": {
          "type": "string",
          "description": "Optional format for the resolved token; \"{value}\" is the placeholder, e.g. \"Bearer {value}\"."
        }
      },
      "required": [
        "resource"
      ]
    },
    "RaiEgressMode": {
      "type": "string",
      "description": "The enforcement mode for egress rules.\nIf omitted on create, the server defaults to Enforced.",
      "enum": [
        "Enforced",
        "Audit"
      ],
      "x-ms-enum": {
        "name": "RaiEgressMode",
        "modelAsString": true,
        "values": [
          {
            "name": "Enforced",
            "value": "Enforced",
            "description": "Rules are enforced. Matching traffic is allowed or denied per rule actions."
          },
          {
            "name": "Audit",
            "value": "Audit",
            "description": "Rules are evaluated and logged but not enforced. Traffic is always forwarded regardless of\nrule action. A would-be Deny is logged but not applied. Transform and Rewrite actions are\nstill applied to matching traffic (only Deny enforcement is suppressed)."
          }
        ]
      }
    },
    "RaiEgressPolicyConfig": {
      "type": "object",
      "description": "Egress (outbound network) policy configuration nested within an RAI policy.\nControls which external endpoints sandboxed agents can reach and what\ntransformations (header injection, URL rewrite) are applied to matching traffic.",
      "properties": {
        "mode": {
          "$ref": "#/$defs/RaiEgressMode",
          "description": "The enforcement mode for egress rules.\nIf omitted on create, the server defaults to Enforced. On subsequent GET\nrequests, the server always returns the effective mode."
        },
        "defaultAction": {
          "$ref": "#/$defs/RaiEgressDefaultAction",
          "description": "The default action when no user-defined rules match.\nDeny blocks unmatched traffic; Allow permits it. Transform and Rewrite rules\nare always applied to their matched traffic regardless of this setting —\ndefaultAction only governs traffic that does not match any rule.\nIf omitted on create, the server defaults to Deny (fail-closed). On subsequent\nGET requests, the server always returns the effective value."
        },
        "description": {
          "type": "string",
          "description": "Description of the egress policy."
        },
        "rules": {
          "type": "array",
          "description": "Ordered list of egress rules. First matching rule wins.\nRules are evaluated in declaration order; the first rule whose match criteria\nare satisfied determines the action taken on the request.",
          "items": {
            "$ref": "#/$defs/RaiEgressRule"
          },
          "x-ms-identifiers": [
            "name"
          ]
        }
      }
    },
    "RaiEgressRewriteTarget": {
      "type": "object",
      "description": "Where a Rewrite action sends matched traffic. At least one field must be set;\nomitted fields retain the original request values. This constraint is enforced\nby the server (400 Bad Request if all fields are omitted).",
      "properties": {
        "scheme": {
          "$ref": "#/$defs/RaiEgressScheme",
          "description": "Target scheme. Original scheme is kept if omitted."
        },
        "host": {
          "type": "string",
          "description": "Target host. Original host is kept if omitted."
        },
        "path": {
          "type": "string",
          "description": "Target path (literal string). Original path (and query) is kept if omitted."
        }
      }
    },
    "RaiEgressRule": {
      "type": "object",
      "description": "A single egress rule. Rules are evaluated in order; first match wins.",
      "properties": {
        "name": {
          "type": "string",
          "description": "Name of the rule. Must be unique within the policy."
        },
        "description": {
          "type": "string",
          "description": "Description of the rule."
        },
        "ruleType": {
          "$ref": "#/$defs/RaiEgressRuleType",
          "description": "The type of rule (e.g., Fqdn). Determines how match criteria are interpreted."
        },
        "match": {
          "$ref": "#/$defs/RaiEgressRuleMatch",
          "description": "The match criteria for this rule."
        },
        "action": {
          "$ref": "#/$defs/RaiEgressRuleAction",
          "description": "The action to take when this rule matches, including the action type and any\ntype-specific configuration (headers for Transform, rewrite target for Rewrite)."
        }
      },
      "required": [
        "name",
        "ruleType",
        "action"
      ]
    },
    "RaiEgressRuleAction": {
      "type": "object",
      "description": "The action an egress rule takes when it matches.\n- Allow/Deny: no additional fields needed; headers and rewrite must not be set.\n- Transform: headers is required with at least one entry; rewrite must not be set.\n- Rewrite: rewrite is required with at least one of scheme/host/path;\nheaders is optional for injecting headers alongside the redirect.",
      "properties": {
        "actionType": {
          "$ref": "#/$defs/RaiEgressRuleActionType",
          "description": "The kind of action."
        },
        "headers": {
          "type": "array",
          "description": "Header transforms to apply. Required for Transform; optional for Rewrite;\nnot allowed for Allow or Deny.",
          "items": {
            "$ref": "#/$defs/RaiEgressHeaderTransform"
          },
          "x-ms-identifiers": [
            "name"
          ]
        },
        "rewrite": {
          "$ref": "#/$defs/RaiEgressRewriteTarget",
          "description": "Destination override. Required for Rewrite; not allowed otherwise."
        }
      },
      "required": [
        "actionType"
      ]
    },
    "RaiEgressRuleActionType": {
      "type": "string",
      "description": "The kind of action an egress rule takes when it matches.",
      "enum": [
        "Allow",
        "Deny",
        "Transform",
        "Rewrite"
      ],
      "x-ms-enum": {
        "name": "RaiEgressRuleActionType",
        "modelAsString": true,
        "values": [
          {
            "name": "Allow",
            "value": "Allow",
            "description": "Allow the matched traffic."
          },
          {
            "name": "Deny",
            "value": "Deny",
            "description": "Deny the matched traffic."
          },
          {
            "name": "Transform",
            "value": "Transform",
            "description": "Forward the matched traffic after applying header transforms. Requires at least one header."
          },
          {
            "name": "Rewrite",
            "value": "Rewrite",
            "description": "Redirect the matched traffic to a new destination, optionally applying header transforms. Requires a rewrite target."
          }
        ]
      }
    },
    "RaiEgressRuleMatch": {
      "type": "object",
      "description": "The match criteria for an egress rule.\nIf both host and path are omitted, the rule matches all traffic.\nHost uses DNS wildcard syntax (e.g., \"\\*.openai.com\" matches \"api.openai.com\").\nPath uses URI prefix matching with an asterisk as a single-segment wildcard.\nFor example, \"/v1/\\*\" matches \"/v1/chat\".",
      "properties": {
        "host": {
          "type": "string",
          "description": "Host pattern to match using DNS wildcard syntax (e.g., \"\\*.openai.com\").\nA leading \"\\*.\" matches any subdomain. Omit to match all hosts."
        },
        "path": {
          "type": "string",
          "description": "Path pattern to match using URI prefix matching.\nAn asterisk serves as a single-segment wildcard.\nFor example, \"/v1/\\*\" matches \"/v1/chat\". Omit to match all paths."
        }
      }
    },
    "RaiEgressRuleType": {
      "type": "string",
      "description": "The type of an egress rule, determining what kind of traffic matching it performs.",
      "enum": [
        "Fqdn"
      ],
      "x-ms-enum": {
        "name": "RaiEgressRuleType",
        "modelAsString": true,
        "values": [
          {
            "name": "Fqdn",
            "value": "Fqdn",
            "description": "Fully qualified domain name (FQDN) based rule matching on host and path patterns."
          }
        ]
      }
    },
    "RaiEgressScheme": {
      "type": "string",
      "description": "URL scheme for rewrite targets. Only HTTP and HTTPS are supported.",
      "enum": [
        "http",
        "https"
      ],
      "x-ms-enum": {
        "name": "RaiEgressScheme",
        "modelAsString": true,
        "values": [
          {
            "name": "Http",
            "value": "http",
            "description": "HTTP scheme."
          },
          {
            "name": "Https",
            "value": "https",
            "description": "HTTPS scheme."
          }
        ]
      }
    },
    "RaiEgressSecretRef": {
      "type": "object",
      "description": "A reference to a stored secret used as a header value.",
      "properties": {
        "secretId": {
          "type": "string",
          "description": "Identifier of the secret to inject."
        },
        "secretKey": {
          "type": "string",
          "format": "password",
          "description": "Optional key within the secret.",
          "x-ms-secret": true
        },
        "format": {
          "type": "string",
          "description": "Optional format for the resolved value; \"{value}\" is the placeholder, e.g. \"Bearer {value}\"."
        }
      },
      "required": [
        "secretId"
      ]
    },
    "RaiPolicyContentFilter": {
      "type": "object",
      "description": "Azure OpenAI Content Filter.",
      "properties": {
        "name": {
          "type": "string",
          "description": "Name of ContentFilter."
        },
        "enabled": {
          "type": "boolean",
          "description": "If the ContentFilter is enabled."
        },
        "severityThreshold": {
          "$ref": "#/$defs/ContentLevel",
          "description": "Level at which content is filtered."
        },
        "blocking": {
          "type": "boolean",
          "description": "If blocking would occur."
        },
        "source": {
          "$ref": "#/$defs/RaiPolicyContentSource",
          "description": "Content source to apply the Content Filters."
        },
        "action": {
          "$ref": "#/$defs/RaiActionType",
          "description": "The action types to apply to the content filters"
        }
      }
    },
    "RaiPolicyContentSource": {
      "type": "string",
      "description": "Content source to apply the Content Filters.",
      "enum": [
        "Prompt",
        "Completion",
        "PreToolCall",
        "PostToolCall",
        "PreRun",
        "PostRun"
      ],
      "x-ms-enum": {
        "name": "RaiPolicyContentSource",
        "modelAsString": true,
        "values": [
          {
            "name": "Prompt",
            "value": "Prompt"
          },
          {
            "name": "Completion",
            "value": "Completion"
          },
          {
            "name": "PreToolCall",
            "value": "PreToolCall"
          },
          {
            "name": "PostToolCall",
            "value": "PostToolCall"
          },
          {
            "name": "PreRun",
            "value": "PreRun"
          },
          {
            "name": "PostRun",
            "value": "PostRun"
          }
        ]
      }
    },
    "RaiPolicyMode": {
      "type": "string",
      "description": "Rai policy mode. The enum value mapping is as below: Default = 0, Deferred=1, Blocking=2, Asynchronous_filter =3. Please use 'Asynchronous_filter' after 2025-06-01. It is the same as 'Deferred' in previous version.",
      "enum": [
        "Default",
        "Deferred",
        "Blocking",
        "Asynchronous_filter"
      ],
      "x-ms-enum": {
        "name": "RaiPolicyMode",
        "modelAsString": true,
        "values": [
          {
            "name": "Default",
            "value": "Default"
          },
          {
            "name": "Deferred",
            "value": "Deferred"
          },
          {
            "name": "Blocking",
            "value": "Blocking"
          },
          {
            "name": "Asynchronous_filter",
            "value": "Asynchronous_filter"
          }
        ]
      }
    },
    "RaiPolicyProperties": {
      "type": "object",
      "description": "Azure OpenAI Content Filters properties.",
      "properties": {
        "type": {
          "$ref": "#/$defs/RaiPolicyType",
          "description": "Content Filters policy type.",
          "readOnly": true
        },
        "mode": {
          "$ref": "#/$defs/RaiPolicyMode",
          "description": "Rai policy mode. The enum value mapping is as below: Default = 0, Deferred=1, Blocking=2, Asynchronous_filter =3. Please use 'Asynchronous_filter' after 2025-06-01. It is the same as 'Deferred' in previous version."
        },
        "basePolicyName": {
          "type": "string",
          "description": "Name of Rai policy."
        },
        "contentFilters": {
          "type": "array",
          "description": "The list of Content Filters.",
          "items": {
            "$ref": "#/$defs/RaiPolicyContentFilter"
          },
          "x-ms-identifiers": [
            "name"
          ]
        },
        "customBlocklists": {
          "type": "array",
          "description": "The list of custom Blocklist.",
          "items": {
            "$ref": "#/$defs/CustomBlocklistConfig"
          },
          "x-ms-identifiers": []
        },
        "safetyProviders": {
          "type": "array",
          "description": "The list of Safety Providers.",
          "items": {
            "$ref": "#/$defs/SafetyProviderConfig"
          },
          "x-ms-identifiers": []
        },
        "egressPolicy": {
          "$ref": "#/$defs/RaiEgressPolicyConfig",
          "description": "Egress (outbound network) policy controlling which external endpoints sandboxed\nagents can reach. Includes rules with Allow/Deny/Transform/Rewrite actions."
        }
      }
    },
    "RaiPolicyType": {
      "type": "string",
      "description": "Content Filters policy type.",
      "enum": [
        "UserManaged",
        "SystemManaged"
      ],
      "x-ms-enum": {
        "name": "RaiPolicyType",
        "modelAsString": true,
        "values": [
          {
            "name": "UserManaged",
            "value": "UserManaged"
          },
          {
            "name": "SystemManaged",
            "value": "SystemManaged"
          }
        ]
      }
    },
    "RaiSafetyProviderConfig": {
      "type": "object",
      "description": "Azure OpenAI RAI safety provider config.",
      "properties": {
        "safetyProviderName": {
          "type": "string",
          "description": "Name of RAI Safety Provider."
        },
        "blocking": {
          "type": "boolean",
          "description": "If blocking would occur."
        }
      }
    },
    "SafetyProviderConfig": {
      "type": "object",
      "description": "Gets or sets the source to which safety providers applies.",
      "properties": {
        "source": {
          "$ref": "#/$defs/RaiPolicyContentSource",
          "description": "Content source to apply the Content Filters."
        }
      },
      "allOf": [
        {
          "$ref": "#/$defs/RaiSafetyProviderConfig"
        }
      ]
    }
  }
}