{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/spendline-ai/json-schema/spendline-ai-policy-schema.json",
  "title": "Policy",
  "x-generated": "2026-11-25",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/spendline-ai-openapi.json#/components/schemas/Policy",
  "type": "object",
  "required": [
    "name",
    "type",
    "model"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "readOnly": true
    },
    "name": {
      "type": "string"
    },
    "type": {
      "type": "string",
      "enum": [
        "model_block",
        "model_allow",
        "max_input_tokens",
        "max_output_tokens"
      ],
      "description": "model_block refuses the named model. model_allow is one ENTRY in an allow-list: every enabled model_allow row sharing one exact scope is one list, and a call must match some entry of every list that applies to it. Both judge the requested and the served model."
    },
    "model": {
      "type": "string",
      "description": "Model name to match. Stored lowercased."
    },
    "match_mode": {
      "type": "string",
      "enum": [
        "exact",
        "prefix",
        "contains"
      ],
      "default": "exact"
    },
    "value": {
      "type": [
        "number",
        "null"
      ],
      "description": "Required positive number for token-limit types. Null for model_block and model_allow."
    },
    "enforcement": {
      "type": "string",
      "enum": [
        "block",
        "warn"
      ],
      "default": "block",
      "description": "Ignored for model_block and model_allow, which always block."
    },
    "enabled": {
      "type": "boolean",
      "default": true
    },
    "scope": {
      "type": [
        "object",
        "null"
      ],
      "description": "Optional; the same object a reroute rule carries. Omit for an account-wide policy. A scoped policy applies to calls attributed to that agent / customer AND to calls carrying no attribution, so leaving x-agent-id off is never a way around it. A call attributed to a different agent or customer is not affected. Unknown keys are a 400.",
      "properties": {
        "agent_id": {
          "type": "string"
        },
        "customer_id": {
          "type": "string"
        },
        "agent_name": {
          "type": "string"
        }
      }
    }
  }
}