Skip to content

[BFCL] Fix silent drop of text responses when tool_calls is empty list - #1328

Open
shubhra wants to merge 1 commit into
ShishirPatil:mainfrom
shubhra:fix/handle-empty-tool-calls-list
Open

[BFCL] Fix silent drop of text responses when tool_calls is empty list#1328
shubhra wants to merge 1 commit into
ShishirPatil:mainfrom
shubhra:fix/handle-empty-tool-calls-list

Conversation

@shubhra

@shubhra shubhra commented Apr 23, 2026

Copy link
Copy Markdown

When an OpenAI-compatible server (e.g. vLLM) returns "tool_calls": [] instead of "tool_calls": null for a text-only response, _parse_query_response_FC iterated over the empty list successfully, producing model_responses = [] and silently discarding the actual text in message.content. This broke all agentic and multi-turn tasks where the model needs to return a final text answer after using tools.

Replace the try/except (which relied on TypeError from iterating over None) with an explicit truthiness check. Both None and [] produce false, so the else branch now correctly falls back to message.content in either case. A populated tool_calls list is processed as before - no regressions for the normal path.

When an OpenAI-compatible server (e.g. vLLM) returns `"tool_calls": []`
instead of `"tool_calls": null` for a text-only response,
`_parse_query_response_FC` iterated over the empty list successfully,
producing `model_responses = []` and silently discarding the actual text
in `message.content`. This broke all agentic and multi-turn tasks where
the model needs to return a final text answer after using tools.

Replace the fragile `try/except` (which relied on `TypeError` from
iterating over `None`) with an explicit truthiness check. Both `None`
and `[]` are falsy, so the `else` branch now correctly falls back to
`message.content` in either case. A populated tool_calls list is truthy
and is processed as before — no regressions for the normal path.

Made-with: Cursor
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.

1 participant