fix(examples): raise ToolError instead of returning it in realtime_joke_teller#5904
Merged
Conversation
…ke_teller The framework's function-tool error contract is to raise ToolError so the error message is surfaced to the LLM. Returning the instance serializes it as an opaque value on the success path, so the LLM never learns the call failed. Also drop the bogus `| ToolError` return annotations.
davidzhao
approved these changes
May 30, 2026
theomonnom
approved these changes
May 30, 2026
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
get_weather,search_web, andtell_jokeinexamples/voice_agents/realtime_joke_teller.pyconstructedToolError(...)and returned it on exception.ToolErroris anExceptionsubclass and the framework's contract is to raise it so the message is surfaced to the LLM — returning serializes it as an opaque success value, and the LLM never learns the call failed.raise ToolError(...) from eand dropped the bogus| ToolErrorreturn annotations onget_weatherandtell_joke.Every other example in
examples/already usesraise ToolError(...)(drive-thru, frontdesk, healthcare, warm-transfer, web_search, telephony) — this file was the only outlier.Test plan
python examples/voice_agents/realtime_joke_teller.py consoleand trigger an error path (e.g. unreachable joke API / invalid city) — confirm the LLM responds to the failure instead of speaking a serialized object.