The parameters for the tool builder.
Parameters for creating a tool builder.
Optionaldescription?: stringOptional description of the tool for the LLM.
Array of field names from InputSchema that are dynamic (will be made optional at runtime).
Function that executes the tool after all dynamic fields have passed validation.
The input parameter is fully validated and matches the InputSchema (all required fields are present).
Must return a ToolCallResult that indicates success or failure:
{ ok: true, ...output } where output matches OutputSchema (if OutputSchema is a record, spread it directly; otherwise use { value: output }){ ok: false, validationResults: {...}, problems: [...], feedback: [...], instructions: [...], ... } with structured feedbackThe Zod schema defining the tool's input structure.
The Zod schema defining the tool's output structure.
A builder object with .field() and .build() methods.
const tool = toolBuilder({
inputSchema: z.object({ name: z.string(), age: z.number() }),
outputSchema: z.object({ greeting: z.string() }),
dynamicFields: ['name', 'age'],
execute: async (input) => {
return { ok: true, greeting: `Hello, ${input.name}!` };
},
})
.field('name', { ... })
.field('age', { ... })
.build();
Creates a builder for tool definitions.
Use
.field(...)for each dynamic field in theInputSchema, and then call.build()to get the tool. The builder ensures type safety by requiring all dynamic fields to be configured before building.The
executefunction receives fully validated input (after all dynamic fields pass their validation) and must return a ToolCallResult:{ ok: true, ...output }(spread output directly if OutputSchema is a record, otherwise use{ value: output }){ ok: false, validationResults: {...}, problems: [...], feedback: [...], instructions: [...], ... }with structured feedback