Skip to content

Commit c2e9e37

Browse files
ref(anthropic): Revert input transformation
1 parent a6c4ed0 commit c2e9e37

2 files changed

Lines changed: 11 additions & 753 deletions

File tree

sentry_sdk/integrations/anthropic.py

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
normalize_message_roles,
1313
truncate_and_annotate_messages,
1414
get_start_span_function,
15-
transform_anthropic_content_part,
1615
)
1716
from sentry_sdk.consts import OP, SPANDATA
1817
from sentry_sdk.integrations import _check_minimum_version, DidNotEnable, Integration
@@ -323,27 +322,6 @@ def _collect_ai_data(
323322
)
324323

325324

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-
347325
def _transform_system_instructions(
348326
system_instructions: "Union[str, Iterable[TextBlockParam]]",
349327
) -> "list[TextPart]":
@@ -401,41 +379,19 @@ def _set_common_input_data(
401379
and "content" in message
402380
and isinstance(message["content"], (list, tuple))
403381
):
404-
transformed_content = []
405382
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+
)
426393
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)
439395

440396
role_normalized_messages = normalize_message_roles(normalized_messages)
441397
scope = sentry_sdk.get_current_scope()

0 commit comments

Comments
 (0)