Skip to content

fix(openai): yield tool calls with invalid JSON instead of silently dropping#223

Open
mkaaad wants to merge 1 commit intocharmbracelet:mainfrom
mkaaad:fix/invalid-json-tool-call
Open

fix(openai): yield tool calls with invalid JSON instead of silently dropping#223
mkaaad wants to merge 1 commit intocharmbracelet:mainfrom
mkaaad:fix/invalid-json-tool-call

Conversation

@mkaaad
Copy link
Copy Markdown

@mkaaad mkaaad commented May 1, 2026

Summary

• Yield tool calls with invalid JSON arguments instead of silently dropping them, so the
agent can report errors back to the model

After the Agent fails the validation in validateAndRepairToolCall, it marks Invalid = true and returns the validation error to the model in the form of a tool result message, allowing the model to correct it automatically.

• Add test coverage for invalid JSON tool call handling

Test plan

[✓] Existing tests pass ( go test ./providers/openai/... )
[✓] New test "should drop tool calls with invalid JSON arguments" validates that
invalid JSON tool calls are yielded with correct deltas and finish reason

…ropping

Previously, tool calls with invalid JSON arguments were silently dropped
in the stream, preventing the agent from reporting the error back to the
model. Now all tool calls are yielded regardless of argument validity,
and the agent handles validation via its existing repair/error flow.

Additionally, track hasYieldedToolCall to map finishReason correctly:
use tool_calls only when a tool call was actually yielded, and fall back
to stop when no tool call was yielded despite the API saying tool_calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants