{"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":"Error","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/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/agent/src/primitives.ts#L149-L185","documentation":"After obtaining a converted or supplied JSON Schema for a Standard Schema tool input, tool() sanity-checks that it is a plain object (isRecord). If the converter or inputJSONSchema returned an array, string, null, or a primitive, the value cannot be a JSON Schema and the factory throws 'Standard Schema emitted invalid input JSON Schema'.","triggerScenarios":"A schema library whose jsonSchema.input() returns a { $schema, schema } envelope instead of the bare schema object, or a caller passing inputJSONSchema: \"string\" / an array of schemas. Note: converters returning undefined take error 176's path instead.","commonSituations":"Mismatch between what a given validator's converter returns (some return { draft, schema } wrappers) and what this package expects (the schema object itself), or hand-written inputJSONSchema values built by JSON.parse of something that was not an object.","solutions":["Unwrap envelope returns: inputJSONSchema: envelope.schema rather than envelope","Check with Array.isArray(x) || typeof x !== \"object\" || x === null before passing","Upgrade the schema library if a new version returns the bare object directly"],"exampleFix":"// before\ninputJSONSchema: converter.output // { draft: \"07\", schema: {...} }\n\n// after\ninputJSONSchema: converter.output.schema // the bare object","handlingStrategy":"type-guard","validationCode":"const isRecord = (v: unknown): v is Record<string, unknown> =>\n  typeof v === \"object\" && v !== null && !Array.isArray(v);\nif (!isRecord(converted)) {\n  throw new Error(\"JSON Schema converter must return a plain schema object\");\n}","typeGuard":"const isJsonObject = (v: unknown): v is Record<string, unknown> =>\n  typeof v === \"object\" && v !== null && !Array.isArray(v);","tryCatchPattern":null,"preventionTips":["Know your converter's return shape: unwrap envelopes ({ schema }) before passing","JSON.parse schema files and assert typeof === \"object\" before use","Unit-test the tool factory against every schema pipeline you support"],"tags":["json-schema","standard-schema","validation","api-misuse"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}