Skip to content

fix(llm): keep falsy tool return values in make_function_call_output#6551

Open
Osamaali313 wants to merge 1 commit into
livekit:mainfrom
Osamaali313:fix-tool-output-falsy-values
Open

fix(llm): keep falsy tool return values in make_function_call_output#6551
Osamaali313 wants to merge 1 commit into
livekit:mainfrom
Osamaali313:fix-tool-output-falsy-values

Conversation

@Osamaali313

Copy link
Copy Markdown

Summary

make_function_call_output (livekit/agents/llm/utils.py) builds the tool result sent back to the LLM with:

output=str(output or ""),

_is_valid_function_output in the same file explicitly accepts int, float, bool, and empty collections as valid tool return values, but output or "" collapses every falsy value to "". So a tool that legitimately returns 0, False, 0.0, [], or {} has its result replaced by an empty string before it reaches the model.

@function_tool
async def items_in_cart() -> int:
    return 0   # the model receives "" instead of "0"

Falsy-return cases (verbatim logic slice):

tool returns current fixed
0 "" "0"
False "" "False"
0.0 "" "0.0"
None "" ""
5 "5" "5"

FunctionCallOutput.output is serialized to providers unchanged (OpenAI tool content, Anthropic tool_result, …), so the empty string reaches the model and it loses the answer.

Fix

output="" if output is None else str(output),

Preserves the original intent (map None"") while correctly stringifying 0, 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.

`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.
Copilot AI review requested due to automatic review settings July 26, 2026 20:29
@Osamaali313
Osamaali313 requested a review from a team as a code owner July 26, 2026 20:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@CLAassistant

CLAassistant commented Jul 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@longcw longcw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me!

can you also fix the same idiom in voice/events.py

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.

4 participants