Skip to content

fix(openai): handle tool calls with empty/null arguments#4060

Merged
markbackman merged 1 commit intopipecat-ai:mainfrom
alpsencer:fix/empty-tool-call-arguments
Mar 27, 2026
Merged

fix(openai): handle tool calls with empty/null arguments#4060
markbackman merged 1 commit intopipecat-ai:mainfrom
alpsencer:fix/empty-tool-call-arguments

Conversation

@alpsencer
Copy link
Copy Markdown
Contributor

Fixes #4059

Problem

When an LLM returns a streaming tool call with no arguments (arguments=null in the delta chunks), the tool call is silently dropped. This affects all OpenAI-compatible providers that don't send arguments: "{}" for parameterless tools, including vLLM (with Qwen, Llama, Mistral), Ollama, and others.

Root cause in BaseOpenAILLMService._process_context:

  1. tool_call.function.arguments is None → nothing accumulated → arguments stays ""
  2. if function_name and arguments:"" is falsy → tool call execution skipped entirely
  3. No error or warning logged — completely silent failure

OpenAI masks this because it always sends arguments: "{}" even for tools with zero parameters.

Fix

Three lines changed:

  • Line 535: arguments_list.append(arguments)arguments_list.append(arguments or "{}") (intermediate tool calls in multi-tool responses)
  • Line 561: if function_name and arguments:if function_name: (final tool call check)
  • Line 564: arguments_list.append(arguments)arguments_list.append(arguments or "{}") (final tool call append)

Empty arguments default to "{}" so json.loads produces {}. No behavior change for OpenAI or any provider that already sends "{}".

Testing

Verified with vLLM serving Qwen3-VL-235B with --enable-auto-tool-choice --tool-call-parser hermes. Before this fix, end_call tool calls were silently dropped. After, they execute correctly with empty arguments.

When an LLM returns a tool call with no arguments (arguments=null in
the streaming chunks), the tool call is silently dropped because:

1. `tool_call.function.arguments` is None, so nothing is accumulated
   and `arguments` stays as "" (empty string)
2. `if function_name and arguments:` treats "" as falsy, skipping the
   entire tool call execution

OpenAI always sends arguments="{}" even for parameterless tools,
masking this bug. But vLLM, Ollama, and other OpenAI-compatible
providers may omit arguments entirely when the tool schema has no
required parameters, causing tool calls to be silently ignored.

Fix: check only `function_name` (not `arguments`) and default empty
arguments to "{}" so `json.loads` produces an empty dict. Apply the
same fallback for intermediate tool calls in multi-tool responses.
Copy link
Copy Markdown
Contributor

@markbackman markbackman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the well-written issue and clean fix.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pipecat/services/openai/base_llm.py 33.33% 2 Missing ⚠️
Files with missing lines Coverage Δ
src/pipecat/services/openai/base_llm.py 58.06% <33.33%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@markbackman markbackman merged commit eee47de into pipecat-ai:main Mar 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool calls with empty/null arguments silently dropped (affects vLLM, Ollama, and other OpenAI-compatible providers)

2 participants