{"record":{"id":"659bcbb8bd8aaef8","repo":"trpc/trpc","slug":"could-not-find-a-validator-fn","errorCode":null,"errorMessage":"Could not find a validator fn","messagePattern":"Could not find a validator fn","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/unstable-core-do-not-import/parser.ts","lineNumber":139,"sourceCode":"    // ParserScaleEsque\n    return (value) => {\n      parser.assert(value);\n      return value as TType;\n    };\n  }\n\n  if (isStandardSchema) {\n    // StandardSchemaEsque\n    return async (value) => {\n      const result = await parser['~standard'].validate(value);\n      if (result.issues) {\n        throw new StandardSchemaV1Error(result.issues);\n      }\n      return result.value;\n    };\n  }\n\n  throw new Error('Could not find a validator fn');\n}\n","sourceCodeStart":121,"sourceCodeEnd":141,"githubUrl":"https://github.com/trpc/trpc/blob/acff82332de8b4562d3e6975fa8d94ab1a6de5e0/packages/server/src/unstable-core-do-not-import/parser.ts#L121-L141","documentation":"`getParseFn` walks the supported parser shapes (Zod-like `.parse/.parseAsync`, Yup `.validateSync`, Superstruct `.create`, Scale `.assert`, custom function, Valibot, ArkType, Standard Schema `~standard`). If none of those signatures is detected on the object passed to `.input()`/`.output()`, it throws 'Could not find a validator fn' - tRPC cannot guess how to run your validator.","triggerScenarios":"Passing a schema class instance whose API doesn't match any supported shape (e.g. a raw JSON Schema object, a Joi schema, or a hand-written class); passing a string/number/null by mistake; a tree-shaking/bundling bug that strips the `parse`/`validate` methods off the prototype; passing an already-unwrapped function that lacks the expected signature.","commonSituations":"Using a validator library tRPC doesn't auto-detect; double-wrapping (`z.object(...).parse` instead of `z.object(...)`); version skew where the validator lib changed its API; passing `schema.refine(...)` result that returns a different shape.","solutions":["Confirm the validator object exposes one of the supported APIs (e.g. `parser.parse` / `parser['~standard']` / is a function).","If using an unsupported library, wrap it as a plain function `(input) => result` and pass that function to `.input()`/`.output()`.","Check that you're passing the schema, not the result of calling it (e.g. `z.object(...)` not `z.object(...).parse(...)`).","Verify the validator library version matches what tRPC's detection logic expects."],"exampleFix":"// before - JSON schema object is not a parser\n.input({ type: 'object', properties: { id: { type: 'number' } } })\n\n// after - wrap an unsupported validator in a function\n.input((raw) => {\n  const v = assertUserShape(raw);\n  return v;\n})","handlingStrategy":"type-guard","validationCode":"// Verify the validator exposes a supported API before passing it\nfunction isParser(v: unknown): boolean {\n  return typeof v === 'function'\n    || (v && typeof (v as any).parse === 'function')\n    || (v && typeof (v as any).parseAsync === 'function')\n    || (v && typeof (v as any).validateSync === 'function')\n    || (v && typeof (v as any).create === 'function')\n    || (v && typeof (v as any).assert === 'function')\n    || (v && '~standard' in (v as any));\n}","typeGuard":"import type { Parser } from '@trpc/server';\nfunction asParser<T>(p: Parser): Parser { return p; }","tryCatchPattern":"try { t.procedure.input(maybeParser); }\ncatch (e) {\n  if (/Could not find a validator fn/.test(e.message))\n    throw new Error('Wrap your validator as a function: (v) => lib.validate(v)');\n  throw e;\n}","preventionTips":["Use a supported library (zod, valibot, yup, superstruct, arktype, standard-schema).","Pass the schema object, not the result of calling .parse().","For unsupported libs, wrap them in a plain function.","Check the validator version matches tRPC's detection logic."],"tags":["validation","parser","schema","trpc"],"backgroundTag":null,"analyzedSha":"acff82332de8b4562d3e6975fa8d94ab1a6de5e0","analyzedAt":"2026-08-12T22:04:41.179Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}