Skip to content

LearnGenerate & answer

Tool calling

Function calling

A model returning a structured request to run a named function with JSON arguments, which the application executes and feeds back as a result.

In DocSlurpGlossary entry

On this page

Tool calling (also called function calling) lets a model ask your application to run code. You describe each tool with a name, a description and a JSON Schema for its arguments. When the model decides a tool would help, it returns a structured call instead of text:

{ "name": "search", "arguments": { "q": "Learjet booking lead time London", "limit": 5 } }

Your code validates the arguments, runs the search, and sends the result back as a tool message. The model reads it and either answers or calls another tool. That loop is the engine of agentic RAG, and the Model Context Protocol standardizes how tools are listed and invoked.

The model never executes anything itself. It only writes a request, which means your application keeps full control over what runs, with what permissions, and how often.

The gotcha

Treat tool calls as untrusted input. The arguments are generated text: they may be malformed, out of range or, when the model has read a malicious document, chosen by an attacker. Validate arguments against the schema, check permissions on every call as if a user had made it, cap the number of calls per turn, and require explicit user confirmation for anything that sends, deletes or spends. Some models also write tool-call syntax into their plain-text answer when tools are disallowed; filter it out rather than showing it to users.

In DocSlurp

In DocSlurp

The chat agent calls DocSlurp’s own tools (search, upload status, web tools when enabled) through the MCP dispatcher, capped at 16 calls per turn by default; tool-call syntax a model writes as plain text is stripped from the answer (core/server/src/services/chat-mcp-agent.ts, core/packages/shared/src/project.ts). /v1/chat/completions does not accept client-defined tools.

Sources

Jump to