Principle:Openai Openai node Tool Definition
| Knowledge Sources | |
|---|---|
| Domains | Function_Calling, Schema_Validation |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
A principle for defining typed tool specifications that a language model can invoke, including parameter schemas and implementation callbacks.
Description
Tool Definition is the process of declaring functions that a language model can call during a conversation. Each tool has a name, description (for the model to understand when to use it), a parameters schema (defining the argument types), and optionally an implementation callback (the actual function to execute when called).
The Zod-based approach provides three benefits: (1) the schema is automatically converted to JSON Schema for the API, (2) the model's output arguments are automatically parsed and validated against the schema, and (3) the callback receives typed arguments matching the Zod schema.
Usage
Use this principle when building applications where the model needs to interact with external systems (databases, APIs, file systems) or perform computations. Tool definitions are used with runTools() for automatic execution or with create() for manual handling.
Theoretical Basis
Tool definition follows a Contract-First Design:
function defineTool(options):
// 1. Convert Zod schema to JSON Schema
jsonSchema = zodToJsonSchema(options.parameters)
// 2. Create tool specification for the API
toolSpec = {
type: 'function',
function: {
name: options.name,
description: options.description,
parameters: jsonSchema,
strict: true, // Enforce exact schema matching
},
}
// 3. Attach parser and callback for automatic execution
toolSpec.$parse = (rawArgs) => options.parameters.parse(JSON.parse(rawArgs))
toolSpec.$callback = options.function
return toolSpec
The strict: true flag ensures the model's output exactly matches the schema, preventing type mismatches during argument parsing.