From 313fc7db32ca0a2259508b9f9b82ee7a96a177b8 Mon Sep 17 00:00:00 2001 From: Jessica Alder Date: Wed, 11 Feb 2026 13:33:45 -0800 Subject: [PATCH] Fix Anthropic system prompt not captured in traces The Anthropic Ruby SDK uses `system_:` (with trailing underscore) as the keyword argument name because `system` is a reserved method in Ruby (Kernel#system). The instrumentation was checking for `params[:system]` which never matched, causing system prompts to be silently dropped from Braintrust traces. Update both messages.rb and beta_messages.rb to use `params[:system_]` to match the official Anthropic Ruby SDK semantics. --- .../contrib/anthropic/instrumentation/beta_messages.rb | 4 ++-- lib/braintrust/contrib/anthropic/instrumentation/messages.rb | 4 ++-- .../contrib/anthropic/instrumentation/messages_test.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/braintrust/contrib/anthropic/instrumentation/beta_messages.rb b/lib/braintrust/contrib/anthropic/instrumentation/beta_messages.rb index 8b9aca9..1dba91a 100644 --- a/lib/braintrust/contrib/anthropic/instrumentation/beta_messages.rb +++ b/lib/braintrust/contrib/anthropic/instrumentation/beta_messages.rb @@ -169,8 +169,8 @@ def set_input(span, params) input_messages = [] begin - if params[:system] - system_content = params[:system] + if params[:system_] + system_content = params[:system_] if system_content.is_a?(Array) system_text = system_content.map { |blk| blk.is_a?(Hash) ? blk[:text] : blk diff --git a/lib/braintrust/contrib/anthropic/instrumentation/messages.rb b/lib/braintrust/contrib/anthropic/instrumentation/messages.rb index 5512c07..ab112fc 100644 --- a/lib/braintrust/contrib/anthropic/instrumentation/messages.rb +++ b/lib/braintrust/contrib/anthropic/instrumentation/messages.rb @@ -98,8 +98,8 @@ def build_metadata(params, stream: false) def set_input(span, params) input_messages = [] - if params[:system] - system_content = params[:system] + if params[:system_] + system_content = params[:system_] if system_content.is_a?(Array) system_text = system_content.map { |blk| blk.is_a?(Hash) ? blk[:text] : blk diff --git a/test/braintrust/contrib/anthropic/instrumentation/messages_test.rb b/test/braintrust/contrib/anthropic/instrumentation/messages_test.rb index 50e087b..12f09aa 100644 --- a/test/braintrust/contrib/anthropic/instrumentation/messages_test.rb +++ b/test/braintrust/contrib/anthropic/instrumentation/messages_test.rb @@ -130,7 +130,7 @@ def test_handles_system_prompt message = client.messages.create( model: "claude-sonnet-4-20250514", max_tokens: 20, - system: "You are a helpful assistant that always responds briefly.", + system_: "You are a helpful assistant that always responds briefly.", messages: [ {role: "user", content: "Say hello"} ]