Skip to main content

FunctionSchema

Defines the JSON Schema for a tool or function that an LLM can invoke via function calling.

Import

import type { FunctionSchema } from '@adaline/api';

Definition

interface FunctionSchema {
  name: string;
  description: string;
  parameters: any;
  strict?: boolean | null;
}

Fields

FieldTypeDescription
namestringFunction name. Must match ^[a-zA-Z0-9_]{1,64}$ — alphanumeric and underscores only, 1–64 characters.
descriptionstringHuman-readable description of what the function does. Maximum 4096 characters. The LLM uses this to decide when to call the function.
parametersanyA JSON Schema object describing the function’s input parameters. Typically an object schema with properties and required.
strictboolean | nullWhen true, the LLM must produce arguments that strictly conform to the parameters schema. When false or null, the LLM may produce approximate matches.

Usage

Basic function schema

import type { FunctionSchema } from '@adaline/api';

const getWeather: FunctionSchema = {
  name: 'get_weather',
  description: 'Get the current weather for a given city',
  parameters: {
    type: 'object',
    properties: {
      city: {
        type: 'string',
        description: 'City name (e.g., "San Francisco")',
      },
      units: {
        type: 'string',
        enum: ['celsius', 'fahrenheit'],
        default: 'celsius',
        description: 'Temperature units',
      },
    },
    required: ['city'],
  },
  strict: true,
};

Complete tool definition

FunctionSchema is used inside a ToolFunction definition:
import type { ToolFunction, FunctionSchema } from '@adaline/api';

const schema: FunctionSchema = {
  name: 'search_database',
  description: 'Search the internal knowledge base for relevant documents',
  parameters: {
    type: 'object',
    properties: {
      query: {
        type: 'string',
        description: 'Natural language search query',
      },
      limit: {
        type: 'number',
        description: 'Maximum number of results to return',
        default: 10,
      },
      filters: {
        type: 'object',
        properties: {
          category: { type: 'string' },
          dateAfter: { type: 'string', format: 'date' },
        },
      },
    },
    required: ['query'],
  },
};

const tool: ToolFunction = {
  type: 'function',
  definition: { schema },
};

JSON representation

{
  "name": "get_weather",
  "description": "Get the current weather for a given city",
  "parameters": {
    "type": "object",
    "properties": {
      "city": { "type": "string", "description": "City name" },
      "units": { "type": "string", "enum": ["celsius", "fahrenheit"] }
    },
    "required": ["city"]
  },
  "strict": true
}

See Also

  • ToolFunction — wraps FunctionSchema inside a tool definition