fix(llm): keep falsy tool return values in make_function_call_output#6551
Open
Osamaali313 wants to merge 1 commit into
Open
fix(llm): keep falsy tool return values in make_function_call_output#6551Osamaali313 wants to merge 1 commit into
Osamaali313 wants to merge 1 commit into
Conversation
`str(output or "")` collapsed valid falsy tool results — 0, False, 0.0, [],
{} — to an empty string, even though _is_valid_function_output explicitly
accepts int/float/bool and empty collections. A tool returning 0 therefore
sent "" to the model instead of "0", silently losing the answer.
Map only None to "" and stringify everything else, preserving the original
intent without over-catching falsy-but-valid values.
longcw
approved these changes
Jul 27, 2026
longcw
left a comment
Contributor
There was a problem hiding this comment.
looks good to me!
can you also fix the same idiom in voice/events.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
make_function_call_output(livekit/agents/llm/utils.py) builds the tool result sent back to the LLM with:_is_valid_function_outputin the same file explicitly acceptsint,float,bool, and empty collections as valid tool return values, butoutput or ""collapses every falsy value to"". So a tool that legitimately returns0,False,0.0,[], or{}has its result replaced by an empty string before it reaches the model.Falsy-return cases (verbatim logic slice):
0"""0"False"""False"0.0"""0.0"None""""5"5""5"FunctionCallOutput.outputis serialized to providers unchanged (OpenAItoolcontent, Anthropictool_result, …), so the empty string reaches the model and it loses the answer.Fix
Preserves the original intent (map
None→"") while correctly stringifying0,False,0.0, and empty collections. Non-falsy outputs are unchanged.I verified the behavior with a standalone slice of the function; I didn't add a unit test because the change sits in the live tool-execution path and the suite needs the full agents runtime — happy to add one if you'd like a spot for it.