{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://chris-page-gov.github.io/okf-uk-legislation/whole-law/schemas/model-enrichment-run-v2.schema.json",
  "title": "OKF optional direct-API model-enrichment run v2",
  "description": "Optional future direct-API profile contract, activated only by a new explicit user decision and not required for the current Codex/no-direct-API release. Fail-closed final receipt for a paid, independently reviewed and content-addressed model-enrichment run.",
  "type": "object",
  "required": [
    "schema",
    "run_id",
    "provider",
    "endpoint",
    "authority",
    "input",
    "governance",
    "roles",
    "counts",
    "usage",
    "cost",
    "artifacts",
    "review_status"
  ],
  "properties": {
    "schema": {
      "const": "okf-model-enrichment-run.v2"
    },
    "run_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "provider": {
      "const": "OpenAI"
    },
    "endpoint": {
      "type": "string",
      "pattern": "^https://api\\.openai\\.com/"
    },
    "authority": {
      "const": "derived-non-official"
    },
    "input": {
      "$ref": "#/$defs/input"
    },
    "governance": {
      "$ref": "#/$defs/governance"
    },
    "roles": {
      "$ref": "#/$defs/roles"
    },
    "counts": {
      "$ref": "#/$defs/counts"
    },
    "usage": {
      "$ref": "#/$defs/usage"
    },
    "cost": {
      "$ref": "#/$defs/cost"
    },
    "artifacts": {
      "$ref": "#/$defs/artifacts"
    },
    "review_status": {
      "const": "independently-accepted"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "material": {
      "type": "object",
      "required": [
        "path",
        "sha256"
      ],
      "properties": {
        "path": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "sha256": {
          "$ref": "#/$defs/sha256"
        }
      },
      "additionalProperties": false
    },
    "input": {
      "type": "object",
      "required": [
        "snapshot_id",
        "manifest_sha256",
        "semantic_root_sha256",
        "ordered_identity_sha256",
        "ordered_input_projection_sha256",
        "eligible_records"
      ],
      "properties": {
        "snapshot_id": {
          "type": "string",
          "minLength": 1
        },
        "manifest_sha256": {
          "$ref": "#/$defs/sha256"
        },
        "semantic_root_sha256": {
          "$ref": "#/$defs/sha256"
        },
        "ordered_identity_sha256": {
          "$ref": "#/$defs/sha256"
        },
        "ordered_input_projection_sha256": {
          "$ref": "#/$defs/sha256"
        },
        "eligible_records": {
          "type": "integer",
          "minimum": 1
        }
      },
      "additionalProperties": false
    },
    "governance": {
      "type": "object",
      "required": [
        "policy",
        "calibration_manifest",
        "pricing_snapshot",
        "candidate_schema",
        "review_schema",
        "batch_plan_schema",
        "model_capabilities_schema",
        "calibration_result_schema",
        "execution_authorization_schema",
        "external_attestation_schema",
        "transition_statement_schema",
        "run_schema",
        "pricing_snapshot_schema",
        "selection_receipt_schema",
        "attempt_schema",
        "attempt_ledger_schema",
        "cache_entry_schema",
        "cache_manifest_schema",
        "cost_cap_receipt_schema",
        "independent_audit_schema",
        "terminal_outcome_schema",
        "terminal_evidence_schema",
        "terminal_outcome_manifest_schema",
        "relationship_assertion_schema",
        "acceptance_proof_schema",
        "deterministic_results_schema",
        "accepted_assertion_manifest_schema"
      ],
      "properties": {
        "policy": {
          "$ref": "#/$defs/material"
        },
        "calibration_manifest": {
          "$ref": "#/$defs/material"
        },
        "pricing_snapshot": {
          "$ref": "#/$defs/material"
        },
        "candidate_schema": {
          "$ref": "#/$defs/material"
        },
      "review_schema": {
        "$ref": "#/$defs/material"
      },
        "batch_plan_schema": {
          "$ref": "#/$defs/material"
        },
        "model_capabilities_schema": {
          "$ref": "#/$defs/material"
        },
        "calibration_result_schema": {
          "$ref": "#/$defs/material"
        },
        "execution_authorization_schema": {
          "$ref": "#/$defs/material"
        },
        "external_attestation_schema": {
          "$ref": "#/$defs/material"
        },
        "transition_statement_schema": {
          "$ref": "#/$defs/material"
        },
        "run_schema": {
          "$ref": "#/$defs/material"
        },
        "pricing_snapshot_schema": {
          "$ref": "#/$defs/material"
        },
        "selection_receipt_schema": {
          "$ref": "#/$defs/material"
        },
        "attempt_schema": {
          "$ref": "#/$defs/material"
        },
        "attempt_ledger_schema": {
          "$ref": "#/$defs/material"
        },
        "cache_entry_schema": {
          "$ref": "#/$defs/material"
        },
        "cache_manifest_schema": {
          "$ref": "#/$defs/material"
        },
        "cost_cap_receipt_schema": {
          "$ref": "#/$defs/material"
        },
        "independent_audit_schema": {
          "$ref": "#/$defs/material"
        },
        "terminal_outcome_schema": {
          "$ref": "#/$defs/material"
        },
        "terminal_evidence_schema": {
          "$ref": "#/$defs/material"
        },
        "terminal_outcome_manifest_schema": {
          "$ref": "#/$defs/material"
        },
        "relationship_assertion_schema": {
          "$ref": "#/$defs/material"
        },
        "acceptance_proof_schema": {
          "$ref": "#/$defs/material"
        },
        "deterministic_results_schema": {
          "$ref": "#/$defs/material"
        },
        "accepted_assertion_manifest_schema": {
          "$ref": "#/$defs/material"
        }
      },
      "additionalProperties": false
    },
    "role": {
      "type": "object",
      "required": [
        "requested_model",
        "returned_model",
        "prompt_sha256",
        "response_schema_sha256",
        "parameters_sha256"
      ],
      "properties": {
        "requested_model": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "returned_model": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "prompt_sha256": {
          "$ref": "#/$defs/sha256"
        },
        "response_schema_sha256": {
          "$ref": "#/$defs/sha256"
        },
        "parameters_sha256": {
          "$ref": "#/$defs/sha256"
        }
      },
      "additionalProperties": false
    },
    "roles": {
      "type": "object",
      "required": [
        "generator",
        "reviewer",
        "strongest"
      ],
      "properties": {
        "generator": {
          "$ref": "#/$defs/role"
        },
        "reviewer": {
          "$ref": "#/$defs/role"
        },
        "strongest": {
          "$ref": "#/$defs/role"
        }
      },
      "additionalProperties": false
    },
    "counts": {
      "type": "object",
      "required": [
        "eligible_records",
        "terminal_record_outcomes",
        "records_with_candidates",
        "records_without_candidates",
        "accepted_assertions",
        "review_rejections",
        "escalations"
      ],
      "properties": {
        "eligible_records": {
          "type": "integer",
          "minimum": 1
        },
        "terminal_record_outcomes": {
          "type": "integer",
          "minimum": 1
        },
        "records_with_candidates": {
          "type": "integer",
          "minimum": 0
        },
        "records_without_candidates": {
          "type": "integer",
          "minimum": 0
        },
        "accepted_assertions": {
          "type": "integer",
          "minimum": 0
        },
        "review_rejections": {
          "type": "integer",
          "minimum": 0
        },
        "escalations": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "usage": {
      "type": "object",
      "required": [
        "api_calls",
        "cache_hits",
        "input_tokens",
        "cached_input_tokens",
        "output_tokens",
        "retries"
      ],
      "properties": {
        "api_calls": {
          "type": "integer",
          "minimum": 1
        },
        "cache_hits": {
          "type": "integer",
          "minimum": 0
        },
        "input_tokens": {
          "type": "integer",
          "minimum": 0
        },
        "cached_input_tokens": {
          "type": "integer",
          "minimum": 0
        },
        "output_tokens": {
          "type": "integer",
          "minimum": 0
        },
        "retries": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "cost": {
      "type": "object",
      "required": [
        "cap_usd",
        "preflight_projected_usd",
        "actual_usd",
        "actual_gbp",
        "cost_per_accepted_assertion_usd",
        "pricing_snapshot_sha256",
        "fx",
        "cap_exceeded"
      ],
      "properties": {
        "cap_usd": {
          "const": 250
        },
        "preflight_projected_usd": {
          "type": "number",
          "minimum": 0,
          "maximum": 250
        },
        "actual_usd": {
          "type": "number",
          "minimum": 0,
          "maximum": 250
        },
        "actual_gbp": {
          "type": "number",
          "minimum": 0
        },
        "cost_per_accepted_assertion_usd": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "pricing_snapshot_sha256": {
          "$ref": "#/$defs/sha256"
        },
        "fx": {
          "$ref": "#/$defs/fx"
        },
        "cap_exceeded": {
          "const": false
        }
      },
      "additionalProperties": false
    },
    "fx": {
      "type": "object",
      "required": [
        "source",
        "date",
        "rate",
        "direction"
      ],
      "properties": {
        "source": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "date": {
          "type": "string",
          "format": "date"
        },
        "rate": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "direction": {
          "enum": [
            "GBP-per-USD",
            "USD-per-GBP"
          ]
        }
      },
      "additionalProperties": false
    },
    "artifacts": {
      "type": "object",
      "required": [
        "selection_receipt",
        "execution_authorization_receipt",
        "attempt_ledger",
        "cache_manifest",
        "cost_cap_receipt",
        "independent_audit",
        "accepted_assertion_manifest",
        "terminal_outcome_manifest"
      ],
      "properties": {
        "selection_receipt": {
          "$ref": "#/$defs/material"
        },
        "execution_authorization_receipt": {
          "$ref": "#/$defs/material"
        },
        "attempt_ledger": {
          "$ref": "#/$defs/material"
        },
        "cache_manifest": {
          "$ref": "#/$defs/material"
        },
        "cost_cap_receipt": {
          "$ref": "#/$defs/material"
        },
        "independent_audit": {
          "$ref": "#/$defs/material"
        },
        "accepted_assertion_manifest": {
          "$ref": "#/$defs/material"
        },
        "terminal_outcome_manifest": {
          "$ref": "#/$defs/material"
        }
      },
      "additionalProperties": false
    }
  }
}
