Skip to content
Source
Sign inSign up
TanStack/ai

openai-base: malformed Chat Completions tool arguments execute as an empty object #1601

ClosedL-1ngg(GitHub profile, opens in a new tab) opened this issue 0 comments

TanStack AI version

  • @tanstack/ai: 0.63.0
  • @tanstack/ai-openai: 0.25.1
  • @tanstack/openai-base: 0.12.1

Reproduced against repository source at b97c174035ccb500b886f1cdaf82f816eed7c8d8. The versions above come from that checkout. Published npm bundles were not tested separately.

Framework/Library version

No UI framework. Node.js 24.14.1, pnpm 11.9.0, Vitest 4.1.10, OpenAI SDK 6.41.0, and Zod 4.3.6.

Describe the bug and the steps to reproduce it

Chat Completions can execute a tool after its streamed arguments fail JSON parsing. The adapter supplies TOOL_CALL_END.input: {}, which replaces the original arguments before the core parses them.

A tool with z.object({ path: z.string().optional() }) accepts the replacement object. Its handler runs with {} despite the invalid original input.

This contradicts the documented tool error behavior: malformed JSON produces a tool-result error without calling the tool implementation.

Steps to reproduce

  1. Use a fresh checkout at b97c174035ccb500b886f1cdaf82f816eed7c8d8.
  2. Run pnpm install --frozen-lockfile.
  3. Place the linked reproduction files in repro-adapters/ at the repository root.
  4. Run:
pnpm exec vitest run --config repro-adapters/vite.config.mjs

The reproduction calls public chat() through the real OpenAI SDK with a controlled SSE response. It supplies a named tool call whose arguments are {"path":.

Two cases cover normal finish_reason: "tool_calls" and body EOF without a finish reason. The normally terminated case demonstrates that missing stream completion is not required for this failure.

Actual behavior

Both malformed cases call the local tool once with {}. The next model request contains a successful tool result, with no argument parse error.

Three controls cover {}, an empty argument string, and {"path":"chosen"}. They all execute with the expected input.

Expected behavior

Return a tool-result error for malformed JSON without calling the tool. Let the agent loop send that error to the model so it can repair the call.

The schema can accept {} without accepting malformed JSON. Runtime schemas with required fields can block some replacement objects, but optional fields make this failure observable.

Cause

  • Both normal completion and EOF drain retain {} after a parse failure.
  • completeToolCall serializes that completed input over the original argument string.
  • The core then receives valid JSON, so its existing malformed-argument error path cannot detect the failure.

Related work

#1131 and #1134 establish recovery through a tool error. This adapter fallback replaces the invalid string before that check.

#545 added logging for this fallback. #1481 explicitly mentions {} as the value that execution receives. This report targets the malformed-input fallback, while preserving authoritative completed input for successful normalization.

The fixtures use a local no-op tool and make no provider network requests. They establish the adapter behavior, not live model frequency.

Complete reproduction files and commands

Do you intend to try to help solve this bug with your own PR?

Yes, I am also opening a PR that solves the problem along side this issue

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
  1. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

  2. tombeckenham closed this

Sign in to join this conversation.