{"record":{"id":"4d24fdfbfe373f73","repo":"JuliusBrussee/caveman","slug":"caveman-agent-tool-standard-json-schema-converter","errorCode":null,"errorMessage":"caveman agent: tool Standard JSON Schema converter is invalid","messagePattern":"caveman agent: tool Standard JSON Schema converter is invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/primitives.ts","lineNumber":221,"sourceCode":"  return Object.freeze(definition);\n}\n\nfunction standardToolSchema(\n  value: unknown,\n): StandardSchemaV1.Props<unknown, unknown> & {\n  jsonSchema?: StandardJSONSchemaV1.Converter;\n} | undefined {\n  if (!isRecord(value) || !isRecord(value[\"~standard\"])) return undefined;\n  const standard = value[\"~standard\"];\n  if (standard.version !== 1 || typeof standard.vendor !== \"string\" ||\n      typeof standard.validate !== \"function\") {\n    throw new Error(\n      \"caveman agent: tool Standard Schema must implement version 1 validation\",\n    );\n  }\n  if (standard.jsonSchema !== undefined &&\n      (!isRecord(standard.jsonSchema) || typeof standard.jsonSchema.input !== \"function\")) {\n    throw new Error(\"caveman agent: tool Standard JSON Schema converter is invalid\");\n  }\n  return standard as unknown as StandardSchemaV1.Props<unknown, unknown> & {\n    jsonSchema?: StandardJSONSchemaV1.Converter;\n  };\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction artifactResultPolicy(definition: ArtifactDefinition): ToolResultPolicy {\n  if (definition.strategy === \"verbatim\") {\n    return definition.recovery === \"exact_ccr\" ? \"exact_ccr\" : \"inline\";\n  }\n  if (definition.strategy === \"json-index\") return \"compress\";\n  return \"page\";\n}\n","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/primitives.ts#L203-L239","documentation":"After confirming the `~standard` props themselves are valid, standardToolSchema checks the optional `jsonSchema` converter. If `~standard.jsonSchema` is present it must be a record with a callable `input` method (the Standard JSON Schema v1 converter shape). This error means the object advertises a JSON Schema converter but its shape is wrong, so the library cannot convert the schema to JSON Schema.","triggerScenarios":"Passing a tool whose inputSchema has `~standard` valid for validate/version/vendor, but `~standard.jsonSchema` is: not a record (e.g. a function or string), or an object whose `input` is not a function (e.g. `jsonSchema: { input: '...' }` or missing `input`).","commonSituations":"Hand-rolling the `jsonSchema` converter stub; using an older Standard JSON Schema draft where the converter API differed; a wrapper library exposing `jsonSchema` as a getter that resolved to a non-object; typos like `inputs` instead of `input`.","solutions":["Ensure `~standard.jsonSchema` is an object with a callable `input` method: `jsonSchema: { input: (schema) => jsonSchemaObject, target: 'draft-2020-12' }`.","Prefer passing a native schema (Zod/Valibot/ArkType) whose `~standard.jsonSchema` is provided by the library instead of constructing it yourself.","If you don't need JSON Schema conversion, omit `~standard.jsonSchema` entirely (it is optional).","Upgrade the schema library to a version implementing Standard JSON Schema v1 correctly."],"exampleFix":"// before\nschema[\"~standard\"].jsonSchema = { input: \"not-a-function\" };\n// after\nschema[\"~standard\"].jsonSchema = {\n  input: (s) => toJsonSchema(s),\n  target: \"draft-2020-12\",\n};","handlingStrategy":"type-guard","validationCode":"function hasValidJsonSchemaConverter(std: any): boolean {\n  const c = std?.jsonSchema;\n  return c === undefined || (typeof c === \"object\" && c !== null && typeof c.input === \"function\");\n}\nif (!hasValidJsonSchemaConverter(inputSchema?.[\"~standard\"])) throw new Error(\"invalid jsonSchema converter\");","typeGuard":"const hasJsonSchemaConverter = (v: unknown): v is { \"~standard\": { jsonSchema: { input: (schema: unknown, options?: unknown) => unknown } } } =>\n  typeof v === \"object\" && v !== null &&\n  typeof (v as any)[\"~standard\"]?.jsonSchema === \"object\" && (v as any)[\"~standard\"]?.jsonSchema !== null &&\n  typeof (v as any)[\"~standard\"].jsonSchema.input === \"function\";","tryCatchPattern":"try {\n  registerTool({ inputSchema });\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"Standard JSON Schema converter is invalid\")) {\n    console.error(\"~standard.jsonSchema must be an object with a callable input() — omit it or use a compliant schema library\", e);\n  } else throw e;\n}","preventionTips":["Omit `~standard.jsonSchema` unless you actually implement the Standard JSON Schema v1 converter contract.","Let the schema library supply the converter rather than hand-rolling `{ input: ... }`.","Type the tool schema as `StandardSchemaV1.Props` from the standard-schema package so mismatches are caught at compile time."],"tags":["standard-schema","json-schema","tools","typescript"],"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"}