Open History to see the last commit
1---
2id: ToolDefinitionInstance
3title: ToolDefinitionInstance
4---
5
6Defined in: [packages/ai/src/activities/chat/tools/tool-definition.ts:146](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/tools/tool-definition.ts#L146)
7
8Tool definition that can be used directly or instantiated for server/client
9
10## Extends
11
12- [`Tool`](Tool.md)\<`TInput`, `TOutput`, `TName`, `TContext`\>
13
14## Extended by
15
16- [`ToolDefinition`](ToolDefinition.md)
17
18## Type Parameters
19
20### TInput
21
22`TInput` *extends* [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined` = `undefined`
23
24### TOutput
25
26`TOutput` *extends* [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined` = `undefined`
27
28### TName
29
30`TName` *extends* `string` = `string`
31
32### TContext
33
34`TContext` = `unknown`
35
36### TNeedsApproval
37
38`TNeedsApproval` *extends* `boolean` = `false`
39
40### TApprovalSchema
41
42`TApprovalSchema` *extends*
43 \| [`ApprovalSchemaConfig`](../type-aliases/ApprovalSchemaConfig.md)
44 \| `undefined` = `undefined`
45
46## Properties
47
48### \_\_toolSide
49
50```ts
51__toolSide: "definition";
52```
53
54Defined in: [packages/ai/src/activities/chat/tools/tool-definition.ts:154](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/tools/tool-definition.ts#L154)
55
56***
57
58### \[toolApprovalCapability\]?
59
60```ts
61readonly optional [toolApprovalCapability]?: object;
62```
63
64Defined in: [packages/ai/src/activities/chat/tools/tool-definition.ts:161](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/tools/tool-definition.ts#L161)
65
66#### approvalSchema
67
68```ts
69approvalSchema: TApprovalSchema;
70```
71
72#### needsApproval
73
74```ts
75needsApproval: TNeedsApproval;
76```
77
78***
79
80### approvalSchema
81
82```ts
83approvalSchema: TApprovalSchema;
84```
85
86Defined in: [packages/ai/src/activities/chat/tools/tool-definition.ts:160](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/tools/tool-definition.ts#L160)
87
88***
89
90### description
91
92```ts
93description: string;
94```
95
96Defined in: [packages/ai/src/types.ts:774](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L774)
97
98Clear description of what the tool does.
99
100This is crucial - the model uses this to decide when to call the tool.
101Be specific about what the tool does, what parameters it needs, and what it returns.
102
103#### Example
104
105```ts
106"Get the current weather in a given location. Returns temperature, conditions, and forecast."
107```
108
109#### Inherited from
110
111[`Tool`](Tool.md).[`description`](Tool.md#description)
112
113***
114
115### execute?
116
117```ts
118optional execute?: ToolExecuteFunction<TInput, TOutput, TContext>;
119```
120
121Defined in: [packages/ai/src/types.ts:854](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L854)
122
123Optional function to execute when the model calls this tool.
124
125If provided, the SDK will automatically execute the function with the model's arguments
126and feed the result back to the model. This enables autonomous tool use loops.
127
128Can return any value - will be automatically stringified if needed.
129
130#### Param
131
132**args**
133
134The arguments parsed from the model's tool call (validated against inputSchema)
135
136#### Returns
137
138Result to send back to the model (validated against outputSchema if provided)
139
140#### Example
141
142```ts
143execute: async (args) => {
144 const weather = await fetchWeather(args.location);
145 return weather; // Can return object or string
146}
147```
148
149#### Inherited from
150
151[`Tool`](Tool.md).[`execute`](Tool.md#execute)
152
153***
154
155### inputSchema
156
157```ts
158inputSchema: TInput;
159```
160
161Defined in: [packages/ai/src/activities/chat/tools/tool-definition.ts:157](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/tools/tool-definition.ts#L157)
162
163Schema describing the tool's input parameters.
164
165Can be any Standard JSON Schema compliant schema (Zod, ArkType, Valibot, etc.) or a plain JSON Schema object.
166Defines the structure and types of arguments the tool accepts.
167The model will generate arguments matching this schema.
168Standard JSON Schema compliant schemas are converted to JSON Schema for LLM providers.
169
170#### See
171
172 - https://standardschema.dev/json-schema
173 - https://json-schema.org/
174
175#### Examples
176
177```ts
178// Using Zod v4+ schema (natively supports Standard JSON Schema)
179import { z } from 'zod';
180z.object({
181 location: z.string().describe("City name or coordinates"),
182 unit: z.enum(["celsius", "fahrenheit"]).optional()
183})
184```
185
186```ts
187// Using ArkType (natively supports Standard JSON Schema)
188import { type } from 'arktype';
189type({
190 location: 'string',
191 unit: "'celsius' | 'fahrenheit'"
192})
193```
194
195```ts
196// Using plain JSON Schema
197{
198 type: 'object',
199 properties: {
200 location: { type: 'string', description: 'City name or coordinates' },
201 unit: { type: 'string', enum: ['celsius', 'fahrenheit'] }
202 },
203 required: ['location']
204}
205```
206
207#### Overrides
208
209[`Tool`](Tool.md).[`inputSchema`](Tool.md#inputschema)
210
211***
212
213### lazy?
214
215```ts
216optional lazy?: boolean;
217```
218
219Defined in: [packages/ai/src/types.ts:860](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L860)
220
221If true, this tool is lazy and will only be sent to the LLM after being discovered via the lazy tool discovery mechanism. Works with both chat() (the synthetic discovery tool) and Code Mode (kept out of the system prompt and revealed via discover_tools).
222
223#### Inherited from
224
225[`Tool`](Tool.md).[`lazy`](Tool.md#lazy)
226
227***
228
229### metadata?
230
231```ts
232optional metadata?: Record<string, any>;
233```
234
235Defined in: [packages/ai/src/types.ts:863](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L863)
236
237Additional metadata for adapters or custom extensions
238
239#### Inherited from
240
241[`Tool`](Tool.md).[`metadata`](Tool.md#metadata)
242
243***
244
245### name
246
247```ts
248name: TName;
249```
250
251Defined in: [packages/ai/src/types.ts:764](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L764)
252
253Unique name of the tool (used by the model to call it).
254
255Should be descriptive and follow naming conventions (e.g., snake_case or camelCase).
256Must be unique within the tools array.
257
258#### Example
259
260```ts
261"get_weather", "search_database", "sendEmail"
262```
263
264#### Inherited from
265
266[`Tool`](Tool.md).[`name`](Tool.md#name)
267
268***
269
270### needsApproval?
271
272```ts
273optional needsApproval?: TNeedsApproval;
274```
275
276Defined in: [packages/ai/src/activities/chat/tools/tool-definition.ts:159](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/tools/tool-definition.ts#L159)
277
278If true, tool execution requires user approval before running. Works with both server and client tools.
279
280#### Overrides
281
282[`Tool`](Tool.md).[`needsApproval`](Tool.md#needsapproval)
283
284***
285
286### outputSchema
287
288```ts
289outputSchema: TOutput;
290```
291
292Defined in: [packages/ai/src/activities/chat/tools/tool-definition.ts:158](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/tools/tool-definition.ts#L158)
293
294Optional schema for validating tool output.
295
296Can be any Standard JSON Schema compliant schema or a plain JSON Schema object.
297If provided with a Standard Schema compliant schema, tool results will be validated
298against this schema before being sent back to the model. This catches bugs in tool
299implementations and ensures consistent output formatting.
300
301Note: This is client-side validation only - not sent to LLM providers.
302Note: Plain JSON Schema output validation is not performed at runtime.
303
304#### Example
305
306```ts
307// Using Zod
308z.object({
309 temperature: z.number(),
310 conditions: z.string(),
311 forecast: z.array(z.string()).optional()
312})
313```
314
315#### Overrides
316
317[`Tool`](Tool.md).[`outputSchema`](Tool.md#outputschema)