Remove spurious 'single system message' warning from Anthropic provider#768
Merged
crmne merged 1 commit intoMay 12, 2026
Merged
Conversation
The build_system_content method already serializes multiple :system messages into Anthropic's `system: [...]` content-block array correctly (preserving per-block cache_control). The warning predates that support and is now misleading -- applications that intentionally split system content into separate blocks (e.g. a static cached prefix + a per-conversation envelope) get spurious log spew on every request. Match the Bedrock provider, which handles the same case without warning. Adds unit coverage for build_system_content directly: zero/one/two messages, the no-warn assertion, cache_control round-trip, and mixed Raw + plain string content. Fixes crmne#767
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #768 +/- ##
==========================================
+ Coverage 87.04% 87.05% +0.01%
==========================================
Files 119 119
Lines 5596 5594 -2
Branches 1409 1407 -2
==========================================
- Hits 4871 4870 -1
+ Misses 725 724 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Removes a stale
RubyLLM.logger.warn(...)call inAnthropic::Chat#build_system_contentthat fires on every request whenever a chat carries more than one:system-role message. The warning claims Anthropic only supports a single system message and that the gem will merge them -- neither is still true. Anthropic'ssystemparameter has accepted an array of text content blocks (with per-blockcache_control) since the prompt-caching launch in August 2024 (GA December 2024), and the gem already serializes correctly viaflat_mapoverMedia.format_content. Only the warning is stale.At high request volume the warning floods logs for applications that intentionally split system content into a cached prefix + a per-conversation envelope. The Bedrock provider (
lib/ruby_llm/providers/bedrock/chat.rb) handles the same case without warning, so this also aligns the two providers.Adds direct unit coverage for
build_system_content:[]for zero messages:systemmessages are passedcache_controlon aContent::Rawblock when paired with a plain-text blockContent::Raw+ plain-string content correctlyFixes #767.
References:
system: string | array of text content blockscache_controlon system blocks: https://docs.anthropic.com/en/docs/build-with-claude/prompt-cachinganthropic-sdk-pythonshipssystem: Union[str, Iterable[TextBlockParam]]Type of change
Scope check
Required for new features
Quality check
overcommit --installand all hooks passbundle exec rake vcr:record[provider_name](N/A -- this change is wire-format-neutral; no provider request/response shape changed, so existing cassettes still match)bundle exec rspec spec/ruby_llm/providers/anthropic/chat_spec.rb(13 examples, 0 failures -- 6 new + 7 existing) andbundle exec rspec spec/ruby_llm/providers/anthropic_spec.rb(2 examples, 0 failures)models.json,aliases.json)AI-generated code
API changes