{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.opengpt.com/evaluations/opengpt-evidence-schema-v2.json",
  "title": "OpenGPT Local Evaluation Evidence v2",
  "description": "Strict schema for locally produced, auditable OpenGPT evaluation evidence with at most 10,000 runs per package.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "protocol_version",
    "is_demo",
    "model_id",
    "provider",
    "evaluated_at",
    "suite_sha256",
    "runs"
  ],
  "properties": {
    "protocol_version": {
      "const": "opengpt-evidence-v2"
    },
    "is_demo": {
      "type": "boolean"
    },
    "disclaimer": {
      "type": "string",
      "maxLength": 200
    },
    "model_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160
    },
    "provider": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80
    },
    "evaluated_at": {
      "type": "string",
      "format": "date-time"
    },
    "suite_sha256": {
      "$ref": "#/$defs/sha256"
    },
    "runs": {
      "type": "array",
      "minItems": 1,
      "maxItems": 10000,
      "items": {
        "$ref": "#/$defs/run"
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "is_demo": {
            "const": true
          }
        },
        "required": [
          "is_demo"
        ]
      },
      "then": {
        "required": [
          "disclaimer"
        ],
        "properties": {
          "disclaimer": {
            "const": "DEMO ONLY — this file is synthetic and is not a real model evaluation."
          }
        }
      },
      "else": {
        "not": {
          "required": [
            "disclaimer"
          ]
        }
      }
    }
  ],
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "nullableSha256": {
      "oneOf": [
        {
          "$ref": "#/$defs/sha256"
        },
        {
          "type": "null"
        }
      ]
    },
    "run": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "case_id",
        "status",
        "score",
        "latency_ms",
        "output_sha256"
      ],
      "properties": {
        "case_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
        },
        "status": {
          "enum": [
            "completed",
            "failed",
            "skipped"
          ]
        },
        "score": {
          "oneOf": [
            {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "latency_ms": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": 0
            },
            {
              "type": "null"
            }
          ]
        },
        "output_sha256": {
          "$ref": "#/$defs/nullableSha256"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "completed"
              }
            },
            "required": [
              "status"
            ]
          },
          "then": {
            "properties": {
              "score": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "latency_ms": {
                "type": "integer",
                "minimum": 0
              },
              "output_sha256": {
                "$ref": "#/$defs/sha256"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "status": {
                "const": "failed"
              }
            },
            "required": [
              "status"
            ]
          },
          "then": {
            "properties": {
              "score": {
                "type": "null"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "status": {
                "const": "skipped"
              }
            },
            "required": [
              "status"
            ]
          },
          "then": {
            "properties": {
              "score": {
                "type": "null"
              },
              "latency_ms": {
                "type": "null"
              },
              "output_sha256": {
                "type": "null"
              }
            }
          }
        }
      ]
    }
  }
}
