How to generate zod input schemas for trpc router procedures
- Step 1Capture a sample tRPC procedure input — Use the tRPC client to call the procedure and log the input: console.log(JSON.stringify(input)). Or construct the expected input manually as a JSON object with all fields.
- Step 2Generate the Zod schema — Paste the input JSON and convert. The generated z.object() schema has the correct field types for each input property.
- Step 3Add validation constraints — Tighten the schema: string IDs →’ .uuid(), paginator.limit →’ .number().int().min(1).max(100), search →’ .string().min(1).optional(). Constraints are the primary advantage of Zod over bare TypeScript types in tRPC.
- Step 4Add to the tRPC router — export const userRouter = router({ update: protectedProcedure.input(UpdateUserSchema).mutation(({ ctx, input }) => { // input is fully typed here }), }).
Frequently asked questions
How does tRPC use the Zod schema for type inference on the client?+
tRPC uses z.infer<typeof InputSchema> to derive the TypeScript type of the procedure's input. This type is automatically available in the generated tRPC client, so the client's trpc.users.update.mutate() call is type-checked against the Zod schema's inferred type without any manual type export.
Can I reuse Zod schemas between tRPC input and form validation?+
Yes, and it's recommended. Define the schema once in a shared location (e.g. lib/validators/user.ts) and import it in both the tRPC router for server-side validation and the React Hook Form zodResolver for client-side validation. This ensures client and server validation are always in sync.
Is the tRPC input data transmitted to JAD Apps?+
No. Schema generation runs entirely in your browser. tRPC input data and user action payloads are never transmitted to JAD Apps servers.
Privacy first
Conversion runs locally in your browser. No file is uploaded — only metadata counters are saved for signed-in dashboard stats.