{"record":{"id":"cd336f15c27c3e8f","repo":"JuliusBrussee/caveman","slug":"caveman-agent-standard-schema-cannot-emit-draft-0","errorCode":null,"errorMessage":"caveman agent: Standard Schema cannot emit draft-07 input JSON Schema","messagePattern":"caveman agent: Standard Schema cannot emit draft-07 input JSON Schema","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/primitives.ts","lineNumber":156,"sourceCode":"    throw new Error(`caveman agent: unknown tool result policy ${JSON.stringify(result)}`);\n  }\n  const timeoutMs = options.timeoutMs ?? 30_000;\n  if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) {\n    throw new Error(\"caveman agent: tool timeoutMs must be a positive integer\");\n  }\n  const standard = standardToolSchema(options.input);\n  let input: TSchema;\n  if (standard === undefined) {\n    input = options.input as TSchema;\n  } else {\n    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,","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/primitives.ts#L138-L174","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass an explicit inputJSONSchema (a valid draft-07 object) instead of relying on automatic conversion","Upgrade the schema library to a version whose Standard Schema jsonSchema export supports target \"draft-07\"","Inspect error.cause to see the underlying conversion failure and simplify the offending schema constructs"],"exampleFix":"// before\ntool({ name: \"search\", input: myZodSchema, ... }) // conversion throws\n// after\ntool({ name: \"search\", input: myZodSchema, inputJSONSchema: { type: \"object\", properties: { query: { type: \"string\" } }, required: [\"query\"] }, ... })","handlingStrategy":"try-catch","validationCode":"function supportsDraft07(schema: { [\"~standard\"]?: { jsonSchema?: { input?: (o: { target: string }) => unknown } } }): boolean {\n  try {\n    return schema[\"~standard\"]?.jsonSchema?.input?.({ target: \"draft-07\" }) !== undefined;\n  } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const def = tool({ input: standardSchema });\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"cannot emit draft-07\")) {\n    console.error(\"conversion cause:\", (err as { cause?: unknown }).cause);\n    // retry with explicit inputJSONSchema\n  } else throw err;\n}","preventionTips":["Keep schema libraries updated to versions with draft-07 Standard Schema support","Test tool construction in CI to catch conversion breakage after upgrades","Supply explicit inputJSONSchema for schemas known to use exotic constructs"],"tags":["schema","json-schema","standard-schema","tool-definition"],"backgroundTag":"schema-validation-failed","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"}