{"record":{"id":"bbc6fd7fde4ea301","repo":"ComposioHQ/composio","slug":"tool-schema-nesting-exceeded-the-maximum-supported","errorCode":null,"errorMessage":"Tool schema nesting exceeded the maximum supported depth (${MAX_SCHEMA_DEPTH})","messagePattern":"Tool schema nesting exceeded the maximum supported depth \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ts/packages/core/src/utils/schemaPropertyKeys.ts","lineNumber":219,"sourceCode":" * Recursively sanitizes the property keys of a JSON-schema node, returning the\n * rewritten node and a {@link KeyMapping} shaped like the node. Traversal covers\n * object `properties`, array `items`/`prefixItems`, the composition keywords\n * (`allOf`/`anyOf`/`oneOf`, `not`/`if`/`then`/`else` — whose renames merge into\n * this level), and the rewrite-only positions in {@link REWRITE_ONLY_SINGLE_KEYWORDS}\n * / {@link REWRITE_ONLY_MAP_KEYWORDS}.\n *\n * The input node is never mutated; a new node is returned.\n */\nfunction sanitizeNode(\n  node: Record<string, unknown>,\n  policy: KeySanitizationPolicy,\n  depth = 0\n): {\n  node: Record<string, unknown>;\n  mapping: KeyMapping;\n} {\n  if (depth >= MAX_SCHEMA_DEPTH) {\n    throw new Error(\n      `Tool schema nesting exceeded the maximum supported depth (${MAX_SCHEMA_DEPTH})`\n    );\n  }\n\n  const result: Record<string, unknown> = { ...node };\n  // Lookup/result tables are prototype-free so a property key that collides with\n  // an `Object.prototype` member (`__proto__`, `constructor`, `toString`, …)\n  // becomes a plain own entry instead of resolving to (or reparenting via) the\n  // inherited member. Mirrors the `POLLUTING_KEYS` defense in `jsonSchema.ts`.\n  const renames: Record<string, string> = Object.create(null);\n  const children: Record<string, KeyMapping> = Object.create(null);\n  const mapping: KeyMapping = { renames, children };\n\n  const properties = node.properties;\n  if (isPlainObject(properties)) {\n    const newProperties: Record<string, unknown> = Object.create(null);\n    const renamedOriginalToSanitized: Record<string, string> = Object.create(null);\n","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/ts/packages/core/src/utils/schemaPropertyKeys.ts#L201-L237","documentation":"The SDK renames tool-schema property keys that collide with dangerous prototypes, and recursively sanitizes the schema with a hard depth cap (MAX_SCHEMA_DEPTH). sanitizeNode throws when the tool's JSON schema nests deeper than that cap, protecting against cyclic or pathological schemas.","triggerScenarios":"Registering or executing a tool whose parameter JSON schema (nested objects/arrays/allOf etc.) exceeds MAX_SCHEMA_DEPTH — often a schema with an accidental self-referencing $ref-like cycle, or a generated schema with extremely deep nesting.","commonSituations":"Auto-generated OpenAPI/JSON schemas with recursive models expanded inline; deeply nested config types from codegen; a tool definition accidentally embedding itself.","solutions":["Inspect the failing tool's schema and flatten or remove unnecessary nesting","If the schema is recursive, express it with $defs/$ref instead of inline expansion so the physical nesting is shallow","Reduce nesting in the tool's parameter type definition before registering the tool","Report the tool/schema to Composio if it's a built-in integration tool you can't modify"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const schemaDepth = (s: object, d = 0): number =>\n  d > 20 ? d : Math.max(d, ...Object.values(s)\n    .filter(v => v && typeof v === 'object')\n    .map(v => schemaDepth(v as object, d + 1)));\nif (schemaDepth(toolSchema) >= MAX_SCHEMA_DEPTH) throw new Error('schema too deep');","typeGuard":"null","tryCatchPattern":"try {\n  await composio.tools.execute(action, args);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('nesting exceeded the maximum supported depth')) {\n    // flatten or fix the tool schema\n  }\n}","preventionTips":["Keep tool parameter types shallow; avoid deeply nested one-ofs","Express recursion with $ref/$defs, not inline expansion","Add a depth lint for generated OpenAPI schemas before registering tools"],"tags":["json-schema","tool-schema","depth-limit","validation"],"backgroundTag":"schema-nesting-too-deep","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}