{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://futurecraft.pro/artifacts/production-llm-release-manifest/manifest.schema.json",
  "title": "Production LLM release manifest",
  "description": "A versioned contract for evaluating, rolling out, and rolling back one LLM-backed task.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "releaseId",
    "createdAt",
    "task",
    "components",
    "dataPolicy",
    "execution",
    "evaluation",
    "rollout",
    "rollback",
    "provenance"
  ],
  "properties": {
    "schemaVersion": {
      "const": "1.0.0"
    },
    "releaseId": {
      "$ref": "#/$defs/releaseId"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "task": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "inputSchema",
        "outputSchema",
        "requiredCapabilities",
        "successMetrics"
      ],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$"
        },
        "inputSchema": {
          "$ref": "#/$defs/immutableRef"
        },
        "outputSchema": {
          "$ref": "#/$defs/immutableRef"
        },
        "requiredCapabilities": {
          "$ref": "#/$defs/nonEmptyUniqueStrings"
        },
        "successMetrics": {
          "$ref": "#/$defs/nonEmptyUniqueStrings"
        }
      }
    },
    "components": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "prompt",
        "policy",
        "router",
        "retrieval",
        "toolset",
        "modelAdapter"
      ],
      "properties": {
        "prompt": {
          "$ref": "#/$defs/immutableRef"
        },
        "policy": {
          "$ref": "#/$defs/immutableRef"
        },
        "router": {
          "$ref": "#/$defs/immutableRef"
        },
        "retrieval": {
          "$ref": "#/$defs/immutableRef"
        },
        "toolset": {
          "$ref": "#/$defs/immutableRef"
        },
        "modelAdapter": {
          "$ref": "#/$defs/immutableRef"
        }
      }
    },
    "dataPolicy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "classification",
        "allowedRegions",
        "retentionDays",
        "redactionPolicy",
        "humanReviewTriggers"
      ],
      "properties": {
        "classification": {
          "type": "string",
          "minLength": 1
        },
        "allowedRegions": {
          "$ref": "#/$defs/nonEmptyUniqueStrings"
        },
        "retentionDays": {
          "type": "integer",
          "minimum": 0
        },
        "redactionPolicy": {
          "$ref": "#/$defs/immutableRef"
        },
        "humanReviewTriggers": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      }
    },
    "execution": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "allowedProviders",
        "allowedTools",
        "maxTotalLatencyMs",
        "maxProviderAttempts",
        "maxToolSteps",
        "retryPolicy"
      ],
      "properties": {
        "allowedProviders": {
          "$ref": "#/$defs/nonEmptyUniqueStrings"
        },
        "allowedTools": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "maxTotalLatencyMs": {
          "type": "integer",
          "minimum": 1
        },
        "maxProviderAttempts": {
          "type": "integer",
          "minimum": 1
        },
        "maxToolSteps": {
          "type": "integer",
          "minimum": 0
        },
        "retryPolicy": {
          "$ref": "#/$defs/immutableRef"
        }
      }
    },
    "evaluation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "dataset",
        "evaluatedAt",
        "baselineReleaseId",
        "thresholds",
        "candidateResults"
      ],
      "properties": {
        "dataset": {
          "$ref": "#/$defs/immutableRef"
        },
        "evaluatedAt": {
          "type": "string",
          "format": "date-time"
        },
        "baselineReleaseId": {
          "$ref": "#/$defs/releaseId"
        },
        "thresholds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/threshold"
          }
        },
        "candidateResults": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": {
            "type": "number"
          }
        }
      }
    },
    "rollout": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "strategy",
        "initialTrafficPercent",
        "guardrails",
        "owner",
        "runbook"
      ],
      "properties": {
        "strategy": {
          "enum": [
            "canary",
            "blue-green",
            "rolling",
            "manual"
          ]
        },
        "initialTrafficPercent": {
          "type": "number",
          "minimum": 0,
          "maximum": 100
        },
        "guardrails": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/threshold"
          }
        },
        "owner": {
          "type": "string",
          "minLength": 1
        },
        "runbook": {
          "$ref": "#/$defs/immutableRef"
        }
      }
    },
    "rollback": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "previousReleaseId",
        "automaticTriggers",
        "procedure",
        "lastTestedAt"
      ],
      "properties": {
        "previousReleaseId": {
          "$ref": "#/$defs/releaseId"
        },
        "automaticTriggers": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/threshold"
          }
        },
        "procedure": {
          "$ref": "#/$defs/immutableRef"
        },
        "lastTestedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sourceCommit",
        "buildId"
      ],
      "properties": {
        "sourceCommit": {
          "type": "string",
          "pattern": "^[a-f0-9]{7,64}$"
        },
        "buildId": {
          "$ref": "#/$defs/immutableRef"
        },
        "changeRecord": {
          "$ref": "#/$defs/immutableRef"
        }
      }
    },
    "notes": {
      "type": "string",
      "maxLength": 2000
    }
  },
  "$defs": {
    "immutableRef": {
      "type": "string",
      "minLength": 3,
      "pattern": "^\\S+$"
    },
    "releaseId": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._-]{2,127}$"
    },
    "nonEmptyUniqueStrings": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "threshold": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "metric",
        "operator",
        "value"
      ],
      "properties": {
        "metric": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9._-]*$"
        },
        "operator": {
          "enum": [
            "<",
            "<=",
            "==",
            ">=",
            ">"
          ]
        },
        "value": {
          "type": "number"
        },
        "slice": {
          "type": "string",
          "minLength": 1
        },
        "window": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}
