ComposioHQ/composio · error · Error

Tool arguments nesting exceeded the maximum supported depth

Error message

Tool arguments nesting exceeded the maximum supported depth (${MAX_SCHEMA_DEPTH})

What it means

The counterpart to sanitizeNode: when tool arguments (the actual call parameters) are restored to their original key names after execution, restoreOriginalKeys recurses with the same MAX_SCHEMA_DEPTH cap and throws when the arguments object nests deeper than allowed. This guards against runaway recursion on adversarial or cyclic inputs.

Source

Thrown at ts/packages/core/src/utils/schemaPropertyKeys.ts:393

 */
export function sanitizeSchemaPropertyKeys<T extends Record<string, unknown>>(
  schema: T,
  policy: KeySanitizationPolicy
): { schema: T; mapping: KeyMapping } {
  const { node, mapping } = sanitizeNode(schema, policy);
  return { schema: node as T, mapping };
}

/**
 * Restores original property names in a tool-call argument object using the
 * mapping produced by {@link sanitizeSchemaPropertyKeys}. The mapping is walked
 * in lockstep with the value, so a key is only renamed at the nesting level where
 * its alias was actually generated. Nested objects and arrays are handled
 * recursively. Returns a new value; the input is not mutated.
 */
export function restoreOriginalKeys(value: unknown, mapping: KeyMapping, depth = 0): unknown {
  if (depth >= MAX_SCHEMA_DEPTH) {
    throw new Error(
      `Tool arguments nesting exceeded the maximum supported depth (${MAX_SCHEMA_DEPTH})`
    );
  }

  if (Array.isArray(value)) {
    const { items, restItems } = mapping;
    if (Array.isArray(items)) {
      return value.map((item, index) => {
        // Elements inside the tuple use their positional mapping; elements past it
        // use the trailing single-`items` rest mapping (2020-12), if any.
        const itemMapping = index < items.length ? items[index] : restItems;
        return itemMapping ? restoreOriginalKeys(item, itemMapping, depth + 1) : item;
      });
    }
    if (items) {
      return value.map(item => restoreOriginalKeys(item, items, depth + 1));
    }
    return value;

View on GitHub (pinned to 64b1b85502)

Solutions

  1. Validate/flatten arguments before invoking the tool so nesting stays within the SDK's cap
  2. Fix the underlying schema (see error 410) — deep arguments usually accompany a deep schema
  3. If arguments are machine-generated, add a depth check on the serialized JSON before sending

Example fix

// before
await composio.tools.execute(actionName, { args: deeplyNestedArgs });

// after
const depth = (v: unknown, d = 0): number =>
  v && typeof v === 'object'
    ? Math.max(...Object.values(v as object).map(x => depth(x, d + 1)), d)
    : d;
if (depth(deeplyNestedArgs) > 10) throw new Error('Arguments too deeply nested');
Defensive patterns

Strategy: validation

Validate before calling

const argDepth = (v: unknown, d = 0): number =>
  v && typeof v === 'object'
    ? Math.max(d, ...Object.values(v as object).map(x => argDepth(x, d + 1)))
    : d;
if (argDepth(args) >= 10) throw new Error('Arguments too deeply nested');

Type guard

null

Try / catch

try {
  await composio.tools.execute(action, args);
} catch (e) {
  if (e instanceof Error && e.message.includes('Tool arguments nesting exceeded')) {
    // flatten arguments and retry
  }
}

Prevention

When it happens

Trigger: Calling executeToolCall (or restoreOriginalKeys directly) with arguments whose object/array nesting depth exceeds MAX_SCHEMA_DEPTH — typically arguments crafted for a schema that itself hit error 410, or hand-built cyclic argument objects.

Common situations: Passing deeply/cyclically nested arguments from an LLM that hallucinated structure; arguments generated from a recursive type; a mismatch between a very deep schema and its serialized arguments.

Related errors


AI-assisted analysis of ComposioHQ/composio@64b1b85502 (2026-08-28). Data as JSON: /api/errors/1cbd1f0c877c0b33. Report an issue: GitHub.