Shaf Lab

Tool calling

Letting a model request a named function with structured arguments, which your code then runs.

Tool calling, also called function calling, lets a model respond with a structured request to run a named function instead of replying in prose. You describe the available tools in the request. The model may answer with a tool name and arguments, usually as JSON. Your code checks those arguments, runs the function, and sends the result back as a new message, and the model continues from there.

The model never executes anything itself. It only proposes a call, and your application decides whether to honor it. That boundary is where all the safety lives: validate arguments against the schema, enforce permissions in code, and require human approval for anything hard to undo. Treat the model's arguments as untrusted input, exactly as you would treat a form submitted by a stranger.

This one mechanism is the foundation of agents. A loop of call, run, return, repeat lets a model search, read files, query databases, and take actions over many steps. Many models can also request several independent calls at once, which your code can run in parallel. Results should be compact and informative; returning a huge raw payload wastes context, and returning a bare error code gives the model nothing to recover with.

Design tools for the model as you would design an API for a new teammate: few, narrow, clearly named, with obvious arguments. A handful of well-described tools beats dozens of overlapping ones, because the model chooses tools only from their names and descriptions.

Tool schema

The name, description, and typed parameter definition a model sees for each tool it can call.

A tool schema is everything the model knows about a tool: its name, a plain-language description of what it does and when to use it, and a typed definition of its parameters, usually written in JSON Schema with types, required fields, allowed values, and per-field descriptions. The model decides whether and how to call a tool using only this text, so the schema is effectively part of the prompt.

Vague or overlapping descriptions lead to wrong or missed calls. Name tools by action, describe when not to use them as well as when to, constrain arguments with enums and formats, and document units and edge cases. Keep the tool list short, since every schema consumes context on every request, and test tool selection with real requests the same way you test prompts.