JuliusBrussee/caveman · error

caveman agent: Standard Schema cannot emit draft-07 input…

Error message

caveman agent: Standard Schema cannot emit draft-07 input JSON Schema

What it means

When a tool's input is defined via Standard Schema and no explicit inputJSONSchema is supplied, tool() asks the schema for a draft-07 JSON Schema conversion. If that conversion throws, the error is rethrown wrapped with this message (original error attached as cause), because the library needs draft-07 output to describe the tool to providers.

Solutions

  1. Pass an explicit inputJSONSchema (a valid draft-07 object) instead of relying on automatic conversion
  2. Upgrade the schema library to a version whose Standard Schema jsonSchema export supports target "draft-07"
  3. Inspect error.cause to see the underlying conversion failure and simplify the offending schema constructs

Example fix

// before
tool({ name: "search", input: myZodSchema, ... }) // conversion throws
// after
tool({ name: "search", input: myZodSchema, inputJSONSchema: { type: "object", properties: { query: { type: "string" } }, required: ["query"] }, ... })
Defensive patterns

Strategy: try-catch

Validate before calling

function supportsDraft07(schema: { ["~standard"]?: { jsonSchema?: { input?: (o: { target: string }) => unknown } } }): boolean {
  try {
    return schema["~standard"]?.jsonSchema?.input?.({ target: "draft-07" }) !== undefined;
  } catch { return false; }
}

Try / catch

try {
  const def = tool({ input: standardSchema });
} catch (err) {
  if (err instanceof Error && err.message.includes("cannot emit draft-07")) {
    console.error("conversion cause:", (err as { cause?: unknown }).cause);
    // retry with explicit inputJSONSchema
  } else throw err;
}

Prevention

When it happens

Trigger: tool({ input: standardSchema }) where standardSchema['~standard'].jsonSchema.input({ target: "draft-07" }) throws — e.g. the schema library does not support the draft-07 target or the schema uses constructs it cannot convert.

Common situations: Schema libraries (zod/valibot variants) lacking JSON Schema conversion or draft-07 support at the installed version; exotic schema features (custom transforms, branded types) failing conversion; version mismatch after upgrading the schema library.

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@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/cd336f15c27c3e8f. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/primitives.ts:156

    throw new Error(`caveman agent: unknown tool result policy ${JSON.stringify(result)}`);
  }
  const timeoutMs = options.timeoutMs ?? 30_000;
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) {
    throw new Error("caveman agent: tool timeoutMs must be a positive integer");
  }
  const standard = standardToolSchema(options.input);
  let input: TSchema;
  if (standard === undefined) {
    input = options.input as TSchema;
  } else {
    let converted = "inputJSONSchema" in options
      ? options.inputJSONSchema
      : undefined;
    if (converted === undefined && standard.jsonSchema !== undefined) {
      try {
        converted = standard.jsonSchema.input({ target: "draft-07" });
      } catch (error) {
        throw new Error("caveman agent: Standard Schema cannot emit draft-07 input JSON Schema", {
          cause: error,
        });
      }
    }
    if (converted === undefined) {
      throw new Error(
        "caveman agent: Standard Schema needs inputJSONSchema or Standard JSON Schema conversion",
      );
    }
    if (!isRecord(converted)) {
      throw new Error("caveman agent: Standard Schema emitted invalid input JSON Schema");
    }
    input = converted as TSchema;
  }
  const definition = {
    kind: "tool",
    name: options.name,
    description: options.description,

View on GitHub (pinned to 3ee70a1026)