{"record":{"id":"da34033abdc67d10","repo":"JuliusBrussee/caveman","slug":"caveman-agent-standard-schema-emitted-invalid-inp","errorCode":null,"errorMessage":"caveman agent: Standard Schema emitted invalid input JSON Schema","messagePattern":"caveman agent: Standard Schema emitted invalid input JSON Schema","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/primitives.ts","lineNumber":167,"sourceCode":"    let converted = \"inputJSONSchema\" in options\n      ? options.inputJSONSchema\n      : undefined;\n    if (converted === undefined && standard.jsonSchema !== undefined) {\n      try {\n        converted = standard.jsonSchema.input({ target: \"draft-07\" });\n      } catch (error) {\n        throw new Error(\"caveman agent: Standard Schema cannot emit draft-07 input JSON Schema\", {\n          cause: error,\n        });\n      }\n    }\n    if (converted === undefined) {\n      throw new Error(\n        \"caveman agent: Standard Schema needs inputJSONSchema or Standard JSON Schema conversion\",\n      );\n    }\n    if (!isRecord(converted)) {\n      throw new Error(\"caveman agent: Standard Schema emitted invalid input JSON Schema\");\n    }\n    input = converted as TSchema;\n  }\n  const definition = {\n    kind: \"tool\",\n    name: options.name,\n    description: options.description,\n    input,\n    effect: options.effect,\n    result,\n    ...(typeof options.result === \"object\" ? { artifact: options.result } : {}),\n    ...(options.allowRepeat === undefined ? {} : { allowRepeat: options.allowRepeat }),\n    timeoutMs,\n    ...(options.runtime === undefined ? {} : { runtime: options.runtime }),\n    async execute(value: unknown, signal?: AbortSignal) {\n      if (standard === undefined) {\n        return options.execute(value as never, signal);\n      }","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/primitives.ts#L149-L185","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Parse stringified schemas before passing: inputJSONSchema: JSON.parse(schemaText)","Ensure inputJSONSchema is a plain object, e.g. { type: \"object\", ... }","Fix or upgrade the schema library if its jsonSchema conversion returns a non-object"],"exampleFix":"// before\ntool({ name: \"search\", inputJSONSchema: JSON.stringify(schema), ... }) // string, not record\n// after\ntool({ name: \"search\", inputJSONSchema: schema /* plain object */, ... })","handlingStrategy":"type-guard","validationCode":"function isRecord(v: unknown): v is Record<string, unknown> {\n  return typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n// check isRecord(myInputJSONSchema) before passing it to tool()","typeGuard":"function isJsonObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === \"object\" && v !== null && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  const def = tool(options);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"emitted invalid input JSON Schema\")) {\n    // inspect/parse the schema value and retry with a plain object\n  } else throw err;\n}","preventionTips":["Always pass parsed schema objects, never JSON strings","Validate inputJSONSchema with isRecord (or a JSON Schema validator) at construction sites","Sanity-check schema library output once in tests after each dependency upgrade"],"tags":["schema","json-schema","type-check","tool-definition"],"backgroundTag":"type-mismatch","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}