Tool calling with self-hosted Ollama models

Ollama supports tool calling through its native chat API and an OpenAI-compatible tools field, with gaps such as tool_choice. This page covers what platform teams must design, configure and verify before exposing tools to users or agents.

On this page

Tool calling with self-hosted Ollama models: what your platform team must plan

Ollama supports tool calling through its native chat API and through the OpenAI-compatible /v1/chat/completions endpoint, but that endpoint accepts the tools field without tool_choice, so your application cannot force a specific function or require a call. Teams need this when a locally hosted model must look up an account, check a ticket or query an internal service instead of answering from its training data alone. The model only proposes a call with a function name and arguments. Your application validates that request, runs the function under its own identity and permissions, and returns the result to the model, which then writes the answer. Ollama does not execute your tools.

Start by confirming which models support tools. Support is a property of each model and its template, so check the Ollama tool calling documentation and test each candidate model on the Ollama version you plan to run before you design around it. Your platform team also decides how the tool registry is governed: who may add a tool, what each tool can reach, and whether arguments are checked against a schema before anything runs. Network exposure matters as well. The local API has no authentication and binds to 127.0.0.1 on port 11434 by default, so a tool-calling service reached by other systems needs an authenticated proxy in front of it.

Plan for change in both the runtime and the models. Ollama ships frequent releases, including v0.40.5 on 14 October 2026 and a pre-release, v0.40.6, on 16 October 2026, so pin the version your tool loop was tested against and read the Ollama release notes before each upgrade. Build the test suite around the behaviors that break in production: single and multiple tool calls in one turn, malformed or missing arguments, a model that keeps calling tools without finishing, and tool results too large for the context window. Budget the work in two parts. Building the tool loop and its test cases is a one-time engineering cost, while retesting after each model or runtime change recurs. Ollama's pricing page states that running models on your own hardware is unlimited, so the cost to ask a partner to quote is the build and retest effort.

How a tool call moves between client, Ollama and your functions

The loop starts when the client application sends a user request to Ollama's /api/chat endpoint with a tools list. The model does not run anything itself. It returns a tool call, the application executes the matching function against internal systems, and it sends the result back as a tool message so the model can write the final response. The trust boundary sits between the Ollama server and those internal systems: Ollama never holds the credentials for them, so the application must validate every requested call before it runs.

Tool call loop between the client, Ollama, your functions and internal systems.

Which tool calling interface fits which integration

This table compares the native /api/chat tools flow, the OpenAI-compatible tools field and the Python and JavaScript SDKs. Read each column to match your client code to the interface that supports it, and note the known gaps before you commit to one.

InterfaceBest fitWhat the client must handleKnown gap to plan for
Native /api/chat toolsNew integrations built directly against OllamaSend tool schemas, detect tool_calls in the response, run the function and return a tool-role messageYour code owns the full loop, including the follow-up request after each tool result
OpenAI-compatible /v1/chat/completions tools fieldExisting OpenAI-style client code that you want to point at a local serverKeep OpenAI request and response shapes, parse tool_calls and return results in the same formattool_choice is not supported, so you cannot force or forbid a tool call on this endpoint
Python SDKPython services and scripts using Ollama directlyDefine tools as functions or schemas, then run the returned calls and append results to the message historyConfirm the installed SDK version handles your tool schema before relying on it in production
JavaScript SDKNode.js or browser-side tooling that talks to your Ollama serverSame message loop as the native API, with tool schemas and results handled in JavaScriptBrowser use exposes the server to origin and credential questions covered in the security guidance
Multiple tool calls in one turnAgents that may request several functions at onceExecute every returned call, return each result, then send the updated history back to the modelWhether a given model emits parallel calls varies, so test each approved model
Models without tool supportChat-only models or unverified community buildsFall back to prompt-based tool selection, or choose a model that lists tool supportConfirm tool support per model before rollout, since a model may accept a tools field and still call tools poorly

Choosing models that support tools before you standardize

Tool support varies from model to model, so the approved list should be built from tests, not from a model's name or reputation. The cards below cover the checks that decide whether a candidate model can be standardized for function calling, including licensing and custom imports.

Check each model's tool capability

Confirm in Ollama's model listing that each candidate carries the tools capability before anyone builds on it. Capability labels can change as models are updated, so record the exact model tag and the date you checked it. A model that answers in plain text when given a tools field has not passed the check, even if its general quality is strong.

Tool calling docs

Test with your own tool schemas

Run each candidate against the function schemas your applications will really send, including nested objects, optional parameters and enums. Check that the model picks the right tool, fills arguments with valid types and handles a result it did not expect. Passing a generic demo does not show that a model will work with your schemas.

Measure multiple tool calls

Some workflows need a model to request several tools in one turn, or to chain calls across turns. Test the candidate on those patterns with the same prompts your users will send, and log the arguments it produces. Note which models skip a needed call or repeat one, because those failures are harder to see in production than outright errors.

Review model licenses

A model's license governs what your organization may do with its weights, outputs and derivatives, and that can differ from the MIT license covering the Ollama runtime. Have legal or compliance review the license of each candidate before it enters the catalog. Record commercial use, redistribution and attribution terms alongside the approval.

Plan approval for custom imports

Fine-tuned or quantized models imported from Safetensors or GGUF files are not covered by the vendor's tool testing. Repeat the capability and schema tests on each import, because quantization and template changes can alter tool behavior. Keep the import's source, conversion steps and test results with the model record in your internal catalog.

Pin versions and retest on upgrades

Standardize on specific model tags and Ollama versions, and retest tool behavior before moving either one. A runtime release or a new model build can change chat templates and tool output. Ask your team to define the retest set and the owner who signs off the upgrade, so the approved list stays accurate over time.

How to set up and verify tool calling on a self-hosted server

This sequence takes a platform team from a locked-down Ollama endpoint to a verified tool-calling loop, with a checkpoint at each stage so problems surface before applications depend on the server. The output is a tested configuration, a set of tool schemas and a record of how the model behaves on valid and invalid input.

  1. Confirm the server is reachable only where intended

    The platform team checks which address Ollama listens on before any model work starts. By default Ollama binds to 127.0.0.1 on port 11434, so a server that is meant to be private should keep that default or set the bind address deliberately with the OLLAMA_HOST environment variable. From a machine outside the intended network, run a request against the port and confirm it is refused or times out. The check is done when a host that should not reach the API gets no response and an allowed host gets one. The local API has no authentication, so this network check is the main access control at this stage.

  2. Pull and test an approved tool-capable model

    Pull the model your organization has approved, using the exact tag recorded in your model catalog, and confirm it is listed as supporting tool calling in its documentation before you rely on it. Send a short chat request to /api/chat with no tools defined and check that a normal text answer comes back. Record the model name, tag and the Ollama version reported by the server so the test can be repeated after an upgrade. Ask the model vendor or your catalog owner to confirm the license terms, since tool support does not imply that a model is approved for your use. The check is done when the model answers a plain prompt and the version and tag are written in your test log.

  3. Define tool schemas with names, descriptions and typed parameters

    Write one schema for each tool the model may call, using the function format that Ollama accepts in the tools field. Each tool needs a clear name, a description that tells the model when to use it, and typed parameters with descriptions and required fields. Keep the number of tools small for the first test, and make sure each tool maps to an action your application already controls, such as a read-only lookup. Store the schemas in version control next to the application code. The check is done when a reviewer can read each schema and identify what the tool does, what each argument means and which arguments are mandatory, without reading the application code.

  4. Run a single tool call

    Send one user message to /api/chat with the tools field set, then inspect the response for a tool call entry naming the function and its arguments. Your application, not the model, must execute the function. Run the function with the arguments as returned, return its result to the model as a tool message, and request a final answer. Check that the final answer uses the returned data. Use the same prompt several times to see whether the model calls the tool consistently. The check is done when the tool is called with arguments that match the schema and the final answer reflects the tool result.

  5. Run a multi-tool turn

    Send a request that needs two or more tools, such as a question that requires a lookup and a calculation, and confirm the model can return more than one tool call in a single response. Your code should execute every returned call and send each result back with its matching tool message before the next model request. Confirm that the order and identifiers of results line up with the calls. Ollama's documentation and the OpenAI compatibility notes differ in details, so test the exact response shape your client library will parse. The check is done when all requested calls run and the final answer draws on every result.

  6. Confirm the loop terminates

    Build the application loop with a hard limit on the number of model round trips and a stop condition when the response contains no tool calls. Test a prompt that the model might answer forever by repeatedly calling tools, and confirm your code stops at the limit and returns a controlled error to the user. Log each round trip with its tool names and status so the behavior can be reviewed. The check is done when the loop ends on a normal answer and also ends on the limit during a forced test, with the error logged.

  7. Test malformed and unexpected arguments

    Deliberately send prompts that tempt the model toward wrong types, missing required values, out-of-range numbers, unknown tool names and instructions to call tools that do not exist. Validate every argument on the server side against the schema before running any function, and reject or reformat anything that fails. Confirm that a failed validation returns a clear error message to the model, and that the application never executes a tool it has not allowlisted. Repeat this set after each model or Ollama upgrade. Tool_choice is not supported on Ollama's OpenAI-compatible endpoint, so your application must enforce which tools are available for each request. The check is done when every invalid case is blocked or corrected, and the test set is saved as a regression suite.

Questions teams ask before building tool calling on Ollama

Does running tool calling on Ollama cost money?

Running models on your own hardware is free of per-token fees. Ollama's pricing page states that running models on your own hardware is always unlimited, and the paid plans it lists apply to cloud models. Your real cost is the hardware or cloud compute you already pay for, plus engineering time to define tool schemas, build the tool loop, and test it. Ask any partner for a quote that separates one-time build work from recurring work such as model upgrades, testing after changes, and support. Ollama's Enterprise plan is a separate purchase for model access controls and support, and only matters if you want the vendor's commercial terms.

How long does building tool calling on Ollama take?

No researched figure is available for build duration, so confirm it against your own scope. The main drivers are the number of tools, how many of them write data or touch sensitive systems, how many models you need to validate, and whether your application already has a tool execution loop. Tools that only read public data are quick to wire up. Tools that change records, trigger payments or access regulated data need permission checks, logging and tests that take longer. Ask for a timeline tied to a written list of tools and models.

What must our team provide before a tool calling build starts?

A partner can only design safe tool calling if you supply three inputs. First, a tool inventory: each function, its purpose, its parameters, and whether it reads or writes data. Second, an identity model that states which user or service account may call each tool and which data it may return. Third, test data and expected outcomes, including malicious or malformed prompts that should be refused. Without these, the work becomes guesswork about permissions, and the testing phase will expand.

Can our own engineers build tool calling on Ollama without a partner?

Yes, if your team already runs production services and can write and test code against a JSON-based API. The Ollama tool calling documentation describes the request and response shapes, and the Python and JavaScript SDKs handle much of the plumbing. The parts teams most often underestimate are authorization inside the tool functions, handling model errors, and regression testing when a model changes. A partner is most useful for a security review of those parts or for a fixed-scope build with written acceptance tests.

What does the missing tool_choice parameter mean for our code?

Ollama's OpenAI-compatible endpoint at /v1/chat/completions accepts the tools field but not tool_choice. Your code cannot force the model to call a specific tool or require any tool call through that parameter. Instead, enforce the behavior in your application: check the response for tool calls, validate them against an allowlist, and reject unexpected calls. If your client library sends tool_choice by default, test whether it is silently ignored. Use the native /api/chat endpoint if you need behavior that depends on how the model chooses tools.

Which Ollama models should we validate for tool calling?

Only models that support tool calling should be in scope, and support varies by model and version. Check the model's listing and the Ollama tool calling documentation before you commit to one. Test each candidate with your own tool inventory, including single calls, multiple calls in one turn, and calls with missing or wrong arguments. Record the results, because a model update can change behavior even when the tool schema stays the same.

What are the main security risks in a tool calling setup?

The model decides which tool to call, so a crafted prompt or document can push it toward a tool it should not use. Ollama's local API at localhost:11434 has no authentication by default, so any service that can reach it can also trigger tools. Protect the tool layer with server-side authorization for every call, least-privilege credentials for each tool, input validation, and audit logs of calls and results. Keep the Ollama API on a restricted network and place authentication in front of it if it is shared.

Security risks when a model can call your functions

A model that can call functions turns a text answer into an action against your systems. The risks below share one root: the model's output is shaped by untrusted input, and the Ollama API itself trusts whoever can reach it. Each card names a control to design in before tools go live.

Unauthenticated API behind a gateway

The local Ollama API at localhost:11434 does not require authentication. Ollama binds to 127.0.0.1 by default, and the bind address changes with OLLAMA_HOST. The FAQ describes exposing it through proxies such as Nginx, which means the proxy becomes the only authentication layer. Put tool-enabled endpoints behind an authenticated gateway, and confirm that nothing reaches port 11434 directly from user networks.

Ollama FAQ

Prompt injection steering tool choice

Text from documents, emails, web pages or chat messages can contain instructions that push the model toward a tool it should not use. Because the model decides which tool to call, any tool reachable from a user-supplied context is reachable by anyone who can place text in that context. Map which tools can be triggered by untrusted content and remove or gate the rest.

Arguments the model should not control

Tool arguments are generated by the model, so a malicious prompt can produce a value such as another customer's account ID, an unexpected file path or an oversized query. Validate every argument on the server side against a schema and an allowlist before execution. Do not pass model-generated strings into shell commands, SQL or file operations without parameterization.

Least-privilege tool credentials

A tool usually runs with a service credential, and that credential often has more rights than the requesting user. Give each tool its own identity with only the scopes it needs, and act on behalf of the user where the downstream system supports it. Keep credentials in a secrets manager, not in the Modelfile, the prompt or the application code, and rotate them on a schedule your security team sets.

Tool call logs without secrets

Logs of tool calls are needed for investigation, but they can capture API keys, personal data and sensitive prompt content if logged raw. Record the tool name, the caller identity, a timestamp, a validated argument summary and the outcome. Redact credential fields and decide with your privacy team how long prompt content is retained before you turn on verbose logging.

Cloud features and model provenance

Cloud features can be disabled with OLLAMA_NO_CLOUD=1 or the server configuration file, so a shared server does not silently send requests off-premises. Models pulled from outside your approved catalog may also carry unknown behavior around tool use. Pin approved model versions, disable cloud access where your policy requires it, and test each model's tool behavior before it is allowed to call a function.

Operating tool calling after go-live

Tool calling needs its own regression suite after go-live. Each tool schema in your registry should have fixed test prompts with expected tool names and argument shapes, run against the exact model tag your users call through /api/chat. Include cases where the model should not call a tool at all, since over-calling is as costly as a missed call. Ollama does not validate arguments against your schema for you, so your application must check each call's JSON before running anything. Ask your engineering team to confirm how the suite is triggered, who owns failing cases and where results are stored.

Plan a retest whenever Ollama or the model changes. Ollama ships frequent releases, with v0.40.5 released on 14 October 2026 and v0.40.6 published as a pre-release on 16 October 2026, so pin the server version and read the Ollama GitHub releases notes before upgrading. A new model tag or quantization can change how reliably a model emits tool calls, so rerun the full suite and compare results against the previous baseline. Keep the tools field behavior on your OpenAI-compatible path in the same test set, because tool_choice is not supported there and your code must not depend on it.

Monitor tool call rates, failures and loops in production. Log the tool name, call count per request, argument validation errors and tool execution errors, and alert when any of these shift after a change. Enforce a turn limit in your agent loop so a model that keeps requesting tools cannot run indefinitely, and stop with an explicit error when the limit is hit. Keep tool registries, schemas, system prompts and Modelfiles in version control so every production change can be traced to a commit and rolled back. Ask your platform team to confirm where logs are retained and who can read them, since tool arguments may contain personal or confidential data.

How DeployOpen scopes and delivers tool calling on Ollama

DeployOpen starts by fixing which models, endpoints and tools the function calling work covers, then builds and tests that path inside your infrastructure. Each engagement is fixed-scope, so the agreed endpoints, tool set and deliverables are written down before work begins.

How we scope

  • Inventory the tools your applications need and the systems each tool can reach.
  • Confirm which Ollama models you approve and test each one for tool calling support before design.
  • Record whether clients call /api/chat or the OpenAI-compatible tools field, and agree on tool_choice workarounds.

How we build

  • Implement the tool loop with single and multiple tool calls and test each tool's error handling.
  • Put an authenticated gateway in front of Ollama, since the local API does not require authentication.
  • Test tool permissions, argument validation and data exposure before anything reaches production.

How we hand over

  • Deliver documentation of the tool definitions, model list, endpoints, configuration and known gaps.
  • Walk your platform and security teams through the tool call logs and the retest results.
  • Record the Ollama version tested, so your team can plan upgrades against release notes.

How we support

  • Offer ongoing support, upgrades and continuous testing as a retainer after handover.
  • Retest tool calling behavior when Ollama releases change models, templates or the API.
  • Quote retainer scope from the written engagement, so recurring work is explicit before it starts.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.