{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/anomalyarmor-ai/json-schema/anomalyarmor-ai-validity-rule-create-schema.json",
  "title": "ValidityRuleCreate",
  "description": "Request schema for creating a validity rule.",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/docs.anomalyarmor.ai-openapi.json#/components/schemas/ValidityRuleCreate",
  "properties": {
    "table_path": {
      "type": "string",
      "title": "Table Path",
      "description": "Fully qualified table path"
    },
    "column_name": {
      "type": "string",
      "title": "Column Name",
      "description": "Column to validate"
    },
    "rule_type": {
      "$ref": "#/$defs/RuleType",
      "description": "Type of validation rule"
    },
    "rule_config": {
      "additionalProperties": true,
      "type": "object",
      "title": "Rule Config",
      "description": "Rule-specific configuration"
    },
    "name": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 255
        },
        {
          "type": "null"
        }
      ],
      "title": "Name",
      "description": "Optional rule name"
    },
    "description": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Description",
      "description": "Optional description"
    },
    "error_message": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Error Message",
      "description": "Custom error message"
    },
    "severity": {
      "$ref": "#/$defs/Severity",
      "description": "Severity level",
      "default": "error"
    },
    "alert_threshold_percent": {
      "anyOf": [
        {
          "type": "number",
          "maximum": 100.0,
          "minimum": 0.0
        },
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Alert Threshold Percent",
      "description": "Alert threshold percentage (manual mode)"
    },
    "detection_mode": {
      "type": "string",
      "enum": [
        "manual",
        "auto"
      ],
      "title": "Detection Mode",
      "description": "'manual' (fixed threshold) or 'auto' (learned baseline)",
      "default": "manual"
    },
    "sensitivity": {
      "type": "integer",
      "maximum": 4.0,
      "minimum": 1.0,
      "title": "Sensitivity",
      "description": "1-4 stddev threshold for auto mode",
      "default": 2
    },
    "operating_period_mode": {
      "type": "string",
      "enum": [
        "off",
        "auto",
        "schedule"
      ],
      "title": "Operating Period Mode",
      "description": "Operating-period awareness (TECH-984): 'off' pools all history, 'schedule' segments by operating_schedule_id, 'auto' learns a calendar from history",
      "default": "off"
    },
    "operating_schedule_id": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ],
      "title": "Operating Schedule Id",
      "description": "Public UUID of the operating schedule (required for 'schedule' mode)"
    },
    "treat_null_as_valid": {
      "type": "boolean",
      "title": "Treat Null As Valid",
      "description": "Whether NULL values pass validation",
      "default": true
    },
    "check_interval": {
      "$ref": "#/$defs/CheckInterval",
      "description": "Check frequency (hourly, daily, weekly)",
      "default": "daily"
    }
  },
  "type": "object",
  "required": [
    "table_path",
    "column_name",
    "rule_type",
    "rule_config"
  ],
  "$defs": {
    "CheckInterval": {
      "type": "string",
      "enum": [
        "hourly",
        "daily",
        "weekly"
      ],
      "title": "CheckInterval",
      "description": "Check interval options for validity rules.\n\nThese values match what the scheduler queries for in get_due_for_check."
    },
    "RuleType": {
      "type": "string",
      "enum": [
        "regex_match",
        "allowed_values",
        "range_bounds",
        "format",
        "length_bounds"
      ],
      "title": "RuleType",
      "description": "Types of validity rules."
    },
    "Severity": {
      "type": "string",
      "enum": [
        "error",
        "warning"
      ],
      "title": "Severity",
      "description": "Severity levels for validity rules."
    }
  }
}