Skip to content

fix(client): format string system messages in anthropic adapter - #16316

Merged
axiomofjoy merged 2 commits into
Arize-ai:mainfrom
Anurag-M1:fix/anthropic-system-message-variables
Sep 25, 2026
Merged

axiomofjoy merged 2 commits into
Arize-ai:mainfrom
Anurag-M1:fix/anthropic-system-message-variables

Conversation

@Anurag-M1

Copy link
Copy Markdown
Contributor

fixes #16228

Description

In packages/phoenix-client/src/phoenix/client/helpers/sdk/anthropic/messages.py, to_chat_messages_and_kwargs appended string system messages (message["content"]) verbatim without running them through formatter.format(..., variables=variables).

As a result, when formatting prompt versions for Anthropic (to_chat_messages_and_kwargs or PromptVersion.format(sdk="anthropic")), variables in string system messages (e.g. You are {{ persona }}.) were ignored and sent as literal templates in kwargs["system"], while non-system messages and multi-part system messages had their variables formatted properly.

This PR routes string system message content through formatter.format(message["content"], variables=variables) in the Anthropic adapter, aligning it with:

  • Anthropic multi-part system messages (_ContentConversion.to_anthropic -> _TextContentPartConversion.to_anthropic)
  • Non-system message formatting (_MessageConversion.to_anthropic)
  • OpenAI chat adapter (_SystemMessageConversion.to_openai)
  • Google GenAI adapter (generate_content.py)

Testing

  • Added regression tests in packages/phoenix-client/tests/canary/sdk/anthropic/test_messages.py testing single string system messages with variables, multiple system messages, and PromptVersion.format(..., sdk="anthropic").
  • Verified all 28 tests in packages/phoenix-client/tests/canary/sdk/anthropic/test_messages.py pass.
  • Verified all 785 tests across client test suites pass.
  • Verified make lint-python and make typecheck-python pass cleanly with zero errors.

Contributor License Agreement (CLA)

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

@Anurag-M1
Anurag-M1 requested a review from a team as a code owner September 19, 2026 07:20
@github-project-automation github-project-automation Bot moved this to 📘 Todo in phoenix Sep 19, 2026
@github-actions github-actions Bot added the triage issues that need triage label Sep 19, 2026
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

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

@Anurag-M1

Copy link
Copy Markdown
Contributor 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 19, 2026
@ehutt ehutt removed the triage issues that need triage label Sep 21, 2026
@axiomofjoy axiomofjoy assigned axiomofjoy and unassigned RogerHYang Sep 25, 2026
@axiomofjoy
axiomofjoy enabled auto-merge (squash) September 25, 2026 22:22
@axiomofjoy
axiomofjoy disabled auto-merge September 25, 2026 23:04
@axiomofjoy
axiomofjoy enabled auto-merge (squash) September 25, 2026 23:12
@axiomofjoy
axiomofjoy merged commit 435de9b into Arize-ai:main Sep 25, 2026
50 checks passed
@github-project-automation github-project-automation Bot moved this from 👍 Approved to ✅ Done in phoenix Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

[BUG]: Anthropic prompt adapter ignores {{ variables }} in str system messages, sending the literal template as the system kwarg

4 participants