How do you test tool calling with a local model?

Tool calling has two parts: the model proposes an action and your application decides whether to execute it. Test the proposal before connecting real tools.

Test local tool calling with a read-only mock tool before giving the model any real authority. Require three separate passes: the right tool, valid arguments, and a final answer supported by the returned data.

Separate the proposal from execution

A tool call is a request from the model to your application. Your application decides whether to run it, supplies the result, and asks the model to continue. In Ollama's native chat API, you send function definitions in tools and inspect message.tool_calls in the response. Verify “I checked inventory” against the application record of the function call.

Start with a dictionary containing three fictional products: A100 has seven units, B200 has zero, and C300 has twelve. Expose only lookup_inventory, taking a string named product_id. Keep the dictionary in the application rather than the prompt. That makes it possible to tell whether the final answer came from a tool result or a guess.

Put an allowlist and argument checks between the response and execution. Reject unknown functions, unexpected keys, missing IDs and non-string IDs. An unknown product can return a normal “not found” result; it must not silently become the nearest known product. Limit each test conversation to three tool rounds so a repeated lookup cannot run forever. Set that three-round budget in your application.

Send a complete Ollama tool definition

With Ollama running and qwen3:4b downloaded, send this request from a macOS or Linux terminal. Ollama lists Qwen3 with tool support. Validate its arguments against the same fixtures as every other candidate.

curl http://localhost:11434/api/chat \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "qwen3:4b",
    "stream": false,
    "messages": [{"role": "user", "content": "How many A100 units are available?"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "lookup_inventory",
        "description": "Read inventory for one exact product ID.",
        "parameters": {
          "type": "object",
          "properties": {"product_id": {"type": "string"}},
          "required": ["product_id"]
        }
      }
    }]
  }'

In this native API, function arguments are an object. Read the function name and arguments from each returned call, validate them, and execute the mock lookup. Preserve the assistant message containing its calls in the next request. Append the tool response as a message with role: "tool", tool_name: "lookup_inventory", and a string content containing your result. Send the accumulated messages and tool definitions again to obtain the answer.

Use stream: false for this first test so you can inspect one complete response. Save the proposal, validation result and tool output separately. If the final answer says six units after the tool returned seven, the tool integration worked but the answer failed.

Match llama.cpp to its tool template

llama.cpp documents OpenAI-style function calling in llama-server with --jinja. Its native handlers include Llama 3.1/3.3, Qwen 2.5 and Qwen 2.5 Coder, Hermes, and GPT-OSS formats. A tools-enabled Jinja template is still required. Launch the server with Jinja enabled and an explicit Flash Attention setting:

llama-server --jinja --flash-attn on \
  -hf bartowski/Qwen2.5-7B-Instruct-GGUF:Q4_K_M

Inspect the server's /props response for chat_template or chat_template_tool_use. If the embedded template is unsuitable, the documented override is --chat-template-file. An unrecognized template can use a generic handler; evaluate tool selection separately from parsing. Repeat the same mock tests after any template change.

Failure Check first Acceptance rule
Tool call appears as ordinary prose Template and server parsing Application receives a structured call
Correct tool, wrong ID Argument extraction and ambiguity Exact ID or a clarification question
Invented stock count Tool result handling Answer matches returned count
Repeated identical lookup Conversation history and loop control Terminates within the test budget

Try it on your workload

Run six prompts: ask about A100, ask about B200, ask about unknown D400, omit the product ID, request two products, and ask the model to change inventory. The last request should not produce a write operation because no write tool exists. Record whether the model asks for clarification when needed and whether it preserves the distinction between zero stock and an unknown product.

Repeat the six prompts five times, starting fresh each time: 6 × 5 = 30 conversations. Score tool selection, argument validity and final factual accuracy independently. Count unnecessary calls too. A model that always invokes a tool may pass a simple lookup test while wasting work on questions answerable without inventory access.

Then replace one tool result with a simulated timeout. Decide in advance whether the acceptable answer is a retry or an explicit unavailable result. Do not accept an invented count as graceful recovery. Keep real purchasing, deletion and messaging tools disconnected throughout this experiment.

How to decide

Choose a checkpoint and template together. Keep local execution when the repeated tests pass and response times suit your application. If structured calls fail, fix the protocol before comparing model size. If valid calls repeatedly contain wrong arguments, compare another checkpoint with the identical tool schema and fixtures.

Run twenty tool-test agents for about 1.4 cents

Twenty tool-test agents working at once on openai/gpt-oss-120b cost about 1.4 cents in tokens on TrustedRouter. In this illustrative evaluation, each consumes 10,000 input and 2,000 output tokens across its complete tool loops. On 2026-11-22, catalog prices rounded to $0.0317 per million input and $0.179 per million output tokens. Input = 20 × 10,000 = 200,000; output = 20 × 2,000 = 40,000. Cost = 0.2 × $0.0317 + 0.04 × $0.179 = $0.0135, about 1.4 cents.

On one local GPU, these agents share its throughput, and requests beyond its parallel capacity wait in line; through a per-token API they can run concurrently, with the same token bill as running them one after another. Give each agent independent mock conversations, then compare tool selection, argument validity and final answers. Your application retains control of tool execution.

Prices change; check the model catalog and agent setup. For approved private fixtures, use confidential inference and provider routing to select and price an eligible route. Local remains preferable when tool results must stay on the device.

Sources

Related local LLM decisions