{"record":{"id":"3a4089dcd019e2f4","repo":"ComposioHQ/composio","slug":"json-schema-node-depth-exceeded-cap-max-node-dep","errorCode":null,"errorMessage":"JSON Schema node depth exceeded cap ({MAX_NODE_DEPTH})","messagePattern":"JSON Schema node depth exceeded cap \\((.+?)\\)","errorType":"exception","errorClass":"JSONSchemaRefResolutionError","httpStatus":null,"severity":"error","filePath":"python/composio/utils/json_schema.py","lineNumber":170,"sourceCode":"    root = t.cast(t.Dict[str, t.Any], schema)\n    # Identity-based cycle guard for the *current* walk path. Python doesn't\n    # suffer JS-style prototype pollution, so unlike the TS port there's no\n    # need to filter ``__proto__``/``constructor`` keys while cloning.\n    visiting: t.Set[int] = set()\n\n    # ``walk`` uses explicit loops (not comprehensions) so each level of schema\n    # nesting costs exactly one Python stack frame. That keeps ``MAX_NODE_DEPTH``\n    # the binding limit under the interpreter's default recursion ceiling, so a\n    # pathologically deep schema fails with our typed error rather than a bare\n    # ``RecursionError`` (which is also caught at the call site as a backstop).\n    def walk(\n        node: t.Any,\n        visited_refs: t.FrozenSet[str],\n        chain_depth: int,\n        node_depth: int,\n    ) -> t.Any:\n        if node_depth >= MAX_NODE_DEPTH:\n            raise JSONSchemaRefResolutionError(\n                f\"JSON Schema node depth exceeded cap ({MAX_NODE_DEPTH})\"\n            )\n\n        if isinstance(node, list):\n            node_id = id(node)\n            if node_id in visiting:\n                return _cycle_break_sentinel()\n            visiting.add(node_id)\n            try:\n                cloned_list: t.List[t.Any] = []\n                for item in node:\n                    cloned_list.append(\n                        walk(item, visited_refs, chain_depth, node_depth + 1)\n                    )\n                return cloned_list\n            finally:\n                visiting.discard(node_id)\n","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/python/composio/utils/json_schema.py#L152-L188","documentation":"dereference_json_schema refuses to walk schemas whose object nesting exceeds MAX_NODE_DEPTH (512). This cap exists so pathological schemas (cyclic data or billion-laughs-style expansion) raise a clean error instead of exhausting Python's recursion limit.","triggerScenarios":"Passing a schema with more than 512 levels of nested properties/items/anyOf containers, or a self-referential structure that expands without $ref cycle protection, to dereference_json_schema or any wrapper (substitute_file_uploads, alias_tool_input_schema).","commonSituations":"Machine-generated schemas from recursive models (tree types without $ref indirection); malicious or corrupted schema payloads; accidental self-nesting when a schema is built programmatically.","solutions":["Inspect the schema's actual depth and collapse unnecessary nesting","Convert deeply repeated inline structures into $defs + $ref so the walker dedupes","Truncate or reject the input schema before calling the SDK if it comes from an untrusted source","Report it if a legitimate Composio tool schema trips the cap"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def schema_depth(n):\n    if isinstance(n, dict): return 1 + max((schema_depth(v) for v in n.values()), default=0)\n    if isinstance(n, list): return 1 + max((schema_depth(v) for v in n), default=0)\n    return 0\nassert schema_depth(schema) < 512","typeGuard":null,"tryCatchPattern":"from composio.exceptions import JSONSchemaRefResolutionError\ntry:\n    out = dereference_json_schema(schema)\nexcept JSONSchemaRefResolutionError:\n    schema = simplify(schema)  # collapse inline duplication into $defs/$ref\n    out = dereference_json_schema(schema)","preventionTips":["Use $defs + $ref instead of inlining repeated nested structures","Cap generation depth when building schemas programmatically"],"tags":["json-schema","depth-limit","python"],"backgroundTag":"schema-nesting-too-deep","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}