{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aruntime.com/schemas/evidence-record.v1.schema.json",
  "title": "ARuntime Evidence Record v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "evidenceId",
    "requestId",
    "correlationId",
    "recordedUtc",
    "actorRef",
    "contractVersions",
    "contextReferences",
    "modelRoute",
    "toolInvocations",
    "approvalDecisions",
    "policyDecisions",
    "sideEffects",
    "failures",
    "retries",
    "recoverySteps",
    "evaluationResults",
    "finalOutputReference",
    "redaction",
    "retentionPolicy"
  ],
  "properties": {
    "schemaVersion": {
      "const": "aruntime.evidence-record.v1"
    },
    "evidenceId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "requestId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "correlationId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "recordedUtc": {
      "type": "string",
      "format": "date-time",
      "pattern": "Z$",
      "description": "UTC ISO 8601 timestamp ending in Z."
    },
    "actorRef": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "tenantRef": {
      "type": [
        "string",
        "null"
      ]
    },
    "contractVersions": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "contextReferences": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "reference",
          "classification"
        ],
        "properties": {
          "reference": {
            "type": "string"
          },
          "hash": {
            "type": [
              "string",
              "null"
            ]
          },
          "classification": {
            "type": "string",
            "enum": [
              "public",
              "internal",
              "confidential",
              "restricted"
            ]
          },
          "rawStored": {
            "type": "boolean"
          }
        }
      }
    },
    "modelRoute": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "routeRef",
        "deploymentVersion",
        "instructionVersionRef"
      ],
      "properties": {
        "routeRef": {
          "type": "string"
        },
        "modelVersion": {
          "type": [
            "string",
            "null"
          ]
        },
        "deploymentVersion": {
          "type": "string"
        },
        "instructionVersionRef": {
          "type": "string"
        }
      }
    },
    "toolInvocations": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "toolRef",
          "startedUtc",
          "outcome"
        ],
        "properties": {
          "toolRef": {
            "type": "string"
          },
          "startedUtc": {
            "type": "string",
            "format": "date-time",
            "pattern": "Z$",
            "description": "UTC ISO 8601 timestamp ending in Z."
          },
          "completedUtc": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time",
                "pattern": "Z$",
                "description": "UTC ISO 8601 timestamp ending in Z."
              },
              {
                "type": "null"
              }
            ]
          },
          "inputReference": {
            "type": [
              "string",
              "null"
            ]
          },
          "resultReference": {
            "type": [
              "string",
              "null"
            ]
          },
          "outcome": {
            "enum": [
              "succeeded",
              "failed",
              "denied",
              "timed-out",
              "unknown"
            ]
          },
          "idempotencyKey": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "approvalDecisions": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "policyDecisions": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "sideEffects": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "failures": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "retries": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "recoverySteps": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "evaluationResults": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "finalOutputReference": {
      "type": [
        "string",
        "null"
      ]
    },
    "redaction": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "applied",
        "rules",
        "omittedFields"
      ],
      "properties": {
        "applied": {
          "type": "boolean"
        },
        "rules": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "omittedFields": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "retentionPolicy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "policyId",
        "expiresUtc"
      ],
      "properties": {
        "policyId": {
          "type": "string"
        },
        "expiresUtc": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time",
              "pattern": "Z$",
              "description": "UTC ISO 8601 timestamp ending in Z."
            },
            {
              "type": "null"
            }
          ]
        },
        "legalHold": {
          "type": "boolean"
        }
      }
    }
  }
}
