Skip to main content
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.

What happens step by step

  1. Serialize — Tool Zod schemas are dynamically converted to standard JSON Schema (type: "object", properties, required) using serializeZodSchema so the model receives clean parameter declarations.
  2. Pre-Coerce — Incoming arguments are pre-coerced (e.g. "6"6, "true"true) before schema parsing runs.
  3. Validate — Coerced arguments are checked against your Zod schema using schema.safeParse().
  4. Error handling — If arguments remain invalid after coercion, formatted validation errors are captured and returned cleanly without crashing your execution loop.

Example


Disable repair for a tool

Set repairable: false when invalid argument attempts should fail immediately without retry attempts (e.g. handoffs, security-sensitive tools):
Configure max retry attempts per run with maxToolRepairAttempts on agent.run().