# Function: tool()

```ts
function tool<S>(config: ToolConfig<S>): FunctionTool;

```

Factory for defining function tools with Zod schemas.

* Generates JSON Schema (for the LLM) from the Zod schema via `z.toJSONSchema()`.
* Infers the `execute` argument type from the schema.
* Validates tool call arguments at runtime. On validation failure, returns a formatted error string to the LLM instead of throwing, so the model can self-correct on its next turn.

## Type Parameters[​](#type-parameters "Direct link to Type Parameters")

| Type Parameter                                                                           |
| ---------------------------------------------------------------------------------------- |
| `S` *extends* `ZodType`<`unknown`, `unknown`, `$ZodTypeInternals`<`unknown`, `unknown`>> |

## Parameters[​](#parameters "Direct link to Parameters")

| Parameter | Type                                                                 |
| --------- | -------------------------------------------------------------------- |
| `config`  | [`ToolConfig`](./docs/api/appkit/Interface.ToolConfig.md)<`S`> |

## Returns[​](#returns "Direct link to Returns")

[`FunctionTool`](./docs/api/appkit/Interface.FunctionTool.md)
