JuliusBrussee/caveman · error

caveman agent: Standard Schema emitted invalid input JSON…

Error message

caveman agent: Standard Schema emitted invalid input JSON Schema

What it means

After obtaining the tool's input JSON Schema (from inputJSONSchema or Standard Schema conversion), tool() verifies it is a record (a plain object). A non-object conversion result means the schema library emitted something unusable (null, array, string), so the library rejects it before constructing the ToolDefinition.

Solutions

  1. Parse stringified schemas before passing: inputJSONSchema: JSON.parse(schemaText)
  2. Ensure inputJSONSchema is a plain object, e.g. { type: "object", ... }
  3. Fix or upgrade the schema library if its jsonSchema conversion returns a non-object

Example fix

// before
tool({ name: "search", inputJSONSchema: JSON.stringify(schema), ... }) // string, not record
// after
tool({ name: "search", inputJSONSchema: schema /* plain object */, ... })
Defensive patterns

Strategy: type-guard

Validate before calling

function isRecord(v: unknown): v is Record<string, unknown> {
  return typeof v === "object" && v !== null && !Array.isArray(v);
}
// check isRecord(myInputJSONSchema) before passing it to tool()

Type guard

function isJsonObject(v: unknown): v is Record<string, unknown> {
  return typeof v === "object" && v !== null && !Array.isArray(v);
}

Try / catch

try {
  const def = tool(options);
} catch (err) {
  if (err instanceof Error && err.message.includes("emitted invalid input JSON Schema")) {
    // inspect/parse the schema value and retry with a plain object
  } else throw err;
}

Prevention

When it happens

Trigger: tool({ input: standardSchema, inputJSONSchema: oddValue }) where oddValue is null, an array, a string, or a number; or a jsonSchema conversion that returns a non-record value.

Common situations: Passing a JSON string of a schema instead of a parsed object; JSON.stringify/parse round-trip mistakes; schema libraries with buggy or partial jsonSchema support returning null; config loading a schema as text.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/da34033abdc67d10. Report an issue: GitHub.

Appendix: source

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

    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,
    input,
    effect: options.effect,
    result,
    ...(typeof options.result === "object" ? { artifact: options.result } : {}),
    ...(options.allowRepeat === undefined ? {} : { allowRepeat: options.allowRepeat }),
    timeoutMs,
    ...(options.runtime === undefined ? {} : { runtime: options.runtime }),
    async execute(value: unknown, signal?: AbortSignal) {
      if (standard === undefined) {
        return options.execute(value as never, signal);
      }

View on GitHub (pinned to 3ee70a1026)