{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/infiniteaudience-ai/json-schema/infiniteaudience-ai-discovery-input-schema.json",
  "title": "DiscoveryInput",
  "description": "One side of a discovery operation — provide exactly one of `filters`, `filter_groups`, `segment_id`, `audience_id`, or `segment_ids` + `set_logic`. Providing more than one returns 400 `AMBIGUOUS_INPUT`; providing none returns 400 `NO_INPUT_SPECIFIED`.\n",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/infiniteaudience-ai-discovery-api-openapi.yml#/components/schemas/DiscoveryInput",
  "type": "object",
  "properties": {
    "filters": {
      "type": "array",
      "description": "Flat filter list.",
      "items": {
        "$ref": "#/$defs/Filter"
      }
    },
    "filter_groups": {
      "type": "array",
      "description": "Compound boolean filter groups.",
      "items": {
        "$ref": "#/$defs/FilterGroup"
      }
    },
    "segment_id": {
      "type": "string",
      "description": "ID of a saved segment."
    },
    "audience_id": {
      "type": "string",
      "description": "ID of a saved audience."
    },
    "segment_ids": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "IDs of multiple segments to combine (requires `set_logic`)."
    },
    "set_logic": {
      "type": "string",
      "enum": [
        "union",
        "intersection"
      ],
      "description": "How to combine segment_ids: union = match ANY segment (OR); intersection = match EVERY segment (AND).\n"
    }
  },
  "$defs": {
    "Filter": {
      "type": "object",
      "description": "A single filter condition for audience discovery or job execution",
      "required": [
        "field",
        "op"
      ],
      "properties": {
        "field": {
          "type": "string",
          "description": "Canonical catalog field_name (e.g. age or state). ZIP5 also accepts zip, zip_code, or postal_code as input aliases; saved responses use zip5."
        },
        "op": {
          "type": "string",
          "enum": [
            "=",
            "!=",
            "<",
            "<=",
            ">",
            ">=",
            "IN",
            "NOT IN",
            "BETWEEN",
            "LIKE",
            "ARRAY_CONTAINS",
            "ARRAY_CONTAINS_ANY",
            "IS NULL",
            "IS NOT NULL"
          ],
          "description": "Comparison operator"
        },
        "text_comparison": {
          "type": "string",
          "enum": [
            "exact",
            "case_insensitive"
          ],
          "description": "Optional STRING comparison mode for =, !=, IN, NOT IN, and LIKE, or ARRAY<STRING> membership mode for ARRAY_CONTAINS and ARRAY_CONTAINS_ANY. Defaults to exact. Case-insensitive mode applies Unicode case folding to both the stored value and the supplied value.\n"
        },
        "trim_whitespace": {
          "type": "boolean",
          "description": "Optionally trim leading and trailing whitespace on both sides of a STRING or ARRAY<STRING> comparison. Defaults to false; independent of text_comparison.\n"
        },
        "value": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "number"
            },
            {
              "type": "boolean"
            },
            {
              "type": "array",
              "items": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "number"
                  }
                ]
              }
            }
          ],
          "description": "The value to match against. For state, a published two-letter code or full State name is accepted and normalized to the code. Scalar types (`string`, `number`, `boolean`) are used for single-value operators (`=`, `!=`, `<`, `<=`, `>`, `>=`, `LIKE`, `ARRAY_CONTAINS`). Pass an **array** for `IN`, `NOT IN`, and `ARRAY_CONTAINS_ANY` — pass the array directly with no comma-encoding. `BETWEEN` takes a two-element array `[low, high]`. Omit entirely for `IS NULL` / `IS NOT NULL` checks.\n"
        }
      }
    },
    "FilterGroup": {
      "type": "object",
      "description": "A group of Filter conditions. All `filters` within a single group are **always ANDed together** — there is no per-group intra-operator. The `combinator` attribute is an **inter-group** operator: it controls how this group is joined to the immediately preceding group in the array. The `combinator` on the first group (index 0) is always ignored.\n\nExample — `(city = \"NYC\" AND state = \"NY\") OR (state = \"CA\")`:\n```json [\n  { \"id\": \"g1\", \"filters\": [{\"field\":\"city\",\"op\":\"=\",\"value\":\"NYC\"},\n                            {\"field\":\"state\",\"op\":\"=\",\"value\":\"NY\"}],\n    \"combinator\": \"AND\" },\n  { \"id\": \"g2\", \"filters\": [{\"field\":\"state\",\"op\":\"=\",\"value\":\"CA\"}],\n    \"combinator\": \"OR\" }\n] ```\nGroup g1's `combinator` is irrelevant (it is the first group). Group g2's `combinator: \"OR\"` means the result is `(g1) OR (g2)`.\n",
      "required": [
        "id",
        "filters",
        "combinator"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Stable identifier (UUID or NanoID). Used to track groups across edits.\n"
        },
        "filters": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Filter"
          },
          "description": "One or more filter conditions. All conditions in this array are combined with AND. Provide at least one filter per group.\n"
        },
        "combinator": {
          "type": "string",
          "enum": [
            "AND",
            "OR"
          ],
          "description": "**Inter-group operator.** Joins this group to the previous group in the array. `AND` narrows the result; `OR` broadens it. Ignored on the first group (index 0) — that group has no predecessor to join.\n"
        }
      }
    }
  }
}