Metadata-Version: 2.5
Name: llm-toolcall-check
Version: 0.1.0
Summary: Check whether an OpenAI-compatible LLM server handles tool calling correctly
Project-URL: Homepage, https://github.com/DipPansuriya/llm-toolcall-check
Project-URL: Issues, https://github.com/DipPansuriya/llm-toolcall-check/issues
Author: Dip Pansuriya
License-Expression: MIT
License-File: LICENSE
Keywords: function-calling,llama.cpp,llm,ollama,openai,testing,tool-calling,vllm
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# llm-toolcall-check

Check whether your local LLM server handles **tool calling** correctly.

Ollama, vLLM, llama.cpp, LM Studio and SGLang all offer an OpenAI-compatible API, but tool calling is where they
break most often: the tool call comes back as plain text, streamed arguments arrive broken, parallel calls get
merged, or `tool_choice` is ignored. Your agent then fails with an error that looks like the model's fault.

`llm-toolcall-check` sends a set of small, realistic requests and tells you exactly what went wrong, and **whose fault
it is**: the server's (a bug to report) or the model's (pick another model).

```console
$ llm-toolcall-check --server ollama --model qwen3:4b
Checking qwen3:4b at http://localhost:11434/v1 (3 runs per check)

  ✔ single              3/3  One tool call
  ✔ streaming           3/3  One tool call, streamed
  ✔ parallel            3/3  Two tool calls in one reply
  ✔ parallel-streaming  3/3  Two tool calls, streamed
  ✔ tool-result         3/3  Answer from a tool result
  ✔ no-tool             3/3  No tool call when none is needed
  ✖ choice-required     0/3  tool_choice 'required'
      server: ignored tool_choice 'required' and answered in text (3x)
  ✖ choice-named        0/3  tool_choice naming a function
      server: ignored tool_choice naming get_weather and answered in text (3x)
  ✖ choice-none         0/3  tool_choice 'none'
      server: ignored tool_choice 'none' and called a tool (3x)
  ✔ nested-arguments    3/3  Nested arguments (objects, arrays, enums)
  ✔ unicode             3/3  Non-ASCII arguments, streamed
  ✔ structured-output   3/3  response_format json_schema

Passed 9 of 12 checks.
Server problems in: choice-required, choice-named, choice-none. These are bugs to report to the server.
```

## Install

```sh
pip install llm-toolcall-check
```

Python 3.10 or newer. No dependencies.

## Usage

Start your server, then point `llm-toolcall-check` at it:

```sh
llm-toolcall-check --server ollama --model qwen3:4b
llm-toolcall-check --server vllm                     # uses the only model the server lists
llm-toolcall-check --base-url http://gpu-box:8000/v1 --model Qwen/Qwen3-8B
```

| Option | Meaning |
| --- | --- |
| `--server NAME` | Default local URL for `ollama`, `vllm`, `sglang`, `llama.cpp` or `lmstudio` |
| `--base-url URL` | Any OpenAI-compatible base URL (default: `$OPENAI_BASE_URL`, then Ollama) |
| `-m, --model NAME` | Model to test (default: the only model the server lists) |
| `--api-key KEY` | API key (default: `$LLM_TOOLCALL_CHECK_API_KEY`, then `$OPENAI_API_KEY`) |
| `-n, --runs N` | Runs per check (default: 3). Models are not fully deterministic, so failures show as `2/3` |
| `--only IDS`, `--skip IDS` | Comma-separated check ids, see `--list` |
| `--markdown` | Print a Markdown table you can paste into a bug report |
| `--json` | Print JSON |
| `--fail-on-model` | Also exit 1 when only the model made mistakes |
| `--timeout SECONDS` | Per request (default: 120) |

Exit codes: `0` no server problems, `1` server problems found, `2` the check could not run (for example the server
is not reachable).

## The checks

| Id | What it sends | What it catches |
| --- | --- | --- |
| `single` | "What's the weather in Paris?" with one tool | Tool call returned as text, missing `id`, `arguments` as an object instead of a string, wrong `finish_reason` |
| `streaming` | The same, with `stream: true` | Broken deltas, missing `index`, name sent twice, no `[DONE]` |
| `parallel` | Two cities in one question | Calls merged into one, duplicate ids |
| `parallel-streaming` | The same, streamed | Arguments of two calls glued together |
| `tool-result` | A conversation with a tool result | Server rejects `role: tool` or `content: null` |
| `no-tool` | A question that needs no tool | Model calls tools anyway |
| `choice-required` | `tool_choice: "required"` | Server ignores it |
| `choice-named` | `tool_choice` naming one function | Server ignores it or calls another tool |
| `choice-none` | `tool_choice: "none"` | Server still calls tools, or leaks raw tool markup |
| `nested-arguments` | A tool with objects, arrays and enums | Arguments that don't match the schema |
| `unicode` | "Zürich", streamed | Mangled non-ASCII text such as `ZÃ¼rich` or `\u00fc` |
| `structured-output` | `response_format: json_schema` | Server doesn't enforce the schema |

Every response is also scanned for raw template tokens such as `<tool_call>`, `[TOOL_CALLS]`, `<|python_tag|>` or
`<|im_end|>`, which mean the server's parser missed something.

### Server problem or model problem?

- **server**: the server broke the OpenAI API contract. The model may have produced a perfect tool call, but the
  server returned it as text, mangled it while streaming, or ignored a request option. Report these to the server
  project; `--markdown` gives you a ready table.
- **model**: the server did its job, but the model chose badly: no tool call, the wrong tool, or arguments that
  don't match the schema. Try a bigger model or a different quantization.

## Same model, different servers

Qwen3 4B (Q4_K_M), 3 runs per check, November 2026:

| Check | Ollama 0.40.18 | llama.cpp 1.1.0 (`--jinja`) |
| --- | --- | --- |
| single, streaming, parallel, tool-result, no-tool | ✔ | ✔ |
| choice-required | ✖ ignored | ✔ |
| choice-named | ✖ ignored | ✔ |
| choice-none | ✖ still calls tools | ✖ tool call leaks into `content` as `<tool_call>…` |
| nested-arguments, unicode, structured-output | ✔ | ✔ |

Both are known upstream: [ollama#17921](https://github.com/ollama/ollama/issues/17921) and
[llama.cpp#30434](https://github.com/ggml-org/llama.cpp/pull/30434).

## Use in CI

Test a model and server combination before you deploy it:

```yaml
- run: pip install llm-toolcall-check
- run: llm-toolcall-check --base-url http://localhost:8000/v1 --model my-model --markdown >> "$GITHUB_STEP_SUMMARY"
```

## How it works

`llm-toolcall-check` talks to `/v1/chat/completions` with the Python standard library and looks at the raw JSON, not at
what an SDK makes of it. Streamed replies are put back together the way the OpenAI SDKs do it (string fields are
concatenated), so it reports what your agent would actually see. Requests use `temperature: 0`.

Nothing is sent anywhere except the server you point it at.

## License

MIT
