{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/latitude-so/main/json-schema/latitude-so-create-signal-body-schema.json",
  "title": "CreateSignalBody",
  "x-generated": "2026-10-18",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/latitude-so-openapi.json#/components/schemas/CreateSignalBody",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "Human-readable name. Used to derive the slug."
    },
    "description": {
      "type": "string",
      "minLength": 1,
      "description": "What this signal captures."
    },
    "priority": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "low",
        "medium",
        "high",
        "urgent",
        null
      ],
      "description": "Manual triage priority. Null/omitted leaves it unset."
    },
    "filters": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": {
        "type": "array",
        "items": {
          "$ref": "#/$defs/FilterCondition"
        }
      },
      "description": "Row-local pre-gate restricting which traces the evaluation runs against. Omitted = all traces."
    },
    "evaluation": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "settings": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "enum": [
                        "judge"
                      ]
                    },
                    "criteria": {
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "required": [
                    "kind",
                    "criteria"
                  ]
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "enum": [
                        "rule"
                      ]
                    },
                    "match": {
                      "type": "string",
                      "enum": [
                        "all",
                        "any"
                      ],
                      "default": "all"
                    },
                    "conditions": {
                      "type": "array",
                      "items": {
                        "oneOf": [
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "text_match"
                                ]
                              },
                              "scope": {
                                "type": "string",
                                "enum": [
                                  "last_assistant",
                                  "any_assistant",
                                  "any_user",
                                  "any_tool",
                                  "conversation"
                                ],
                                "default": "last_assistant"
                              },
                              "operator": {
                                "type": "string",
                                "enum": [
                                  "contains",
                                  "not_contains",
                                  "matches_regex",
                                  "not_matches_regex"
                                ]
                              },
                              "value": {
                                "type": "string",
                                "minLength": 1
                              },
                              "caseSensitive": {
                                "type": "boolean",
                                "default": false
                              }
                            },
                            "required": [
                              "type",
                              "operator",
                              "value"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "empty_output"
                                ]
                              }
                            },
                            "required": [
                              "type"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "output_length"
                                ]
                              },
                              "unit": {
                                "type": "string",
                                "enum": [
                                  "chars",
                                  "words"
                                ],
                                "default": "chars"
                              },
                              "operator": {
                                "type": "string",
                                "enum": [
                                  "gt",
                                  "gte",
                                  "lt",
                                  "lte"
                                ]
                              },
                              "value": {
                                "type": "integer",
                                "minimum": 0
                              }
                            },
                            "required": [
                              "type",
                              "operator",
                              "value"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "json_output"
                                ]
                              },
                              "expectation": {
                                "type": "string",
                                "enum": [
                                  "valid",
                                  "invalid"
                                ]
                              }
                            },
                            "required": [
                              "type",
                              "expectation"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "metric"
                                ]
                              },
                              "field": {
                                "type": "string",
                                "enum": [
                                  "duration",
                                  "cost",
                                  "tokensTotal",
                                  "tokensInput",
                                  "tokensOutput",
                                  "errorCount",
                                  "traceCount",
                                  "spanCount"
                                ]
                              },
                              "aggregation": {
                                "type": "string",
                                "enum": [
                                  "session",
                                  "anyTrace",
                                  "allTraces"
                                ],
                                "default": "session"
                              },
                              "operator": {
                                "type": "string",
                                "enum": [
                                  "gt",
                                  "gte",
                                  "lt",
                                  "lte"
                                ]
                              },
                              "value": {
                                "type": "number",
                                "minimum": 0
                              }
                            },
                            "required": [
                              "type",
                              "field",
                              "operator",
                              "value"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "tool_used"
                                ]
                              },
                              "toolName": {
                                "type": "string",
                                "minLength": 1
                              }
                            },
                            "required": [
                              "type",
                              "toolName"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "tool_failed"
                                ]
                              },
                              "toolName": {
                                "type": "string",
                                "minLength": 1
                              }
                            },
                            "required": [
                              "type"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "tool_call_count"
                                ]
                              },
                              "operator": {
                                "type": "string",
                                "enum": [
                                  "gt",
                                  "gte",
                                  "lt",
                                  "lte"
                                ]
                              },
                              "value": {
                                "type": "integer",
                                "minimum": 0
                              }
                            },
                            "required": [
                              "type",
                              "operator",
                              "value"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "error"
                                ]
                              }
                            },
                            "required": [
                              "type"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "finish_reason"
                                ]
                              },
                              "value": {
                                "type": "string",
                                "minLength": 1
                              }
                            },
                            "required": [
                              "type",
                              "value"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "semantic_similarity"
                                ]
                              },
                              "query": {
                                "type": "string",
                                "minLength": 1
                              },
                              "operator": {
                                "type": "string",
                                "enum": [
                                  "gt",
                                  "gte",
                                  "lt",
                                  "lte"
                                ],
                                "default": "gte"
                              },
                              "threshold": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 1
                              }
                            },
                            "required": [
                              "type",
                              "query",
                              "threshold"
                            ]
                          },
                          {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "enum": [
                                  "always"
                                ]
                              }
                            },
                            "required": [
                              "type"
                            ]
                          }
                        ]
                      },
                      "minItems": 1,
                      "maxItems": 25
                    }
                  },
                  "required": [
                    "kind",
                    "conditions"
                  ]
                }
              ],
              "description": "Declarative detector config. `judge` compiles to an LLM script; `rule` compiles to a deterministic script over the session."
            }
          },
          "required": [
            "settings"
          ]
        },
        {
          "type": "object",
          "properties": {
            "script": {
              "type": "string",
              "minLength": 1,
              "description": "Raw sandbox evaluation script (advanced). Must compile in the QuickJS runtime."
            }
          },
          "required": [
            "script"
          ]
        }
      ],
      "description": "The signal's membership detector. Provide exactly one of `settings` or `script`."
    }
  },
  "required": [
    "name",
    "description",
    "evaluation"
  ],
  "$defs": {
    "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"
      ]
    }
  }
}