Skip to main content

FunctionSchema

Defines the JSON Schema for a tool or function used in LLM function calling.

Overview

FunctionSchema describes a callable function that an LLM can invoke, including its name, description, parameter schema, and optional strict validation mode. It is used inside ToolFunction definitions.

Import

from adaline_api.models.function_schema import FunctionSchema

Fields

name
str
required
Function name. Must match the pattern ^[a-zA-Z0-9_]{1,64}$ — alphanumeric characters and underscores only, between 1 and 64 characters.
description
str
required
A human-readable description of what the function does. Maximum 4096 characters. This is provided to the LLM to help it decide when and how to call the function.
parameters
dict[str, Any]
required
A JSON Schema object describing the function’s parameters. Must have "type": "object" at the top level with "properties" defining each parameter.
strict
bool | None
Whether to enforce strict schema validation. When True, the LLM must conform exactly to the parameter schema — no extra properties or missing required fields. When None or False, the LLM may produce approximate matches.

Usage

Basic function schema

from adaline_api.models.function_schema import FunctionSchema

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

Using within a ToolFunction

from adaline_api.models.function_schema import FunctionSchema
from adaline_api.models.tool_function_definition import ToolFunctionDefinition
from adaline_api.models.tool_function import ToolFunction

schema = FunctionSchema(
    name="search_database",
    description="Search the internal knowledge base for relevant documents",
    parameters={
        "type": "object",
        "properties": {
            "query": {
                "type": "string",
                "description": "The search query"
            },
            "limit": {
                "type": "integer",
                "default": 10,
                "description": "Maximum number of results to return"
            },
            "filters": {
                "type": "object",
                "properties": {
                    "category": {"type": "string"},
                    "date_after": {"type": "string", "format": "date"}
                },
                "description": "Optional filters to narrow results"
            }
        },
        "required": ["query"]
    },
    strict=False
)

tool = ToolFunction(
    type="function",
    definition=ToolFunctionDefinition(var_schema=schema)
)

JSON Representation

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

Name Validation

The name field must match the regex pattern ^[a-zA-Z0-9_]{1,64}$:
ExampleValid
"get_weather"Yes
"searchDB"Yes
"my_function_v2"Yes
"get-weather"No — hyphens not allowed
"get weather"No — spaces not allowed
""No — must be at least 1 character

  • ToolFunction — wraps FunctionSchema in a tool definition