mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
refactor(guardrails): extract the non-string image ref refusal to keep complexity under the ceiling
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
89de4a0f90
commit
a09231ed06
1 changed files with 6 additions and 3 deletions
|
|
@ -658,6 +658,11 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM):
|
|||
# Unrecognized inputs reach the decoder so the guardrail fails closed.
|
||||
return value
|
||||
|
||||
def _refuse_non_string_image_refs(self, image_urls: tuple[object, ...]) -> None:
|
||||
for image_ref in image_urls:
|
||||
if not isinstance(image_ref, str):
|
||||
self._handle_unscannable_attachment(reason="a non-string image reference cannot be scanned")
|
||||
|
||||
def _refuse_unscannable_image_ref(self, image_url: str) -> None:
|
||||
"""Refuse an image ref that is cheaply known to be unscannable.
|
||||
|
||||
|
|
@ -3604,9 +3609,7 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM):
|
|||
# from `image`/`source` blocks. Five other guardrails already consume this
|
||||
# field; Bedrock was the one that dropped it on the floor.
|
||||
image_urls: Final = tuple(inputs.get("images") or ()) if input_type == "request" else ()
|
||||
for image_ref in image_urls:
|
||||
if not isinstance(image_ref, str):
|
||||
self._handle_unscannable_attachment(reason="a non-string image reference cannot be scanned")
|
||||
self._refuse_non_string_image_refs(image_urls=image_urls)
|
||||
# Refused before the shortcuts: ApplyGuardrail has no content type for a document/file attachment.
|
||||
files: Final = tuple(inputs.get("files") or ()) if input_type == "request" else ()
|
||||
if files:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue