{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/welkaim/ea-codex/schemas/v1/edge-evaluation-prompt.json",
  "title": "EdgeEvaluationPrompt",
  "description": "An LLM-evaluated transition condition between governance states. Used at edges in a graph where deterministic Rego rules cannot decide alone. Introduced in Chapter 5 for SAP transition gates and reused in Chapter 13 for sovereignty-edge evaluation. Uses the standard metadata + spec envelope.",
  "type": "object",
  "required": ["apiVersion", "kind", "metadata", "spec"],
  "properties": {
    "apiVersion": { "$ref": "_common.json#/$defs/apiVersion" },
    "kind": { "type": "string", "const": "EdgeEvaluationPrompt" },
    "metadata": {
      "type": "object",
      "required": ["name", "edge"],
      "properties": {
        "id": { "$ref": "_common.json#/$defs/identifier" },
        "name": { "$ref": "_common.json#/$defs/slug" },
        "edge": {
          "type": "string",
          "description": "Symbolic edge in the governance graph, in the form 'SourceState -> TargetState'."
        },
        "version": { "$ref": "_common.json#/$defs/version" },
        "status": { "$ref": "_common.json#/$defs/lifecycleStatus" },
        "owners": { "$ref": "_common.json#/$defs/owners" }
      },
      "additionalProperties": true
    },
    "spec": {
      "type": "object",
      "required": ["systemContext", "contextDocuments", "evaluationCriteria", "expectedOutput"],
      "properties": {
        "systemContext": {
          "type": "string",
          "description": "Role and scope statement passed to the LLM evaluator.",
          "minLength": 20
        },
        "contextDocuments": {
          "type": "array",
          "description": "Typed documents that the LLM consumes as input.",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["type", "source"],
            "properties": {
              "type": { "type": "string" },
              "source": { "type": "string" },
              "role": { "type": "string" }
            },
            "additionalProperties": true
          }
        },
        "evaluationCriteria": {
          "type": "array",
          "description": "Plain-language criteria the LLM must check.",
          "minItems": 1,
          "items": { "type": "string" }
        },
        "expectedOutput": {
          "type": "object",
          "required": ["type", "schema"],
          "properties": {
            "type": { "type": "string", "enum": ["JSON", "YAML"] },
            "schema": {
              "description": "Structured schema for the LLM output. Often a small JSON Schema fragment or a plain object describing the expected fields."
            }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": false
}
