---
title: "Create Validity Rule"
method: POST
path: "/api/v1/sdk/validity/{asset_id}"
tags: ["public-api", "public-validity"]
---

# Create Validity Rule

`POST /api/v1/sdk/validity/{asset_id}`

## Request

- Base URL: `http://localhost:8000`
- URL: `http://localhost:8000/api/v1/sdk/validity/{asset_id}`
- Auth: none declared

Create a new validity rule.

Requires read-write or admin scope.
Accepts asset UUID, qualified name (e.g., "postgresql.mydb"), or asset name.

**SDK Usage:**
```python
from anomalyarmor import Client
client = Client()
rule = client.validity.create(
    "asset-uuid",
    rule_type="NOT_NULL",
    table_path="catalog.schema.table",
    column_name="email",
    severity="critical",
)
```

## Path parameters

- `asset_id` string, required

## Headers

- `Authorization` string

## Request body

- ValidityRuleCreate: Request schema for creating a validity rule.
  - `table_path` string, required: Fully qualified table path
  - `column_name` string, required: Column to validate
  - `rule_type` 'regex_match' | 'allowed_values' | 'range_bounds' | 'format' | 'length_bounds', required: Types of validity rules.
  - `rule_config` object, required: Rule-specific configuration
  - `name` string, nullable: Optional rule name
  - `description` string, nullable: Optional description
  - `error_message` string, nullable: Custom error message
  - `severity` 'error' | 'warning': Severity levels for validity rules.
  - `alert_threshold_percent` union: Alert threshold percentage (manual mode)
    - number
    - string
  - `detection_mode` 'manual' | 'auto': 'manual' (fixed threshold) or 'auto' (learned baseline)
  - `sensitivity` integer: 1-4 stddev threshold for auto mode
  - `operating_period_mode` 'off' | 'auto' | 'schedule': Operating-period awareness (TECH-984): 'off' pools all history, 'schedule' segments by operating_schedule_id, 'auto' learns a calendar from history
  - `operating_schedule_id` string, uuid, nullable: Public UUID of the operating schedule (required for 'schedule' mode)
  - `treat_null_as_valid` boolean: Whether NULL values pass validation
  - `check_interval` 'hourly' | 'daily' | 'weekly': Check interval options for validity rules. These values match what the scheduler queries for in get_due_for_check.

## Response `201`

Successful Response

- StandardResponse: Standard API response wrapper.
  - `success` boolean, required
  - `data` unknown
  - `message` string, nullable
  - `error` string, nullable
  - `meta` object, nullable

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/anomalyarmor/apis/anomalyarmor-api.md) · [All operations](https://skmtc.dev/anomalyarmor/apis/anomalyarmor-api/llms.txt) · [OpenAPI document](https://skmtc.dev/anomalyarmor/apis/anomalyarmor-api/revisions/51c755fb5d0b?raw)
