{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/latitude-so/json-schema/latitude-so-create-annotation-body-schema.json",
  "title": "CreateAnnotationBody",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/latitude-so-annotations-api-openapi.yml#/components/schemas/CreateAnnotationBody",
  "type": "object",
  "properties": {
    "simulationId": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 24,
      "maxLength": 24,
      "default": null,
      "description": "Simulation this annotation is tied to, if any. `null` (default) when not part of a simulation."
    },
    "signalId": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 24,
      "maxLength": 24,
      "default": null,
      "description": "Pre-selected signal this annotation belongs to. Leave `null` (default) to let the automatic signal-discovery pipeline route the annotation."
    },
    "value": {
      "type": "number",
      "minimum": 0,
      "maximum": 1,
      "description": "Normalized score value in [0, 1]. Higher = better."
    },
    "passed": {
      "type": "boolean",
      "description": "Whether the annotated output passes the reviewer's bar."
    },
    "feedback": {
      "type": "string",
      "minLength": 1,
      "description": "Free-text feedback explaining the score. Surfaced alongside the trace."
    },
    "anchor": {
      "$ref": "#/$defs/AnnotationAnchor"
    },
    "trace": {
      "$ref": "#/$defs/TraceRef"
    }
  },
  "required": [
    "value",
    "passed",
    "feedback",
    "trace"
  ],
  "$defs": {
    "AnnotationAnchor": {
      "type": "object",
      "properties": {
        "messageIndex": {
          "type": "integer",
          "minimum": 0,
          "description": "0-based message index inside the conversation. Omit for conversation-level annotations."
        },
        "partIndex": {
          "type": "integer",
          "minimum": 0,
          "description": "0-based index into the target message's `parts[]`. Requires `messageIndex`."
        },
        "startOffset": {
          "type": "integer",
          "minimum": 0,
          "description": "Inclusive start offset for substring annotations. Must be paired with `endOffset` and `partIndex`."
        },
        "endOffset": {
          "type": "integer",
          "minimum": 0,
          "description": "Exclusive end offset for substring annotations. Must be paired with `startOffset` and `partIndex`, and `>= startOffset`."
        },
        "textFormat": {
          "type": "string",
          "enum": [
            "pretty-json"
          ],
          "description": "UI-side text transform applied before the offsets were captured (e.g. `\"pretty-json\"`). Resolvers must apply the same transform before slicing."
        }
      },
      "description": "Optional anchor pinning the annotation to a specific message / part / offset range inside the trace."
    },
    "FilterCondition": {
      "type": "object",
      "properties": {
        "op": {
          "type": "string",
          "enum": [
            "eq",
            "neq",
            "gt",
            "gte",
            "lt",
            "lte",
            "in",
            "notIn",
            "contains",
            "notContains",
            "gtePercentile"
          ],
          "description": "Comparison operator applied to the field's value (e.g. `eq`, `neq`, `in`). The full operator list lives in the API reference."
        },
        "value": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "number"
            },
            {
              "type": "boolean"
            },
            {
              "type": "array",
              "items": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "number"
                  }
                ]
              }
            }
          ],
          "description": "Right-hand value compared against the field. Arrays are required for `in` / `notIn`-style operators."
        }
      },
      "required": [
        "op",
        "value"
      ]
    },
    "FilterSet": {
      "type": "object",
      "additionalProperties": {
        "type": "array",
        "items": {
          "$ref": "#/$defs/FilterCondition"
        }
      },
      "description": "Filter set keyed by field name. Each entry holds an array of conditions ANDed together for that field; field-level groups are also ANDed across the set."
    },
    "TraceRef": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "by": {
              "type": "string",
              "enum": [
                "id"
              ],
              "description": "Match a single trace by its identifier. Pair with `id`."
            },
            "id": {
              "type": "string",
              "minLength": 32,
              "maxLength": 32,
              "description": "32-character trace identifier."
            }
          },
          "required": [
            "by",
            "id"
          ]
        },
        {
          "type": "object",
          "properties": {
            "by": {
              "type": "string",
              "enum": [
                "filters"
              ],
              "description": "Match a single trace by a filter set. Pair with `filters`; exactly one trace must match."
            },
            "filters": {
              "$ref": "#/$defs/FilterSet"
            }
          },
          "required": [
            "by",
            "filters"
          ]
        }
      ],
      "description": "Target trace. Either an explicit id or a filter set matching exactly one trace."
    }
  }
}