Skip to content

fix(client): keep tools when anthropic tool_choice is none - #16535

Merged
cephalization merged 1 commit into
Arize-ai:mainfrom
BlueX888:fix/prep-anthropic-tool-choice-none-drops-tools
Oct 6, 2026
Merged

cephalization merged 1 commit into
Arize-ai:mainfrom
BlueX888:fix/prep-anthropic-tool-choice-none-drops-tools

Conversation

@BlueX888

Copy link
Copy Markdown

Related to #6662 (tool_choice: none support for Anthropic, delivered for the playground in #15683). No separate issue was filed for this client-side gap.

Summary

to_chat_messages_and_kwargs dropped the entire tools list from the replayed request when a stored Anthropic prompt had tool_choice: none, so a request captured with tools but tool use disabled replayed without any tools.

Why

_ToolKwargsConversion.to_anthropic in packages/phoenix-client/src/phoenix/client/helpers/sdk/anthropic/messages.py:513-514 returned an empty dict as soon as the stored tool choice was "none":

if "tool_choice" in obj:
    if obj["tool_choice"]["type"] == "none":
        return {}

ans["tools"] was already set at that point, so the early return discarded it along with the tool choice. _ToolChoiceConversion.to_anthropic (same file, lines 560-561) already maps "none" to {"type": "none"}, and _ToolChoiceConversion.from_anthropic (lines 612-613) already accepts it, so the early return bypassed existing handling on one side of a round trip that otherwise works. The server-side playground sends tool_choice: none together with the tools for the same stored prompt (src/phoenix/server/api/helpers/playground_clients.py:2253-2254 and :2276-2278), so capture and replay must round-trip both.

Changes

  • Removed the early return {} in _ToolKwargsConversion.to_anthropic so the existing _ToolChoiceConversion.to_anthropic mapping emits {"type": "none"} while tools is kept.
  • Added a tool_choice: {"type": "none"} case to the TestToolKwargs round-trip parametrization.
  • Added TestToolKwargs.test_tool_choice_none_keeps_tools, which captures a request with tools and tool_choice: none via create_prompt_version_from_anthropic and asserts to_chat_messages_and_kwargs returns both.

Testing

On the unpatched tree the two new tests fail (to_anthropic returns {}; kwargs.get("tools") is None). With the fix, from packages/phoenix-client/:

$ pytest --disable-socket tests/canary/sdk/anthropic
27 passed
$ pyright -p src/phoenix/client/helpers/sdk/pyrightconfig.json src/phoenix/client/helpers/sdk/anthropic
0 errors, 0 warnings, 0 informations
$ pyright -p tests/canary/sdk/pyrightconfig.json tests/canary/sdk/anthropic
0 errors, 0 warnings, 0 informations
$ mypy --strict --follow-untyped-imports src/phoenix/client/helpers/sdk/anthropic/messages.py
Success: no issues found in 1 source file
$ mypy --strict --follow-untyped-imports tests/canary/sdk/anthropic/test_messages.py
Success: no issues found in 1 source file
$ ruff format --check src/phoenix/client/helpers/sdk/anthropic/messages.py tests/canary/sdk/anthropic/test_messages.py
2 files already formatted
$ ruff check src/phoenix/client/helpers/sdk/anthropic/messages.py tests/canary/sdk/anthropic/test_messages.py
All checks passed!
$ pytest --disable-socket tests/client
744 passed, 7 failed, 1 xfailed, 103 errors — identical to unpatched main (pre-existing executor/rate-limiter/pytest-plugin failures on this machine, unrelated to this change)

I have read the CLA Document and I hereby sign the CLA.

@BlueX888
BlueX888 requested a review from a team as a code owner September 25, 2026 21:04
@github-project-automation github-project-automation Bot moved this to 📘 Todo in phoenix Sep 25, 2026
@github-actions github-actions Bot added the triage issues that need triage label Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@BlueX888
BlueX888 force-pushed the fix/prep-anthropic-tool-choice-none-drops-tools branch from ea3d7b7 to df346ee Compare September 26, 2026 03:42
@BlueX888

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Sep 28, 2026
@cephalization cephalization added bug Something isn't working c/client language: python Issues with python as the primary language of use and removed triage issues that need triage labels Oct 5, 2026
@cephalization
cephalization self-requested a review October 5, 2026 16:31
@cephalization
cephalization enabled auto-merge (squash) October 6, 2026 14:00
_ToolKwargsConversion.to_anthropic returned an empty dict when the
stored prompt's tool_choice was "none", dropping the tools list from
the replayed request even though _ToolChoiceConversion.to_anthropic
already maps "none" to {"type": "none"}. Let that mapping run so a
captured prompt replays with both tools and tool_choice.
@cephalization
cephalization force-pushed the fix/prep-anthropic-tool-choice-none-drops-tools branch from df346ee to e51d2a0 Compare October 6, 2026 14:42
@cephalization
cephalization merged commit 8ce05ec into Arize-ai:main Oct 6, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working c/client language: python Issues with python as the primary language of use

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants