From b4fb2b2e1670ba382da9ee2365fd236af542c094 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Fri, 12 Jun 2026 10:10:50 +0000 Subject: [PATCH] fix(bedrock): skip passthrough output write-back when guardrail returns no texts --- .../guardrail_translation/handler.py | 3 ++- .../guardrail_translation/test_handler.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/litellm/llms/bedrock/passthrough/guardrail_translation/handler.py b/litellm/llms/bedrock/passthrough/guardrail_translation/handler.py index cd118b02fc..9027f96349 100644 --- a/litellm/llms/bedrock/passthrough/guardrail_translation/handler.py +++ b/litellm/llms/bedrock/passthrough/guardrail_translation/handler.py @@ -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 diff --git a/tests/test_litellm/llms/bedrock/passthrough/guardrail_translation/test_handler.py b/tests/test_litellm/llms/bedrock/passthrough/guardrail_translation/test_handler.py index 01dff69bf0..848c40c009 100644 --- a/tests/test_litellm/llms/bedrock/passthrough/guardrail_translation/test_handler.py +++ b/tests/test_litellm/llms/bedrock/passthrough/guardrail_translation/test_handler.py @@ -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