{"record":{"id":"cccc33f2799a814a","repo":"JuliusBrussee/caveman","slug":"caveman-agent-tool-standard-schema-must-implement","errorCode":null,"errorMessage":"caveman agent: tool Standard Schema must implement version 1 validation","messagePattern":"caveman agent: tool Standard Schema must implement version 1 validation","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/agent/src/primitives.ts","lineNumber":215,"sourceCode":"      value: Function.prototype.toString.call(options.execute),\n      enumerable: false,\n      configurable: false,\n      writable: false,\n    },\n  );\n  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\") {","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/agent/src/primitives.ts#L197-L233","documentation":"Before using an input as a Standard Schema, tool() inspects value[\"~standard\"] and requires version === 1, a string vendor, and a function validate. Anything else that merely has a ~standard key (wrong version number, missing vendor, validate not callable) throws 'tool Standard Schema must implement version 1 validation'. This is a definition-time contract check of the Standard Schema v1 interface.","triggerScenarios":"Passing an object with a ~standard property shaped for a different spec version (e.g. version: 2 experiments), a partially implemented facade where validate is missing or not a function, or a schema library on an incompatible Standard Schema revision.","commonSituations":"A future Standard Schema v2 library wired in after a dependency upgrade, custom ~standard wrappers that omit vendor, or objects that coincidentally have a ~standard key (poisoned input treated as a schema).","solutions":["Pass a genuine Standard Schema v1 object (version 1, string vendor, function validate)","Pin schema library versions known to implement Standard Schema v1 until this package supports newer revisions","If you only have a JSON Schema, use a TypeBox schema or a validator that properly implements v1","If the value is not meant to be a Standard Schema at all, check why it carries a ~standard key"],"exampleFix":"// before\nconst input = { \"~standard\": { version: 2, validate: (v) => ({ value: v }) } }; // missing vendor, wrong version\n\n// after\nimport { Type } from \"@sinclair/typebox\";\nconst input = Type.Object({ q: Type.String() }); // full Standard Schema v1 implementation","handlingStrategy":"type-guard","validationCode":"function isStandardSchemaV1(v: unknown): boolean {\n  const std = (v as { \"~standard\"?: Record<string, unknown> })[\"~standard\"];\n  return std !== undefined && (std as { version?: unknown }).version === 1 &&\n    typeof (std as { vendor?: unknown }).vendor === \"string\" &&\n    typeof (std as { validate?: unknown }).validate === \"function\";\n}","typeGuard":"const isStandardSchemaV1 = (v: unknown): v is { \"~standard\": { version: 1; vendor: string; validate: (v: unknown) => unknown } } => {\n  if (typeof v !== \"object\" || v === null) return false;\n  const std = (v as Record<string, unknown>)[\"~standard\"] as Record<string, unknown> | undefined;\n  return std?.version === 1 && typeof std?.vendor === \"string\" && typeof std?.validate === \"function\";\n};","tryCatchPattern":null,"preventionTips":["Pin schema library versions that implement Standard Schema v1 and lockfile-audit upgrades","Never hand-craft ~standard objects; use a library or TypeBox schemas directly","Add a canary test that constructs one tool per schema source after dependency bumps"],"tags":["standard-schema","validation","versioning","api-contract"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}