Home/
Part XIII — Expert Mode: Systems, Agents, and Automation/40. Advanced Structured Output/40.1 Deep schemas: nested objects and arrays
40.1 Deep schemas: nested objects and arrays
Overview and links for this section of the guide.
On this page
The Depth Limit
Models struggle with JSON nested deeper than 3-4 levels. They lose track of which closing brace `}` matches which opening brace `{`.
Handling Recursion
If you need to represent a File System Tree (infinite depth), do not ask for one recursive JSON object.
Flatten the structure:
[
{ "id": 1, "parent_id": null, "name": "root" },
{ "id": 2, "parent_id": 1, "name": "src" },
{ "id": 3, "parent_id": 2, "name": "index.ts" }
]
This "Adjacency List" format is much easier for the model to generate reliably than a deeply nested tree.