Skip to content

fix(vertexai): concatenate anthropic system prompt text parts without commas - #7218

Closed
anjalimishra-0007 wants to merge 1 commit into
genkit-ai:mainfrom
anjalimishra-0007:fix/vertexai-anthropic-system-prompt-join
Closed

anjalimishra-0007 wants to merge 1 commit into
genkit-ai:mainfrom
anjalimishra-0007:fix/vertexai-anthropic-system-prompt-join

Conversation

@anjalimishra-0007

Copy link
Copy Markdown

Fixes #7167.

Description

In Model Garden Anthropic converters (js/plugins/vertexai/src/modelgarden/v2/anthropic.ts and legacy/anthropic.ts), system message parts were joined using msg.content.map((c) => c.text).join(). Because Array.prototype.join() defaults to a comma separator when called without arguments, system messages containing multiple parts (such as prompt system instructions combined with schema formatting instructions from injectInstructions) ended up containing stray commas in the final system prompt sent to Anthropic Claude models.

This changes .join() to .join(''), matching the behavior of Mistral converters (v2/mistral.ts), Ollama (#7124), and Genkit Message.text.

Scenarios Tested

  • Added unit regression tests in both:
    • js/plugins/vertexai/tests/modelgarden/v2/anthropic_test.ts
    • js/plugins/vertexai/tests/modelgarden/legacy/anthropic_test.ts
      verifying that multi-part system messages are concatenated cleanly without commas.
  • Ran all 17 tests across the test suites — all passed.
  • Prettier and copyright checks passed via pre-commit hooks.

… commas

In Model Garden Anthropic converters (both v2 and legacy), system message parts were joined using Array.prototype.join() with no argument, which inserts commas between text parts. This causes system prompts with multiple parts (e.g. system instructions combined with schema formatting instructions) to contain stray commas.

Change .join() to .join('') to match Mistral and Genkit Message.text conventions.

Fixes genkit-ai#7167

Signed-off-by: Anjali Mishra <246823347+anjalimishra-0007@users.noreply.github.com>

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request fixes an issue where multiple system message text parts were joined with commas by changing .join() to .join('') in both the legacy and v2 Anthropic model garden plugins. Corresponding unit tests have been added to verify that system messages are concatenated without commas. I have no additional feedback to provide.

@MichaelDoyle

Copy link
Copy Markdown
Contributor

Closing as duplicate: #7167 already has an earlier open PR in #7214.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JS] vertexai Model Garden Anthropic joins system prompt parts with commas

2 participants