{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://optinrouter.ai/docs/schemas/trace-event.schema.json",
  "title": "OptinRouter trace-event preview contract",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "event_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "parent_event_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "trace_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "request_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "policy_ref": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[a-zA-Z0-9_.@:/-]+$"
    },
    "stage": {
      "enum": [
        "input",
        "routing",
        "inference",
        "output",
        "action",
        "delivery"
      ]
    },
    "outcome": {
      "enum": [
        "allowed",
        "blocked",
        "held",
        "failed",
        "cancelled"
      ]
    },
    "location": {
      "enum": [
        "managed",
        "customer_server",
        "end_device"
      ]
    },
    "region": {
      "type": [
        "string",
        "null"
      ]
    },
    "region_evidence": {
      "enum": [
        "verified",
        "attested",
        "unknown"
      ]
    },
    "duration_ms": {
      "type": "number",
      "minimum": 0
    },
    "content_retained": {
      "type": "boolean"
    }
  },
  "required": [
    "event_id",
    "parent_event_id",
    "trace_id",
    "request_id",
    "policy_ref",
    "stage",
    "outcome",
    "location",
    "region",
    "region_evidence",
    "duration_ms",
    "content_retained"
  ]
}
