{"record":{"id":"9055249468c39d38","repo":"ComposioHQ/composio","slug":"json-schema-exceeds-maximum-nesting-depth-of-max","errorCode":null,"errorMessage":"JSON Schema exceeds maximum nesting depth of {MAX_NODE_DEPTH}","messagePattern":"JSON Schema exceeds maximum nesting depth of (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/composio/utils/strict_schema.py","lineNumber":189,"sourceCode":"    node_type = node.get(\"type\")\n    if isinstance(node_type, str):\n        return node_type == \"null\"\n    if isinstance(node_type, list):\n        return \"null\" in node_type\n    if isinstance(node.get(\"enum\"), list):\n        return None in node[\"enum\"]\n    if \"const\" in node:\n        return node[\"const\"] is None\n    for keyword in (\"anyOf\", \"oneOf\"):\n        branches = node.get(keyword)\n        if isinstance(branches, list):\n            return any(_schema_accepts_null(b, root) for b in branches)\n    return True\n\n\ndef _dedupe_required(value: t.Any, is_schema: bool = True, depth: int = 0) -> t.Any:\n    if depth > MAX_NODE_DEPTH:\n        raise ValueError(\n            f\"JSON Schema exceeds maximum nesting depth of {MAX_NODE_DEPTH}\"\n        )\n    if isinstance(value, list):\n        return [_dedupe_required(item, is_schema, depth + 1) for item in value]\n    if not isinstance(value, dict):\n        return value\n    clone: dict[str, t.Any] = {}\n    for key, child in value.items():\n        if is_schema and key == \"required\" and isinstance(child, list):\n            clone[key] = list(dict.fromkeys(child))\n        else:\n            clone[key] = _dedupe_required(\n                child, is_schema and key not in INSTANCE_VALUE_KEYWORDS, depth + 1\n            )\n    return clone\n\n\nclass _Walker:","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/python/composio/utils/strict_schema.py#L171-L207","documentation":"to_strict_json_schema's _dedupe_required pass enforces a hard recursion cap (MAX_NODE_DEPTH) on schema node depth. Exceeding it raises ValueError, protecting against pathological or cyclic-ish schemas that would otherwise recurse unboundedly during strict-schema conversion.","triggerScenarios":"Feeding a schema whose nested allOf/properties/items chains exceed the depth limit — deeply recursive definitions, schemas where $ref inlining produced self-nesting, or adversarially deep generated specs.","commonSituations":"Recursive schemas (trees, linked structures) inlined without $refs; a bug duplicating nested levels on each transformation pass; schemas from untrusted/auto-generated sources; accidental self-referential definitions after refactoring.","solutions":["Reduce real nesting by using $ref/$defs instead of fully inlined recursive structures","Check for accidental duplication: a transformation pass that re-wraps the schema each run can multiply depth — diff depth before/after each step","If legitimately deep, split the schema or raise the limit only if you control the constant and accept the risk","Sanitize/truncate untrusted schemas before strict conversion"],"exampleFix":"# before (recursive inline)\n{\"type\": \"object\", \"properties\": {\"child\": {\"type\": \"object\", \"properties\": {\"child\": {...deep...}}}}}\n# after\n{\"$defs\": {\"node\": {\"type\": \"object\", \"properties\": {\"child\": {\"$ref\": \"#/$defs/node\"}}}}, \"$ref\": \"#/$defs/node\"}","handlingStrategy":"validation","validationCode":"def schema_depth(v, d=0):\n    if d > 100: return d\n    if isinstance(v, dict): return max([schema_depth(x, d+1) for x in v.values()], default=d)\n    if isinstance(v, list): return max([schema_depth(x, d+1) for x in v], default=d)\n    return d\nassert schema_depth(schema) < MAX_NODE_DEPTH","typeGuard":null,"tryCatchPattern":"try:\n    strict = to_strict_json_schema(schema)\nexcept ValueError as e:\n    if \"nesting depth\" in str(e):\n        schema = flatten_with_defs(schema)\n        strict = to_strict_json_schema(schema)","preventionTips":["Express recursion with $ref/$defs instead of inlining","Depth-check untrusted schemas before conversion","Watch for transformation passes that re-wrap and deepen schemas each run"],"tags":["json-schema","nesting-depth","strict-schema","recursion"],"backgroundTag":"schema-nesting-depth-exceeded","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}