mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-05 06:22:12 +00:00
fix(bedrock): skip passthrough output write-back when guardrail returns no texts
This commit is contained in:
@@ -497,6 +497,7 @@ class BedrockPassthroughGuardrailHandler(BaseTranslation):
|
||||
)
|
||||
|
||||
guardrailed_texts = guardrailed_inputs.get("texts", [])
|
||||
_write_back_texts(guardrailed_texts, holders)
|
||||
if guardrailed_texts:
|
||||
_write_back_texts(guardrailed_texts, holders)
|
||||
|
||||
return response
|
||||
|
||||
@@ -597,6 +597,25 @@ class TestBedrockPassthroughGuardrailHandlerOutput:
|
||||
assert result["output"]["message"]["content"][0]["text"] == "[MASKED]"
|
||||
assert result["stopReason"] == "end_turn"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_response_guardrail_returning_no_texts_preserves_output(self, monkeypatch):
|
||||
"""A guardrail that returns no texts must leave the response untouched and
|
||||
not warn, mirroring the request path's empty-result guard."""
|
||||
handler = BedrockPassthroughGuardrailHandler()
|
||||
response = self._converse_response("Model reply")
|
||||
guardrail = _make_guardrail({"texts": []})
|
||||
|
||||
warnings = []
|
||||
monkeypatch.setattr(
|
||||
"litellm.llms.bedrock.passthrough.guardrail_translation.handler.verbose_proxy_logger.warning",
|
||||
lambda *args, **kwargs: warnings.append(args),
|
||||
)
|
||||
|
||||
result = await handler.process_output_response(response=response, guardrail_to_apply=guardrail)
|
||||
|
||||
assert not warnings
|
||||
assert result["output"]["message"]["content"][0]["text"] == "Model reply"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_response_reasoning_and_tooluse_extracted_and_masked(self):
|
||||
"""Model output hidden in reasoningContent.reasoningText.text and
|
||||
|
||||
Reference in New Issue
Block a user