mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
fix(guardrails): scope tool output refusals to attachment types with a payload
Co-authored-by: feng.tsai <fengtsai@berri.ai> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
72940d7910
commit
ae1165fe9d
2 changed files with 8 additions and 5 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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"},
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue