fix: drop empty tool_calls arrays on assistant messages (strict providers 400) - #82252
fix: drop empty tool_calls arrays on assistant messages (strict providers 400)#82252prateekranka wants to merge 1 commit into
Conversation
…ders 400) DeepSeek and other strict providers reject assistant messages carrying tool_calls: [] as a 400 error. The pre-call sanitizer dedups duplicate tool_call_ids; when every call in a turn was a duplicate, the result was an empty tool_calls array that the early sanitizer pass had already run on. Drop the key entirely in that case, and add a final pass that removes any surviving empty tool_calls arrays before send.
|
This was generated by AI during triage. Summary: Problems:
Solution: Checked against |
Duplicate of #64345: both remove |
|
The empty- |
Problem
DeepSeek (and other strict OpenAI-compatible providers) rejects assistant messages carrying
tool_calls: []with an HTTP 400 (tool_callsmust be a non-empty array or absent).This happens in
sanitize_api_messages: the pre-call sanitizer dedups duplicatetool_call_ids across assistant/tool pairs. When every tool call in a turn was a duplicate id, the dedup lefttool_calls: []on the assistant message — and the earlier sanitizer pass that drops empty arrays had already run, so the empty array reached the wire.Fix
tool_callskey entirely instead of leaving[].tool_calls: []on assistant messages (belt-and-braces for other paths that can produce the same shape).Verification
Reproduced locally with DeepSeek as the primary provider: 400 on
tool_calls: []before the change; long-running sessions with duplicate-id turns proceed cleanly after. Existing sanitizer behavior for non-empty calls is unchanged.