@@ -1074,17 +1074,22 @@ def test_nonstreaming_create_message_with_system_prompt(
10741074 assert span ["data" ][SPANDATA .GEN_AI_REQUEST_MODEL ] == "model"
10751075
10761076 if send_default_pii and include_prompts :
1077+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS in span ["data" ]
1078+ system_instructions = json .loads (
1079+ span ["data" ][SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS ]
1080+ )
1081+ assert system_instructions == [
1082+ {"type" : "text" , "content" : "You are a helpful assistant." }
1083+ ]
1084+
10771085 assert SPANDATA .GEN_AI_REQUEST_MESSAGES in span ["data" ]
10781086 stored_messages = json .loads (span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ])
1079- assert len (stored_messages ) == 2
1080- # System message should be first
1081- assert stored_messages [0 ]["role" ] == "system"
1082- assert stored_messages [0 ]["content" ] == "You are a helpful assistant."
1083- # User message should be second
1084- assert stored_messages [1 ]["role" ] == "user"
1085- assert stored_messages [1 ]["content" ] == "Hello, Claude"
1087+ assert len (stored_messages ) == 1
1088+ assert stored_messages [0 ]["role" ] == "user"
1089+ assert stored_messages [0 ]["content" ] == "Hello, Claude"
10861090 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_TEXT ] == "Hi, I'm Claude."
10871091 else :
1092+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS not in span ["data" ]
10881093 assert SPANDATA .GEN_AI_REQUEST_MESSAGES not in span ["data" ]
10891094 assert SPANDATA .GEN_AI_RESPONSE_TEXT not in span ["data" ]
10901095
@@ -1153,17 +1158,22 @@ async def test_nonstreaming_create_message_with_system_prompt_async(
11531158 assert span ["data" ][SPANDATA .GEN_AI_REQUEST_MODEL ] == "model"
11541159
11551160 if send_default_pii and include_prompts :
1161+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS in span ["data" ]
1162+ system_instructions = json .loads (
1163+ span ["data" ][SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS ]
1164+ )
1165+ assert system_instructions == [
1166+ {"type" : "text" , "content" : "You are a helpful assistant." }
1167+ ]
1168+
11561169 assert SPANDATA .GEN_AI_REQUEST_MESSAGES in span ["data" ]
11571170 stored_messages = json .loads (span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ])
1158- assert len (stored_messages ) == 2
1159- # System message should be first
1160- assert stored_messages [0 ]["role" ] == "system"
1161- assert stored_messages [0 ]["content" ] == "You are a helpful assistant."
1162- # User message should be second
1163- assert stored_messages [1 ]["role" ] == "user"
1164- assert stored_messages [1 ]["content" ] == "Hello, Claude"
1171+ assert len (stored_messages ) == 1
1172+ assert stored_messages [0 ]["role" ] == "user"
1173+ assert stored_messages [0 ]["content" ] == "Hello, Claude"
11651174 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_TEXT ] == "Hi, I'm Claude."
11661175 else :
1176+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS not in span ["data" ]
11671177 assert SPANDATA .GEN_AI_REQUEST_MESSAGES not in span ["data" ]
11681178 assert SPANDATA .GEN_AI_RESPONSE_TEXT not in span ["data" ]
11691179
@@ -1264,18 +1274,23 @@ def test_streaming_create_message_with_system_prompt(
12641274 assert span ["data" ][SPANDATA .GEN_AI_REQUEST_MODEL ] == "model"
12651275
12661276 if send_default_pii and include_prompts :
1277+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS in span ["data" ]
1278+ system_instructions = json .loads (
1279+ span ["data" ][SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS ]
1280+ )
1281+ assert system_instructions == [
1282+ {"type" : "text" , "content" : "You are a helpful assistant." }
1283+ ]
1284+
12671285 assert SPANDATA .GEN_AI_REQUEST_MESSAGES in span ["data" ]
12681286 stored_messages = json .loads (span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ])
1269- assert len (stored_messages ) == 2
1270- # System message should be first
1271- assert stored_messages [0 ]["role" ] == "system"
1272- assert stored_messages [0 ]["content" ] == "You are a helpful assistant."
1273- # User message should be second
1274- assert stored_messages [1 ]["role" ] == "user"
1275- assert stored_messages [1 ]["content" ] == "Hello, Claude"
1287+ assert len (stored_messages ) == 1
1288+ assert stored_messages [0 ]["role" ] == "user"
1289+ assert stored_messages [0 ]["content" ] == "Hello, Claude"
12761290 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_TEXT ] == "Hi! I'm Claude!"
12771291
12781292 else :
1293+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS not in span ["data" ]
12791294 assert SPANDATA .GEN_AI_REQUEST_MESSAGES not in span ["data" ]
12801295 assert SPANDATA .GEN_AI_RESPONSE_TEXT not in span ["data" ]
12811296
@@ -1379,18 +1394,23 @@ async def test_streaming_create_message_with_system_prompt_async(
13791394 assert span ["data" ][SPANDATA .GEN_AI_REQUEST_MODEL ] == "model"
13801395
13811396 if send_default_pii and include_prompts :
1397+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS in span ["data" ]
1398+ system_instructions = json .loads (
1399+ span ["data" ][SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS ]
1400+ )
1401+ assert system_instructions == [
1402+ {"type" : "text" , "content" : "You are a helpful assistant." }
1403+ ]
1404+
13821405 assert SPANDATA .GEN_AI_REQUEST_MESSAGES in span ["data" ]
13831406 stored_messages = json .loads (span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ])
1384- assert len (stored_messages ) == 2
1385- # System message should be first
1386- assert stored_messages [0 ]["role" ] == "system"
1387- assert stored_messages [0 ]["content" ] == "You are a helpful assistant."
1388- # User message should be second
1389- assert stored_messages [1 ]["role" ] == "user"
1390- assert stored_messages [1 ]["content" ] == "Hello, Claude"
1407+ assert len (stored_messages ) == 1
1408+ assert stored_messages [0 ]["role" ] == "user"
1409+ assert stored_messages [0 ]["content" ] == "Hello, Claude"
13911410 assert span ["data" ][SPANDATA .GEN_AI_RESPONSE_TEXT ] == "Hi! I'm Claude!"
13921411
13931412 else :
1413+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS not in span ["data" ]
13941414 assert SPANDATA .GEN_AI_REQUEST_MESSAGES not in span ["data" ]
13951415 assert SPANDATA .GEN_AI_RESPONSE_TEXT not in span ["data" ]
13961416
@@ -1437,21 +1457,23 @@ def test_system_prompt_with_complex_structure(sentry_init, capture_events):
14371457 (span ,) = event ["spans" ]
14381458
14391459 assert span ["data" ][SPANDATA .GEN_AI_OPERATION_NAME ] == "chat"
1460+
1461+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS in span ["data" ]
1462+ system_instructions = json .loads (span ["data" ][SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS ])
1463+
1464+ # System content should be a list of text blocks
1465+ assert isinstance (system_instructions , list )
1466+ assert system_instructions == [
1467+ {"type" : "text" , "content" : "You are a helpful assistant." },
1468+ {"type" : "text" , "content" : "Be concise and clear." },
1469+ ]
1470+
14401471 assert SPANDATA .GEN_AI_REQUEST_MESSAGES in span ["data" ]
14411472 stored_messages = json .loads (span ["data" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ])
14421473
1443- # Should have system message first, then user message
1444- assert len (stored_messages ) == 2
1445- assert stored_messages [0 ]["role" ] == "system"
1446- # System content should be a list of text blocks
1447- assert isinstance (stored_messages [0 ]["content" ], list )
1448- assert len (stored_messages [0 ]["content" ]) == 2
1449- assert stored_messages [0 ]["content" ][0 ]["type" ] == "text"
1450- assert stored_messages [0 ]["content" ][0 ]["text" ] == "You are a helpful assistant."
1451- assert stored_messages [0 ]["content" ][1 ]["type" ] == "text"
1452- assert stored_messages [0 ]["content" ][1 ]["text" ] == "Be concise and clear."
1453- assert stored_messages [1 ]["role" ] == "user"
1454- assert stored_messages [1 ]["content" ] == "Hello"
1474+ assert len (stored_messages ) == 1
1475+ assert stored_messages [0 ]["role" ] == "user"
1476+ assert stored_messages [0 ]["content" ] == "Hello"
14551477
14561478
14571479# Tests for transform_content_part (shared) and _transform_anthropic_content_block helper functions
0 commit comments