{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://complyedge.io/rulebook/0.1.0/decision-record.schema.json",
  "title": "ADCR decision record 0.1.0",
  "description": "One AI Decision Check Record: the structural part of classes Record, Law, Chain, Oversight and Rights of the ADCR rulebook 0.1.0. SPEC.md governs; rules that span records (references, dual verification, rule id reuse, the chain) and the number form of REC-01 are checked by the verifier, not by this schema. Licensed Apache-2.0.",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "rulebook",
    "record_version",
    "record_id",
    "occurred_at",
    "event_type",
    "account_id",
    "producer_id",
    "deploying_party",
    "retention"
  ],
  "properties": {
    "rulebook": {
      "type": "string",
      "const": "https://complyedge.io/rulebook/0.1.0"
    },
    "record_version": {
      "type": "string",
      "minLength": 1
    },
    "record_id": {
      "type": "string",
      "minLength": 1
    },
    "occurred_at": {
      "$ref": "#/$defs/timestamp"
    },
    "detected_at": {
      "$ref": "#/$defs/timestamp"
    },
    "event_type": {
      "type": "string",
      "minLength": 1,
      "$comment": "REC-05: the eleven values below are defined; a producer may register others, and a reader treats an unknown value as decision.",
      "examples": [
        "decision",
        "oversight",
        "contest",
        "notice",
        "fallback",
        "logging_failure",
        "opt_out",
        "incident",
        "classification",
        "oversight_evaluation",
        "legal_hold"
      ]
    },
    "account_id": {
      "type": "string",
      "minLength": 1
    },
    "producer_id": {
      "type": "string",
      "minLength": 1
    },
    "deploying_party": {
      "type": "string",
      "minLength": 1
    },
    "providing_party": {
      "type": "string"
    },
    "deciding_system": {
      "type": "object",
      "required": [
        "id",
        "version"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "config_digest": {
          "$ref": "#/$defs/sha256hex"
        }
      }
    },
    "checker": {
      "type": "object",
      "required": [
        "id",
        "version"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "version": {
          "type": "string"
        },
        "path": {
          "type": "string"
        }
      }
    },
    "user": {
      "$ref": "#/$defs/pseudonym"
    },
    "user_role": {
      "type": "string"
    },
    "session": {
      "$ref": "#/$defs/pseudonym"
    },
    "subject": {
      "$ref": "#/$defs/pseudonym"
    },
    "subject_is_employee": {
      "type": "boolean"
    },
    "works_agreement_ref": {
      "type": "string"
    },
    "commitments": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/commitment"
      }
    },
    "correlation_id": {
      "type": "string"
    },
    "data_categories": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "special_category": {
      "type": "boolean"
    },
    "art4a_basis_ref": {
      "type": "string"
    },
    "verdict": {
      "type": "string",
      "enum": [
        "allow",
        "deny",
        "modify",
        "ask",
        "defer"
      ]
    },
    "action": {
      "type": "string",
      "enum": [
        "passed",
        "blocked",
        "flagged",
        "modified",
        "escalated"
      ]
    },
    "native_result": {
      "type": "string"
    },
    "rules_fired": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/rule_ref"
      }
    },
    "rule_set": {
      "$ref": "#/$defs/rule_set"
    },
    "caller_asserted_provision": {
      "$ref": "#/$defs/provision"
    },
    "reason_codes": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:/-]*$"
      }
    },
    "confidence": {
      "type": "string",
      "pattern": "^(0(\\.[0-9]+)?|1(\\.0+)?)$",
      "$comment": "REC-01, REC-16: a decimal string in [0, 1], never a JSON number"
    },
    "exemptions": {
      "type": "object",
      "required": [
        "claimed",
        "rejected"
      ],
      "properties": {
        "claimed": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/exemption"
          }
        },
        "rejected": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/exemption_rejected"
          }
        }
      }
    },
    "fallback": {
      "type": "object",
      "required": [
        "kind",
        "reason_code"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "skipped",
            "degraded",
            "fallback_engine",
            "timeout"
          ]
        },
        "reason_code": {
          "type": "string"
        }
      }
    },
    "retention": {
      "type": "object",
      "required": [
        "class",
        "erase_after"
      ],
      "properties": {
        "class": {
          "type": "string",
          "minLength": 1
        },
        "erase_after": {
          "$ref": "#/$defs/timestamp"
        }
      },
      "not": {
        "required": [
          "legal_hold"
        ],
        "$comment": "REC-19: a legal hold is its own legal_hold record, never a field on the record it covers"
      }
    },
    "legal_basis": {
      "type": "object",
      "required": [
        "provision"
      ],
      "properties": {
        "provision": {
          "$ref": "#/$defs/provision"
        },
        "art22_exception": {
          "type": "string",
          "enum": [
            "22(2)(a)",
            "22(2)(b)",
            "22(2)(c)"
          ]
        }
      }
    },
    "purpose_ref": {
      "type": "string"
    },
    "annex_iii_point": {
      "type": "string"
    },
    "chain": {
      "type": "object",
      "required": [
        "seq",
        "prev",
        "hash",
        "alg"
      ],
      "properties": {
        "seq": {
          "type": "integer",
          "minimum": 1
        },
        "prev": {
          "type": "string",
          "pattern": "^([0-9a-f]{64})?$"
        },
        "hash": {
          "$ref": "#/$defs/sha256hex"
        },
        "alg": {
          "type": "string",
          "const": "sha256-chain-1"
        }
      }
    },
    "chain_status": {
      "type": "string",
      "enum": [
        "chained",
        "pre_chain"
      ]
    },
    "proposal_ref": {
      "type": "string"
    },
    "oversight_action": {
      "type": "string",
      "enum": [
        "accepted",
        "disregarded",
        "overridden",
        "reversed",
        "not_used",
        "intervened",
        "stopped",
        "verified"
      ]
    },
    "reviewer": {
      "$ref": "#/$defs/pseudonym"
    },
    "reviewer_role": {
      "type": "string"
    },
    "authority_ref": {
      "type": "string"
    },
    "review_opened_at": {
      "$ref": "#/$defs/timestamp"
    },
    "inputs_ref": {
      "type": "string"
    },
    "reason_code": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:/-]*$"
    },
    "outcome_ref": {
      "type": "string"
    },
    "decision_mode": {
      "type": "string",
      "enum": [
        "solely_automated",
        "decisive",
        "advisory",
        "human"
      ]
    },
    "human_decider": {
      "type": "object",
      "required": [
        "pseudonym",
        "role",
        "authority_ref"
      ],
      "properties": {
        "pseudonym": {
          "$ref": "#/$defs/pseudonym"
        },
        "role": {
          "type": "string"
        },
        "authority_ref": {
          "type": "string"
        }
      }
    },
    "notice": {
      "type": "object",
      "required": [
        "given"
      ],
      "properties": {
        "given": {
          "type": "boolean"
        },
        "given_at": {
          "$ref": "#/$defs/timestamp"
        },
        "notice_ref": {
          "type": "string"
        },
        "workers_informed_at": {
          "$ref": "#/$defs/timestamp"
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "given"
            ],
            "properties": {
              "given": {
                "const": true
              }
            }
          },
          "then": {
            "required": [
              "given_at",
              "notice_ref"
            ]
          }
        }
      ]
    },
    "notice_kind": {
      "type": "string",
      "enum": [
        "use_of_ai",
        "rights",
        "explanation",
        "statement_of_reasons",
        "rejection"
      ]
    },
    "decision_ref": {
      "type": "string"
    },
    "channel_ref": {
      "type": "string"
    },
    "language": {
      "type": "string"
    },
    "issued_at": {
      "$ref": "#/$defs/timestamp"
    },
    "statement_ref": {
      "type": "string"
    },
    "request_kind": {
      "type": "string",
      "enum": [
        "human_intervention",
        "express_view",
        "explanation",
        "contest",
        "review"
      ]
    },
    "requested_at": {
      "$ref": "#/$defs/timestamp"
    },
    "responded_at": {
      "$ref": "#/$defs/timestamp"
    },
    "review_outcome": {
      "type": "string",
      "enum": [
        "upheld",
        "rectified",
        "withdrawn"
      ]
    },
    "rectified_at": {
      "$ref": "#/$defs/timestamp"
    },
    "explanation_inputs": {
      "type": "object",
      "required": [
        "logic_ref",
        "procedure_ref",
        "main_factors",
        "data_categories",
        "risks_ref",
        "main_elements"
      ],
      "properties": {
        "logic_ref": {
          "type": "string"
        },
        "procedure_ref": {
          "type": "string"
        },
        "main_factors": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "code",
              "importance"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "importance": {
                "type": "string",
                "enum": [
                  "high",
                  "medium",
                  "low"
                ]
              }
            },
            "additionalProperties": false
          }
        },
        "data_categories": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "risks_ref": {
          "type": "string"
        },
        "main_elements": {
          "type": "object",
          "required": [
            "outcome_code",
            "effect_code",
            "effective_date"
          ],
          "properties": {
            "outcome_code": {
              "type": "string"
            },
            "effect_code": {
              "type": "string"
            },
            "effective_date": {
              "type": "string"
            }
          }
        },
        "sensitivity": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "code",
              "direction",
              "change_bucket"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "direction": {
                "type": "string",
                "enum": [
                  "up",
                  "down",
                  "either"
                ]
              },
              "change_bucket": {
                "type": "string",
                "enum": [
                  "small",
                  "moderate",
                  "large",
                  "none"
                ]
              }
            }
          }
        }
      }
    },
    "withheld": {
      "type": "boolean"
    },
    "escrow_ref": {
      "type": "string"
    },
    "incident_kind": {
      "type": "string",
      "enum": [
        "risk",
        "substantial_modification",
        "serious_incident",
        "suspension"
      ]
    },
    "reported_at": {
      "$ref": "#/$defs/timestamp"
    },
    "report_ref": {
      "type": "string"
    },
    "period": {
      "type": "object",
      "required": [
        "from",
        "to"
      ],
      "properties": {
        "from": {
          "$ref": "#/$defs/timestamp"
        },
        "to": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "action_counts": {
      "type": "object",
      "propertyNames": {
        "enum": [
          "accepted",
          "disregarded",
          "overridden",
          "reversed",
          "not_used",
          "intervened",
          "stopped",
          "verified"
        ]
      },
      "additionalProperties": {
        "type": "integer",
        "minimum": 0
      }
    },
    "evaluator_role": {
      "type": "string"
    },
    "representatives_informed": {
      "type": "boolean"
    },
    "failure_kind": {
      "type": "string",
      "enum": [
        "write_failed",
        "chain_failed",
        "anchor_failed"
      ]
    },
    "classification_result": {
      "type": "string",
      "enum": [
        "high_risk",
        "not_high_risk"
      ]
    },
    "assessment_ref": {
      "type": "string",
      "minLength": 1
    },
    "identification_ref": {
      "type": "string",
      "minLength": 1
    },
    "reviewer_counts": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "reviewer",
          "action_counts"
        ],
        "properties": {
          "reviewer": {
            "$ref": "#/$defs/pseudonym"
          },
          "action_counts": {
            "type": "object",
            "additionalProperties": {
              "type": "integer",
              "minimum": 0
            }
          }
        }
      },
      "$comment": "OVS-05: only in an export whose envelope export_purpose is oversight_evaluation"
    },
    "hold": {
      "$ref": "#/$defs/hold"
    }
  },
  "allOf": [
    {
      "$comment": "REC-05: any event_type outside the ten others is read as decision.",
      "if": {
        "required": [
          "event_type"
        ],
        "properties": {
          "event_type": {
            "enum": [
              "oversight",
              "contest",
              "notice",
              "fallback",
              "logging_failure",
              "opt_out",
              "incident",
              "classification",
              "oversight_evaluation",
              "legal_hold"
            ]
          }
        }
      },
      "then": true,
      "else": {
        "allOf": [
          {
            "required": [
              "verdict",
              "action",
              "rules_fired",
              "rule_set",
              "exemptions",
              "commitments",
              "data_categories",
              "purpose_ref"
            ]
          },
          {
            "properties": {
              "verdict": {
                "enum": [
                  "allow",
                  "deny",
                  "modify",
                  "ask",
                  "defer"
                ]
              },
              "action": {
                "enum": [
                  "passed",
                  "blocked",
                  "flagged",
                  "modified",
                  "escalated"
                ]
              }
            }
          },
          {
            "$comment": "OVS-02: the human action is its own record",
            "not": {
              "anyOf": [
                {
                  "required": [
                    "proposal_ref"
                  ]
                },
                {
                  "required": [
                    "oversight_action"
                  ]
                },
                {
                  "required": [
                    "reviewer"
                  ]
                },
                {
                  "required": [
                    "review_opened_at"
                  ]
                },
                {
                  "required": [
                    "outcome_ref"
                  ]
                }
              ]
            }
          },
          {
            "$comment": "REC-08: a decision about a natural person",
            "if": {
              "required": [
                "subject"
              ]
            },
            "then": {
              "required": [
                "legal_basis",
                "decision_mode",
                "notice",
                "explanation_inputs"
              ]
            }
          },
          {
            "$comment": "OVS-04",
            "if": {
              "required": [
                "decision_mode"
              ],
              "properties": {
                "decision_mode": {
                  "const": "human"
                }
              }
            },
            "then": {
              "required": [
                "human_decider"
              ]
            }
          },
          {
            "$comment": "RGT-05",
            "if": {
              "required": [
                "withheld"
              ],
              "properties": {
                "withheld": {
                  "const": true
                }
              }
            },
            "then": {
              "required": [
                "escrow_ref"
              ]
            }
          },
          {
            "$comment": "RGT-02, AI Act Art 26(7)",
            "if": {
              "required": [
                "subject_is_employee",
                "notice"
              ],
              "properties": {
                "subject_is_employee": {
                  "const": true
                }
              }
            },
            "then": {
              "properties": {
                "notice": {
                  "required": [
                    "workers_informed_at"
                  ]
                }
              }
            }
          }
        ]
      }
    },
    {
      "if": {
        "required": [
          "event_type"
        ],
        "properties": {
          "event_type": {
            "const": "oversight"
          }
        }
      },
      "then": {
        "allOf": [
          {
            "required": [
              "proposal_ref",
              "oversight_action",
              "reviewer",
              "reviewer_role",
              "authority_ref",
              "review_opened_at",
              "inputs_ref",
              "reason_code"
            ]
          },
          {
            "if": {
              "properties": {
                "oversight_action": {
                  "enum": [
                    "overridden",
                    "reversed"
                  ]
                }
              }
            },
            "then": {
              "required": [
                "outcome_ref"
              ]
            }
          }
        ]
      }
    },
    {
      "if": {
        "required": [
          "event_type"
        ],
        "properties": {
          "event_type": {
            "const": "contest"
          }
        }
      },
      "then": {
        "allOf": [
          {
            "required": [
              "decision_ref",
              "request_kind",
              "requested_at"
            ]
          },
          {
            "if": {
              "required": [
                "review_outcome"
              ]
            },
            "then": {
              "required": [
                "responded_at",
                "reviewer",
                "statement_ref"
              ]
            }
          },
          {
            "if": {
              "required": [
                "review_outcome"
              ],
              "properties": {
                "review_outcome": {
                  "const": "rectified"
                }
              }
            },
            "then": {
              "required": [
                "rectified_at"
              ]
            }
          }
        ]
      }
    },
    {
      "if": {
        "required": [
          "event_type"
        ],
        "properties": {
          "event_type": {
            "const": "notice"
          }
        }
      },
      "then": {
        "required": [
          "notice_kind",
          "decision_ref",
          "channel_ref",
          "language",
          "issued_at",
          "statement_ref"
        ]
      }
    },
    {
      "if": {
        "required": [
          "event_type"
        ],
        "properties": {
          "event_type": {
            "const": "fallback"
          }
        }
      },
      "then": {
        "required": [
          "fallback"
        ]
      }
    },
    {
      "if": {
        "required": [
          "event_type"
        ],
        "properties": {
          "event_type": {
            "const": "logging_failure"
          }
        }
      },
      "then": {
        "required": [
          "failure_kind",
          "detected_at"
        ]
      }
    },
    {
      "if": {
        "required": [
          "event_type"
        ],
        "properties": {
          "event_type": {
            "const": "incident"
          }
        }
      },
      "then": {
        "required": [
          "incident_kind",
          "detected_at",
          "reported_at",
          "report_ref"
        ]
      }
    },
    {
      "if": {
        "required": [
          "event_type"
        ],
        "properties": {
          "event_type": {
            "const": "classification"
          }
        }
      },
      "then": {
        "required": [
          "classification_result",
          "assessment_ref"
        ]
      }
    },
    {
      "if": {
        "required": [
          "event_type"
        ],
        "properties": {
          "event_type": {
            "const": "oversight_evaluation"
          }
        }
      },
      "then": {
        "required": [
          "period",
          "action_counts",
          "evaluator_role",
          "representatives_informed"
        ]
      }
    },
    {
      "$comment": "REC-19",
      "if": {
        "required": [
          "event_type"
        ],
        "properties": {
          "event_type": {
            "const": "legal_hold"
          }
        }
      },
      "then": {
        "required": [
          "hold"
        ]
      }
    },
    {
      "$comment": "CHN-01 and EXP-02: every record carries chain, except a record written before the chain existed, which is labelled chain_status pre_chain instead.",
      "if": {
        "required": [
          "chain_status"
        ],
        "properties": {
          "chain_status": {
            "const": "pre_chain"
          }
        }
      },
      "then": {
        "not": {
          "required": [
            "chain"
          ]
        }
      },
      "else": {
        "required": [
          "chain"
        ]
      }
    },
    {
      "$comment": "REC-07: every record names its deciding system except records about the account chain",
      "if": {
        "anyOf": [
          {
            "required": [
              "event_type"
            ],
            "properties": {
              "event_type": {
                "const": "legal_hold"
              }
            }
          },
          {
            "required": [
              "event_type",
              "failure_kind"
            ],
            "properties": {
              "event_type": {
                "const": "logging_failure"
              },
              "failure_kind": {
                "enum": [
                  "anchor_failed",
                  "chain_failed"
                ]
              }
            }
          }
        ]
      },
      "then": true,
      "else": {
        "required": [
          "deciding_system"
        ]
      }
    }
  ],
  "$defs": {
    "timestamp": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{3,9})?Z$"
    },
    "sha256hex": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "pseudonym": {
      "type": "object",
      "required": [
        "value",
        "key_version"
      ],
      "properties": {
        "value": {
          "type": "string",
          "pattern": "^p1:[0-9a-f]{32}$"
        },
        "key_version": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "commitment": {
      "type": "object",
      "required": [
        "alg",
        "value",
        "key_version",
        "direction"
      ],
      "properties": {
        "alg": {
          "type": "string",
          "const": "hmac-sha256-1"
        },
        "value": {
          "$ref": "#/$defs/sha256hex"
        },
        "key_version": {
          "type": "integer",
          "minimum": 1
        },
        "direction": {
          "type": "string",
          "enum": [
            "input",
            "output",
            "action"
          ]
        },
        "source_ref": {
          "type": "string",
          "maxLength": 255,
          "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:\\S+$",
          "$comment": "REC-12: a locator, a URI with no whitespace"
        }
      }
    },
    "provision": {
      "type": "object",
      "required": [
        "label"
      ],
      "anyOf": [
        {
          "required": [
            "eli"
          ]
        },
        {
          "required": [
            "url"
          ]
        }
      ],
      "properties": {
        "eli": {
          "type": "string",
          "pattern": "^http://data\\.europa\\.eu/eli/(reg|reg_del|reg_impl|dir|dir_del|dir_impl|dec|dec_del|dec_impl)/[0-9]{4}/[0-9]+(/art_[0-9a-z]+)?(/par_[0-9a-z]+)?(/pnt_[0-9a-z]+)?(/anx_[ivxlc]+)?/oj$|^https?://(?!data\\.europa\\.eu/)[^ ]+/eli/[^ ]+$"
        },
        "consolidated_eli": {
          "type": "string",
          "pattern": "^http://data\\.europa\\.eu/eli/(reg|reg_del|reg_impl|dir|dir_del|dir_impl|dec|dec_del|dec_impl)/[0-9]{4}/[0-9]+/[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "url": {
          "type": "string",
          "pattern": "^https://"
        },
        "label": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "rule_ref": {
      "type": "object",
      "required": [
        "rule_id",
        "rule_version",
        "provision",
        "citation"
      ],
      "properties": {
        "rule_id": {
          "type": "string",
          "minLength": 1
        },
        "rule_version": {
          "type": "string",
          "minLength": 1
        },
        "provision": {
          "$ref": "#/$defs/provision"
        },
        "citation": {
          "type": "string",
          "minLength": 1
        },
        "confidence": {
          "type": "string",
          "pattern": "^(0(\\.[0-9]+)?|1(\\.0+)?)$"
        }
      }
    },
    "rule_set": {
      "type": "object",
      "required": [
        "digest",
        "label",
        "index_url"
      ],
      "properties": {
        "digest": {
          "$ref": "#/$defs/sha256hex"
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "index_url": {
          "type": "string",
          "pattern": "^https://"
        }
      }
    },
    "exemption": {
      "type": "object",
      "required": [
        "name",
        "provision"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "provision": {
          "$ref": "#/$defs/provision"
        },
        "reason_code": {
          "type": "string"
        }
      }
    },
    "exemption_rejected": {
      "allOf": [
        {
          "$ref": "#/$defs/exemption"
        },
        {
          "required": [
            "reason_code"
          ]
        }
      ]
    },
    "hold": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "action",
        "scope"
      ],
      "$comment": "REC-19: a legal hold placed on, or lifted from, a range of the account chain",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "action": {
          "enum": [
            "placed",
            "lifted"
          ]
        },
        "scope": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "from_seq"
          ],
          "properties": {
            "from_seq": {
              "type": "integer",
              "minimum": 1
            },
            "to_seq": {
              "type": "integer",
              "minimum": 1
            }
          }
        },
        "reason_code": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:/-]*$"
        }
      }
    }
  }
}
