Automatically serialize Zod schemas and pre-coerce argument types.
Models sometimes send stringified numbers or booleans like "42" or "true" when your schema expects primitive numbers or booleans. kenpachi automatically pre-coerces these primitive argument types before validating arguments with Zod.
Argument pre-coercion is enabled by default for every tool defined with defineTool.
Serialize — Tool Zod schemas are dynamically converted to standard JSON Schema (type: "object", properties, required) using serializeZodSchema so the model receives clean parameter declarations.
Pre-Coerce — Incoming arguments are pre-coerced (e.g. "6" → 6, "true" → true) before schema parsing runs.
Validate — Coerced arguments are checked against your Zod schema using schema.safeParse().
Error handling — If arguments remain invalid after coercion, formatted validation errors are captured and returned cleanly without crashing your execution loop.