diff --git a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py index 5b1362c819b..e46feab9fc7 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py +++ b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py @@ -132,6 +132,10 @@ _UNSCANNABLE_ATTACHMENT_PAYLOAD_KEYS: Final[Mapping[str, str]] = MappingProxyTyp "input_audio": "input_audio", } ) +_TOOL_OUTPUT_ATTACHMENT_TYPES: Final[frozenset[str]] = frozenset( + ("input_file", "file", "document", "input_image", "image", "image_url", "video_url", "input_audio") +) +_TOOL_OUTPUT_METADATA_KEYS: Final[frozenset[str]] = frozenset(("type", "name", "filename")) _NO_TRACING_DETAIL: Final[GuardrailTracingDetail] = {} # Resource-less, detect-only InvokeGuardrailChecks API (no guardrail resource required). _BEDROCK_INVOKE_GUARDRAIL_CHECKS_PATH: Final = "/guardrail-checks/invoke" @@ -729,10 +733,9 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM): if not isinstance(content, str): return for part in _serialized_tool_output_parts(content): - if ( - (payload_key := _UNSCANNABLE_ATTACHMENT_PAYLOAD_KEYS.get(str(part.get("type")))) is not None - and part.get(payload_key) - ) or part.get("file_id"): + if part.get("type") in _TOOL_OUTPUT_ATTACHMENT_TYPES and any( + part.get(key) for key in part.keys() - _TOOL_OUTPUT_METADATA_KEYS + ): self._handle_unscannable_attachment(reason="a tool output attachment cannot be scanned") async def _build_image_content_item(self, image_url: str) -> BedrockContentItem: diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py index 00a4c19720a..75f62947fd5 100644 --- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py @@ -7405,7 +7405,7 @@ async def test_during_call_hook_tool_output_payloadless_shell_falls_through(): mock_response.json.return_value = {"action": "NONE", "assessments": []} data = { "messages": [ - {"role": "tool", "content": json.dumps([{"type": "input_file"}, {"type": "output_text", "text": "done"}])}, + {"role": "tool", "content": json.dumps([{"type": "input_file"}, {"type": "output_text", "file_id": "f-1", "text": "done"}])}, {"role": "user", "content": "summarize"}, ] }