Skip to content

fix(py/anthropic): keep every system message in the request - #7073

Closed
pcbeingused33 wants to merge 1 commit into
genkit-ai:mainfrom
pcbeingused33:fix/anthropic-multiple-system
Closed

pcbeingused33 wants to merge 1 commit into
genkit-ai:mainfrom
pcbeingused33:fix/anthropic-multiple-system

Conversation

@pcbeingused33

Copy link
Copy Markdown

AnthropicModel._extract_system returned as soon as it found the first system message, so a request with several system messages sent only the first one to Anthropic and silently dropped the rest. The Gemini and Bedrock plugins already accumulate all of them.

Fix: collect the text of every system message, in order, and join them with a blank line.

Test: test_extract_system_keeps_all_system_messages uses two system messages around a user message and expects both in the result. It fails before the change and passes after.


Disclosure: this change was prepared with AI assistance (Claude Code).

_extract_system returned at the first system message, so any later system
messages were dropped silently. Collect the text of all system messages in
order and join them with blank lines, as the Gemini and Bedrock plugins do.

@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 updates the _extract_system method in the Anthropic model implementation to extract and concatenate text from all system messages (separated by double newlines) rather than only returning the first one. A corresponding unit test has been added to verify this behavior. I have no feedback to provide.

@MichaelDoyle

Copy link
Copy Markdown
Contributor

Hi @pcbeingused333 — heads up that Genkit Python SDK development has moved to https://github.com/genkit-ai/genkit-python! Could you re-open this PR over there (file paths map 1:1 after stripping the leading py/ prefix), and link/close this PR once moved? cc @huangjeff5

@pcbeingused33

Copy link
Copy Markdown
Author

Moved to genkit-ai/genkit-python#146 as requested; closing this one.

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.

2 participants