{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://externalcontrollayer.ai/data/control-gap-record.schema.json",
  "title": "Control Gap Record",
  "type": "object",
  "required": [
    "name",
    "version",
    "released",
    "license",
    "codebook",
    "entries"
  ],
  "properties": {
    "name": {
      "type": "string"
    },
    "version": {
      "type": "string"
    },
    "released": {
      "type": "string",
      "format": "date"
    },
    "license": {
      "type": "string"
    },
    "citation": {
      "type": "string"
    },
    "codebook": {
      "type": "object",
      "required": [
        "version",
        "codes"
      ],
      "properties": {
        "version": {
          "type": "string"
        },
        "codes": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "group",
              "label",
              "definition"
            ],
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^G[0-9]+$"
              },
              "group": {
                "type": "string"
              },
              "label": {
                "type": "string"
              },
              "definition": {
                "type": "string"
              },
              "code_when": {
                "type": "string"
              },
              "do_not_code_when": {
                "type": "string"
              },
              "properties": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "clauses": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "entries": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/entry"
      }
    }
  },
  "$defs": {
    "entry": {
      "type": "object",
      "required": [
        "entry",
        "key",
        "title",
        "date",
        "system_type",
        "sector",
        "precedent",
        "trigger",
        "outcome",
        "codes",
        "evidence",
        "confidence",
        "sources"
      ],
      "properties": {
        "entry": {
          "type": "integer",
          "minimum": 1,
          "description": "Permanent entry number."
        },
        "key": {
          "type": "string",
          "pattern": "^[a-z0-9-]+$",
          "description": "Permanent text identifier."
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "title": {
          "type": "string"
        },
        "short_name": {
          "type": "string"
        },
        "date": {
          "type": "string",
          "format": "date",
          "description": "Date of the harmful action, or the start of the period the sources document."
        },
        "when": {
          "type": "string"
        },
        "organization": {
          "type": "string"
        },
        "system": {
          "type": "string"
        },
        "system_type": {
          "enum": [
            "agent",
            "chat",
            "generative",
            "perception",
            "predictive",
            "automation"
          ]
        },
        "sector": {
          "enum": [
            "software",
            "consumer",
            "transport",
            "government",
            "health",
            "finance",
            "justice",
            "media"
          ]
        },
        "precedent": {
          "type": "boolean",
          "description": "True for conventional automation included as a precedent."
        },
        "action": {
          "type": "string"
        },
        "trigger": {
          "enum": [
            "model",
            "input",
            "change",
            "fault",
            "design"
          ]
        },
        "outcome": {
          "enum": [
            "harm",
            "near-miss",
            "hazard"
          ]
        },
        "harm_types": {
          "type": "array",
          "items": {
            "enum": [
              "injury",
              "money",
              "data",
              "rights",
              "statement"
            ]
          }
        },
        "codes": {
          "type": "array",
          "items": {
            "enum": [
              "G1",
              "G2",
              "G3",
              "G4",
              "G5",
              "G6",
              "G7",
              "G8",
              "G9",
              "G10",
              "G11",
              "G12",
              "G13"
            ]
          }
        },
        "evidence": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "code",
              "evidence",
              "basis",
              "sources"
            ],
            "properties": {
              "code": {
                "enum": [
                  "G1",
                  "G2",
                  "G3",
                  "G4",
                  "G5",
                  "G6",
                  "G7",
                  "G8",
                  "G9",
                  "G10",
                  "G11",
                  "G12",
                  "G13"
                ]
              },
              "evidence": {
                "type": "string"
              },
              "basis": {
                "enum": [
                  "finding",
                  "admission",
                  "allegation",
                  "firsthand",
                  "reporting"
                ]
              },
              "sources": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "pinpoint": {
                "type": "string"
              }
            }
          }
        },
        "not_coded": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "code": {
                "enum": [
                  "G1",
                  "G2",
                  "G3",
                  "G4",
                  "G5",
                  "G6",
                  "G7",
                  "G8",
                  "G9",
                  "G10",
                  "G11",
                  "G12",
                  "G13"
                ]
              },
              "reason": {
                "type": "string"
              }
            }
          }
        },
        "confidence": {
          "enum": [
            "high",
            "medium",
            "low"
          ]
        },
        "sources": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "title",
              "url",
              "type"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "publisher": {
                "type": "string"
              },
              "date": {
                "type": "string"
              },
              "url": {
                "type": "string",
                "format": "uri"
              },
              "type": {
                "enum": [
                  "official",
                  "court",
                  "filing",
                  "company",
                  "firsthand",
                  "press",
                  "research",
                  "commentary"
                ]
              },
              "note": {
                "type": "string"
              }
            }
          }
        },
        "aiid_incident": {
          "type": [
            "integer",
            "null"
          ]
        },
        "analysis_url": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  }
}
