Output schema max_depth: 10 levels, and $defs recursion is free

Sume's output_schema allows 10 levels of literal nesting. Past that you get max_depth. A self-referencing $defs entry does not add to the depth count.

3 min readSume
All posts

A Format output_schema that nests objects more than 10 levels deep is rejected with 400 output_schema_invalid and the rule max_depth. Flatten the shape, or move the inner objects into root $defs and reference them. The depth limit counts literal nesting in the document, and a self-referential $defs entry does not increase it (Structured output).

What counts as a level

Each properties or items step inside the document is a level. A $ref is not followed when Sume counts. That is why a tree such as a comment thread can be written with one definition that refers to itself.

{
  "type": "object",
  "additionalProperties": false,
  "required": ["outline"],
  "properties": { "outline": { "$ref": "#/$defs/node" } },
  "$defs": {
    "node": {
      "type": "object",
      "additionalProperties": false,
      "required": ["title", "children"],
      "properties": {
        "title": { "type": "string" },
        "children": { "type": "array", "items": { "$ref": "#/$defs/node" } }
      }
    }
  }
}

Rules that still apply

If a human can not read your schema at 10 levels, the model will fill it worse. Prefer a flat list of items with a parent_id string over a deep tree when the consumer is a spreadsheet or a database.

  • $defs must sit at the root of the schema. A nested $defs block gives unsupported_ref.
  • $ref: "#" is rejected. Recurse through a named definition instead.
  • Every definition object also needs additionalProperties: false and a full required list.

Sources

Related posts

More in Formats

All Formats posts

Written by Sume