{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/latitude-so/json-schema/latitude-so-annotation-schema.json",
  "title": "Annotation",
  "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/Annotation",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "minLength": 24,
      "maxLength": 24,
      "description": "Stable annotation identifier."
    },
    "organizationId": {
      "type": "string",
      "minLength": 24,
      "maxLength": 24,
      "description": "Organization that owns this annotation."
    },
    "projectId": {
      "type": "string",
      "minLength": 24,
      "maxLength": 24,
      "description": "Project this annotation lives in."
    },
    "sessionId": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 128,
      "description": "Session id lifted from the annotated trace. `null` when the trace has no session."
    },
    "traceId": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 32,
      "maxLength": 32,
      "description": "Identifier of the annotated trace."
    },
    "spanId": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 16,
      "maxLength": 16,
      "description": "Span the annotation pins to. Defaults to the trace's last LLM-completion span."
    },
    "simulationId": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 24,
      "maxLength": 24,
      "description": "Simulation reference, if any."
    },
    "signalId": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 24,
      "maxLength": 24,
      "description": "Signal this annotation contributes to, if any."
    },
    "value": {
      "type": "number",
      "minimum": 0,
      "maximum": 1,
      "description": "Normalized score value in [0, 1]. Higher = better."
    },
    "passed": {
      "type": "boolean",
      "description": "Whether the annotation marks the output as passing."
    },
    "feedback": {
      "type": "string",
      "description": "Free-text feedback explaining the score."
    },
    "error": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1,
      "description": "Generation error text, when the annotation itself errored. `null` for successful annotations."
    },
    "errored": {
      "type": "boolean",
      "description": "`true` when the annotation could not be generated successfully."
    },
    "duration": {
      "type": "integer",
      "minimum": 0,
      "description": "Generation duration in nanoseconds. `0` for human annotations."
    },
    "tokens": {
      "type": "integer",
      "minimum": 0,
      "description": "Total LLM tokens consumed generating the score. `0` for human annotations."
    },
    "cost": {
      "type": "integer",
      "minimum": 0,
      "description": "Total LLM cost in microcents (100,000,000 per USD). `0` for human annotations."
    },
    "draftedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "ISO-8601 timestamp at which the annotation was drafted. `null` for published annotations."
    },
    "annotatorId": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 24,
      "maxLength": 24,
      "description": "User who authored the annotation. `null` when not attributed to a user."
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO-8601 timestamp at which the annotation was created."
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO-8601 timestamp of the last metadata update."
    },
    "source": {
      "type": "string",
      "enum": [
        "annotation"
      ],
      "description": "Always `\"annotation\"` for this shape."
    },
    "sourceId": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "UI",
            "API",
            "SYSTEM"
          ]
        },
        {
          "type": "string",
          "minLength": 24,
          "maxLength": 24
        }
      ],
      "description": "Origin marker. Sentinel `\"UI\"` / `\"API\"` / `\"SYSTEM\"` for drafts and automation, or a CUID for authored rows."
    },
    "metadata": {
      "$ref": "#/$defs/AnnotationMetadata"
    }
  },
  "required": [
    "id",
    "organizationId",
    "projectId",
    "sessionId",
    "traceId",
    "spanId",
    "simulationId",
    "signalId",
    "value",
    "passed",
    "feedback",
    "error",
    "errored",
    "duration",
    "tokens",
    "cost",
    "draftedAt",
    "annotatorId",
    "createdAt",
    "updatedAt",
    "source",
    "sourceId",
    "metadata"
  ],
  "$defs": {
    "AnnotationMetadata": {
      "type": "object",
      "properties": {
        "rawFeedback": {
          "type": "string",
          "description": "Original feedback text as written by the annotator, before any server-side enrichment."
        },
        "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."
        }
      },
      "required": [
        "rawFeedback"
      ],
      "description": "Annotation-specific metadata: `rawFeedback` plus a snapshot of the anchor at write time."
    }
  }
}