{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Experiment Configuration Schema",
  "description": "Schema for validating step-based experiment configurations",
  "type": "object",
  "required": ["experiment"],
  "properties": {
    "experiment": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "name": {
          "type": "string",
          "description": "The name of the experiment"
        },
        "description": {
          "type": "string",
          "description": "A description of the experiment"
        }
      }
    },
    "components": {
      "type": "object",
      "description": "Component definitions and configurations",
      "properties": {
        "llm": {
          "type": "object",
          "required": ["default"],
          "properties": {
            "default": {
              "type": "string",
              "description": "The default LLM component to use"
            }
          },
          "additionalProperties": {
            "type": "object",
            "description": "Configuration for a specific LLM component"
          }
        },
        "task": {
          "type": "object",
          "required": ["default"],
          "properties": {
            "default": {
              "type": "string",
              "description": "The default task component to use"
            }
          },
          "additionalProperties": {
            "type": "object",
            "description": "Configuration for a specific task component"
          }
        },
        "prompt_optimiser": {
          "type": "object",
          "required": ["default"],
          "properties": {
            "default": {
              "type": "string",
              "description": "The default prompt optimiser component to use"
            }
          },
          "additionalProperties": {
            "type": "object",
            "description": "Configuration for a specific prompt optimiser component"
          }
        },
        "evaluator": {
          "type": "object",
          "required": ["default"],
          "properties": {
            "default": {
              "type": "string",
              "description": "The default evaluator component to use"
            }
          },
          "additionalProperties": {
            "type": "object",
            "description": "Configuration for a specific evaluator component"
          }
        },
        "embeddings": {
          "type": "object",
          "required": ["default"],
          "properties": {
            "default": {
              "type": "string",
              "description": "The default embeddings component to use"
            }
          },
          "additionalProperties": {
            "type": "object",
            "description": "Configuration for a specific embeddings component"
          }
        }
      },
      "additionalProperties": {
        "type": "object",
        "description": "Configuration for additional component types"
      }
    },
    "steps": {
      "type": "array",
      "description": "Array of experiment steps to execute",
      "items": {
        "type": "object",
        "required": ["name", "type"],
        "properties": {
          "name": {
            "type": "string",
            "description": "Unique name for this step"
          },
          "type": {
            "type": "string",
            "enum": ["component", "function", "custom"],
            "description": "Type of step: component (uses registry), function (built-in), or custom"
          },
          "component_type": {
            "type": "string",
            "description": "Type of component (required for component steps)"
          },
          "component_name": {
            "type": "string",
            "description": "Name of component to instantiate (supports variable interpolation)"
          },
          "function": {
            "type": "string",
            "description": "Name of function to execute (required for function steps)"
          },
          "module": {
            "type": "string",
            "description": "Module path for custom steps"
          },
          "class": {
            "type": "string",
            "description": "Class name for custom steps"
          },
          "depends_on": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "List of step names this step depends on"
          },
          "optional": {
            "type": "boolean",
            "default": false,
            "description": "Whether this step is optional (can fail without stopping experiment)"
          },
          "config": {
            "type": "object",
            "description": "Additional configuration for this step"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "type": {
                  "const": "component"
                }
              }
            },
            "then": {
              "required": ["component_type", "component_name"]
            }
          },
          {
            "if": {
              "properties": {
                "type": {
                  "const": "function"
                }
              }
            },
            "then": {
              "required": ["function"]
            }
          },
          {
            "if": {
              "properties": {
                "type": {
                  "const": "custom"
                }
              }
            },
            "then": {
              "required": ["module", "class"]
            }
          }
        ]
      }
    },
    "paths": {
      "type": "object",
      "description": "Path configurations",
      "additionalProperties": {
        "type": "string",
        "description": "Path to a directory or file"
      }
    },
    "output": {
      "type": "object",
      "description": "Output file paths",
      "additionalProperties": {
        "type": "string",
        "description": "Path to an output file"
      }
    },
    "llm": {
      "type": "object",
      "description": "Legacy LLM configuration (for backward compatibility)",
      "required": ["default"],
      "properties": {
        "default": {
          "type": "string",
          "description": "The default LLM to use"
        }
      },
      "additionalProperties": {
        "type": "object",
        "description": "Configuration for a specific LLM"
      }
    },
    "task": {
      "type": "object",
      "description": "Legacy task configuration (for backward compatibility)",
      "required": ["default"],
      "properties": {
        "default": {
          "type": "string",
          "description": "The default task to use"
        }
      },
      "additionalProperties": {
        "type": "object",
        "description": "Configuration for a specific task"
      }
    },
    "prompt_optimiser": {
      "type": "object",
      "description": "Legacy prompt optimiser configuration (for backward compatibility)",
      "required": ["default"],
      "properties": {
        "default": {
          "type": "string",
          "description": "The default prompt optimiser to use"
        }
      },
      "additionalProperties": {
        "type": "object",
        "description": "Configuration for a specific prompt optimiser"
      }
    }
  }
}