|
12 | 12 | normalize_message_roles, |
13 | 13 | truncate_and_annotate_messages, |
14 | 14 | get_start_span_function, |
15 | | - transform_anthropic_content_part, |
16 | 15 | ) |
17 | 16 | from sentry_sdk.consts import OP, SPANDATA |
18 | 17 | from sentry_sdk.integrations import _check_minimum_version, DidNotEnable, Integration |
@@ -323,27 +322,6 @@ def _collect_ai_data( |
323 | 322 | ) |
324 | 323 |
|
325 | 324 |
|
326 | | -def _transform_anthropic_content_block( |
327 | | - content_block: "dict[str, Any]", |
328 | | -) -> "dict[str, Any]": |
329 | | - """ |
330 | | - Transform an Anthropic content block using the Anthropic-specific transformer, |
331 | | - with special handling for Anthropic's text-type documents. |
332 | | - """ |
333 | | - # Handle Anthropic's text-type documents specially (not covered by shared function) |
334 | | - if content_block.get("type") == "document": |
335 | | - source = content_block.get("source") |
336 | | - if isinstance(source, dict) and source.get("type") == "text": |
337 | | - return { |
338 | | - "type": "text", |
339 | | - "text": source.get("data", ""), |
340 | | - } |
341 | | - |
342 | | - # Use Anthropic-specific transformation |
343 | | - result = transform_anthropic_content_part(content_block) |
344 | | - return result if result is not None else content_block |
345 | | - |
346 | | - |
347 | 325 | def _transform_system_instructions( |
348 | 326 | system_instructions: "Union[str, Iterable[TextBlockParam]]", |
349 | 327 | ) -> "list[TextPart]": |
@@ -401,41 +379,19 @@ def _set_common_input_data( |
401 | 379 | and "content" in message |
402 | 380 | and isinstance(message["content"], (list, tuple)) |
403 | 381 | ): |
404 | | - transformed_content = [] |
405 | 382 | for item in message["content"]: |
406 | | - # Skip tool_result items - they can contain images/documents |
407 | | - # with nested structures that are difficult to redact properly |
408 | | - if isinstance(item, dict) and item.get("type") == "tool_result": |
409 | | - continue |
410 | | - |
411 | | - # Transform content blocks (images, documents, etc.) |
412 | | - transformed_content.append( |
413 | | - _transform_anthropic_content_block(item) |
414 | | - if isinstance(item, dict) |
415 | | - else item |
416 | | - ) |
417 | | - |
418 | | - # If there are non-tool-result items, add them as a message |
419 | | - if transformed_content: |
420 | | - normalized_messages.append( |
421 | | - { |
422 | | - "role": message.get("role"), |
423 | | - "content": transformed_content, |
424 | | - } |
425 | | - ) |
| 383 | + if item.get("type") == "tool_result": |
| 384 | + normalized_messages.append( |
| 385 | + { |
| 386 | + "role": GEN_AI_ALLOWED_MESSAGE_ROLES.TOOL, |
| 387 | + "content": { # type: ignore[dict-item] |
| 388 | + "tool_use_id": item.get("tool_use_id"), |
| 389 | + "output": item.get("content"), |
| 390 | + }, |
| 391 | + } |
| 392 | + ) |
426 | 393 | else: |
427 | | - # Transform content for non-list messages or assistant messages |
428 | | - transformed_message = message.copy() |
429 | | - if "content" in transformed_message: |
430 | | - content = transformed_message["content"] |
431 | | - if isinstance(content, (list, tuple)): |
432 | | - transformed_message["content"] = [ |
433 | | - _transform_anthropic_content_block(item) |
434 | | - if isinstance(item, dict) |
435 | | - else item |
436 | | - for item in content |
437 | | - ] |
438 | | - normalized_messages.append(transformed_message) |
| 394 | + normalized_messages.append(message) |
439 | 395 |
|
440 | 396 | role_normalized_messages = normalize_message_roles(normalized_messages) |
441 | 397 | scope = sentry_sdk.get_current_scope() |
|
0 commit comments