Skip to content

fix: treat hallucinated tool names as client-side function calls - #5043

Merged
leseb merged 3 commits into
ogx-ai:mainfrom
mattf:issue-4781-hallucinated-tool-calls
Mar 10, 2026
Merged

fix: treat hallucinated tool names as client-side function calls#5043
leseb merged 3 commits into
ogx-ai:mainfrom
mattf:issue-4781-hallucinated-tool-calls

Conversation

@mattf

@mattf mattf commented Mar 4, 2026

Copy link
Copy Markdown
Collaborator

When the LLM called a tool name that was not registered as a function tool, a built-in (web_search/knowledge_search), or an MCP tool, the server raised a ValueError from _coordinate_tool_execution which propagated as a 500 InternalServerError.

The classification in _separate_tool_calls was implicitly routing any unrecognised name into non_function_tool_calls, which coordinate_tool execution had no branch for and therefore crashed on.

Fix by adding an elif in _separate_tool_calls: if a tool call name is not a known server-side built-in and not an MCP tool, it is classified as a function_call and returned to the client as a completed output item. This matches OpenAI's behaviour and lets the caller inspect or ignore the hallucinated call without the response failing.

Also introduce _SERVER_SIDE_BUILTIN_TOOL_NAMES to centralise the set of names the server executes itself, replacing an inline list literal at the one other membership-test site.

closes #4781

When the LLM called a tool name that was not registered as a function
tool, a built-in (web_search/knowledge_search), or an MCP tool, the
server raised a ValueError from _coordinate_tool_execution which
propagated as a 500 InternalServerError.

The classification in _separate_tool_calls was implicitly routing any
unrecognised name into non_function_tool_calls, which _coordinate_tool_
execution had no branch for and therefore crashed on.

Fix by adding an elif in _separate_tool_calls: if a tool call name is
not a known server-side built-in and not an MCP tool, it is classified
as a function_call and returned to the client as a completed output item.
This matches OpenAI's behaviour and lets the caller inspect or ignore the
hallucinated call without the response failing.

Also introduce _SERVER_SIDE_BUILTIN_TOOL_NAMES to centralise the set of
names the server executes itself, replacing an inline list literal at the
one other membership-test site.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 4, 2026
@mattf
mattf marked this pull request as ready for review March 4, 2026 16:29
@franciscojavierarceo
franciscojavierarceo added this pull request to the merge queue Mar 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 5, 2026
@mattf

mattf commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator Author

@jwm4 @hmoghani please confirm this resolves your issue

@skamenan7 skamenan7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM apart a nit, thanks!

logger = get_logger(name=__name__, category="agents::meta_reference")
tracer = trace.get_tracer(__name__)

# Built-in tool names that the server knows how to execute itself.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: is there a single place where built-in tools are registered that we could derive this from, rather than keeping a hardcoded set? if someone adds a new built-in later and misses updating this, it will silently get treated as a hallucinated call. even a comment pointing to where web_search / knowledge_search are registered would help future-proof it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

that would be a useful refactor. the way we go from built-in to the backend tool is complex too.

@leseb leseb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@leseb
leseb merged commit 72bba2d into ogx-ai:main Mar 10, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Responses API returns 500 error when model hallucinates unsupported tool call

4 participants