{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opengastronomy.org/schema/v0.2/benchmark-task.schema.json",
  "title": "OGS Benchmark Task",
  "description": "A single evaluation task for the OGS Benchmark. See spec/ogs-bench.md and spec/ogs-i18n.md.",
  "type": "object",
  "required": ["id", "ogs_version", "benchmark_version", "category", "capability", "difficulty", "prompt", "expected", "scoring"],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^ogs:[a-z0-9-]+:benchmark-task:[a-z0-9-]+$"
    },
    "ogs_version": {
      "type": "string",
      "pattern": "^0\\.(1|2)\\.\\d+$"
    },
    "benchmark_version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$"
    },
    "name": { "$ref": "#/$defs/lstring" },
    "description": { "$ref": "#/$defs/lstring" },
    "primary_language": { "$ref": "#/$defs/bcp47_tag" },
    "available_languages": {
      "type": "array",
      "items": { "$ref": "#/$defs/bcp47_tag" }
    },
    "category": {
      "type": "string",
      "enum": [
        "vocabulary", "sensory", "composition", "pairing",
        "explanation", "risk", "structured_output", "regional",
        "dietary", "safety", "nutrition", "menu_engineering"
      ]
    },
    "capability": { "type": "string", "minLength": 1 },
    "difficulty": {
      "type": "string",
      "enum": ["easy", "medium", "hard", "expert"]
    },
    "prompt": {
      "type": "object",
      "required": ["instruction", "input"],
      "properties": {
        "instruction": { "$ref": "#/$defs/lstring" },
        "input": { "type": "object", "additionalProperties": true },
        "answer_format": { "type": "string" },
        "response_schema": {
          "oneOf": [
            { "type": "null" },
            { "type": "object", "additionalProperties": true }
          ]
        }
      },
      "additionalProperties": false
    },
    "expected": {
      "type": "object",
      "additionalProperties": true
    },
    "scoring": {
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "exact_match",
            "numeric_mae",
            "numeric_rmse",
            "numeric_vector_mae",
            "set_f1",
            "ranked_selection",
            "json_match",
            "schema_validation",
            "rubric_judge"
          ]
        },
        "tolerance": { "type": "number", "minimum": 0 },
        "case_sensitive": { "type": "boolean" },
        "weight": { "type": "number", "minimum": 0 }
      },
      "additionalProperties": true
    },
    "rationale": { "$ref": "#/$defs/lstring" },
    "context_needs": {
      "type": "array",
      "items": { "type": "string" }
    },
    "cuisine_region": { "type": "string" },
    "lang": {
      "$ref": "#/$defs/bcp47_tag",
      "description": "Deprecated alias for primary_language. Kept for v0.1 tasks. BCP 47."
    },
    "tags": {
      "type": "array",
      "items": { "type": "string" }
    },
    "authors": {
      "type": "array",
      "items": { "type": "string" }
    },
    "reviewers": {
      "type": "array",
      "items": { "type": "string" }
    },
    "license": { "type": "string" },
    "disputed": { "type": "boolean" },
    "references": {
      "type": "array",
      "items": { "type": "string" }
    },
    "metadata": {
      "type": "object",
      "properties": {
        "created": { "type": "string" },
        "updated": { "type": "string" },
        "source": { "type": "string" },
        "license": { "type": "string" }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true,
  "$defs": {
    "bcp47_tag": {
      "type": "string",
      "pattern": "^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$"
    },
    "lstring": {
      "oneOf": [
        { "type": "string", "minLength": 1 },
        {
          "type": "object",
          "minProperties": 1,
          "patternProperties": {
            "^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$": { "type": "string", "minLength": 1 }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["labels"],
          "properties": {
            "primary_language": { "$ref": "#/$defs/bcp47_tag" },
            "labels": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "required": ["value", "language"],
                "properties": {
                  "value": { "type": "string", "minLength": 1 },
                  "language": { "$ref": "#/$defs/bcp47_tag" },
                  "script": { "type": "string", "pattern": "^[A-Z][a-z]{3}$" },
                  "role": {
                    "type": "string",
                    "enum": ["preferred", "alternate", "transliteration", "descriptive", "loan", "historical", "deprecated", "ipa"]
                  },
                  "transliteration_scheme": { "type": "string" },
                  "translation": { "type": "object", "additionalProperties": true }
                },
                "additionalProperties": false
              }
            }
          },
          "additionalProperties": false
        }
      ]
    }
  }
}
