JuliusBrussee/caveman · error · Error

tool_schema_transform_invalid

Error message

tool_schema_transform_invalid:${segmentID}

What it means

validatedToolSchemaBytes checks that a lowered/transformed tool-schema segment still parses as { name: string, description: string, input: object }. When a schema transform mangles the JSON — dropping a field, changing a type, or emitting a non-object — the segment's id is attached and the transform output is rejected.

Solutions

  1. Fix the transform so its output keeps name (string), description (string), and input (object)
  2. Exclude tool-schema segments from the transform (treat them as read-only)
  3. Use the segmentID from the message to reproduce with exactly that segment and inspect the bytes it produced

Example fix

// before: transform replaces the schema with a summary object
const out = JSON.stringify({ summary: describe(schema) });

// after: preserve the required shape
const out = JSON.stringify({ ...schema, description: shorten(schema.description) });
Defensive patterns

Strategy: validation

Validate before calling

function isValidToolSchemaJson(bytes: Uint8Array): boolean {
  try {
    const parsed = JSON.parse(new TextDecoder().decode(bytes)) as unknown;
    return isToolSchema(parsed);
  } catch {
    return false;
  }
}

Type guard

function isToolSchema(value: unknown): value is { name: string; description: string; input: Record<string, unknown> } {
  return typeof value === "object" && value !== null && !Array.isArray(value) &&
    typeof (value as { name?: unknown }).name === "string" &&
    typeof (value as { description?: unknown }).description === "string" &&
    typeof (value as { input?: unknown }).input === "object" &&
    (value as { input?: unknown }).input !== null;
}

Try / catch

try {
  bytes = validatedToolSchemaBytes(output, segmentID);
} catch (error) {
  if (error instanceof Error && error.message.startsWith("tool_schema_transform_invalid:")) {
    return originalSchemaBytes; // bypass the bad transform, keep the pre-transform schema
  }
  throw error;
}

Prevention

When it happens

Trigger: A context transform rewriting the tool.<name> schema segment so the output loses name/description/input or makes name/description non-strings or input a non-object; a transform emitting concatenated JSON or prose instead of one object; the segmentID in the message identifies which tool.schema segment broke.

Common situations: Custom schema-compression transforms that summarize description into a non-string or replace the object with an array; renames that drop required fields; transforms applied too broadly across segment kinds.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18). Data as JSON: /api/errors/f458515172a1edad. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/runtime.ts:3804

              : "Use cave_retrieve for omitted detail.",
          ].join("\n"),
        }],
        details: {
          effect: definition.effect,
          resultPolicy: definition.result,
          recoveryHandle: transformed.handle,
          recoveryVerified: true,
        },
      };
    },
  };
}

function validatedToolSchemaBytes(output: Uint8Array, segmentID: string): Uint8Array {
  const parsed = JSON.parse(new TextDecoder().decode(output)) as unknown;
  if (!isRecord(parsed) || typeof parsed.name !== "string" ||
      typeof parsed.description !== "string" || !isRecord(parsed.input)) {
    throw new Error(`tool_schema_transform_invalid:${segmentID}`);
  }
  return output;
}

function providerToolDefinition(
  definition: ToolDefinition,
  lowered: LoweredContext,
  appliedPlan: AppliedPlan,
): { description: string; input: TSchema } {
  const segment = lowered.ir.segments.find((item) => item.id === `tool.${definition.name}`);
  if (!segment) throw new Error(`cave_context_segment_missing:tool.${definition.name}`);
  const body = appliedPlan.bodies.get(segment.bodyHandle);
  if (!body) throw new Error(`cave_context_body_missing:tool.${definition.name}`);
  const parsed = JSON.parse(new TextDecoder().decode(body)) as unknown;
  if (!isRecord(parsed) || parsed.name !== definition.name ||
      typeof parsed.description !== "string" || !isRecord(parsed.input)) {
    throw new Error(`cave_tool_schema_invalid:${definition.name}`);
  }

View on GitHub (pinned to 766dce6b13)