From c63fd3bd29b48506dabb930624b399294e022a38 Mon Sep 17 00:00:00 2001 From: yucheng Date: Tue, 29 Sep 2026 08:21:00 +0000 Subject: [PATCH] chore(guardrails): remove unrelated test churn Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/proxy/guardrails/guardrail_registry.py | 2 +- .../proxy/guardrails/test_guardrail_registry.py | 4 ++-- tests/unit/integrations/test_custom_guardrail.py | 14 ++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_registry.py b/litellm/proxy/guardrails/guardrail_registry.py index 0956d2c9cfc..6527f6be50b 100644 --- a/litellm/proxy/guardrails/guardrail_registry.py +++ b/litellm/proxy/guardrails/guardrail_registry.py @@ -440,8 +440,8 @@ def _as_callback_tuple( def _configure_callback_scoping( custom_guardrail_callback: CustomGuardrail, guardrail_name: str, litellm_params: LitellmParams ) -> None: - custom_guardrail_callback.logging_only_scope = litellm_params.logging_only_scope logging_only_scope: Final = litellm_params.logging_only_scope + custom_guardrail_callback.logging_only_scope = logging_only_scope if logging_only_scope is not None and GuardrailEventHooks.logging_only.value not in _configured_event_hooks( litellm_params.mode ): diff --git a/tests/test_litellm/proxy/guardrails/test_guardrail_registry.py b/tests/test_litellm/proxy/guardrails/test_guardrail_registry.py index d8c6351a384..6af7a7a06a4 100644 --- a/tests/test_litellm/proxy/guardrails/test_guardrail_registry.py +++ b/tests/test_litellm/proxy/guardrails/test_guardrail_registry.py @@ -7,11 +7,11 @@ from pydantic import ValidationError from litellm.integrations.custom_guardrail import CustomGuardrail from litellm.proxy.guardrails.guardrail_registry import ( + get_guardrail_initializer_from_hooks, GuardrailRegistry, InMemoryGuardrailHandler, - get_guardrail_initializer_from_hooks, ) -from litellm.types.guardrails import Guardrail, GuardrailEventHooks, LitellmParams, LoggingOnlyScope, Mode +from litellm.types.guardrails import GuardrailEventHooks, Guardrail, LitellmParams, LoggingOnlyScope, Mode from litellm.types.utils import GenericGuardrailAPIInputs diff --git a/tests/unit/integrations/test_custom_guardrail.py b/tests/unit/integrations/test_custom_guardrail.py index 2fdb338f20e..d01b54aa953 100644 --- a/tests/unit/integrations/test_custom_guardrail.py +++ b/tests/unit/integrations/test_custom_guardrail.py @@ -546,10 +546,14 @@ class TestApplyGuardrailCheck: class ParentGuardrail(CustomGuardrail): """Parent that inherits apply_guardrail from CustomGuardrail""" + pass + # Child class that only inherits apply_guardrail (doesn't override) class ChildGuardrailWithoutOverride(ParentGuardrail): """Child that only inherits apply_guardrail""" + pass + # Child class that overrides apply_guardrail class ChildGuardrailWithOverride(ParentGuardrail): """Child that overrides apply_guardrail""" @@ -2536,7 +2540,7 @@ class TestLoggingOnlyApplyGuardrail: from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.content_filter import ( ContentFilterGuardrail, ) - from litellm.types.guardrails import BlockedWord, ContentFilterAction + from litellm.types.guardrails import BlockedWord, ContentFilterAction, GuardrailEventHooks guardrail: Final = ContentFilterGuardrail( guardrail_name="content-review", @@ -2628,7 +2632,7 @@ class TestLoggingOnlyApplyGuardrail: @pytest.mark.asyncio async def test_block_verdict_is_recorded_without_raising(self): - guardrail: Final = _ApplyOnlyObserver(block=True) + guardrail = _ApplyOnlyObserver(block=True) kwargs, response = _logged_call([{"role": "user", "content": "flagged content"}]) out_kwargs, _ = await guardrail.async_logging_hook(kwargs, response, CallTypes.acompletion.value) @@ -2637,7 +2641,7 @@ class TestLoggingOnlyApplyGuardrail: ("request", ["flagged content"]), ("response", ["general kenobi"]), ] - entries: Final = out_kwargs["standard_logging_object"]["guardrail_information"] + entries = out_kwargs["standard_logging_object"]["guardrail_information"] assert [entry["guardrail_status"] for entry in entries] == ["guardrail_intervened", "guardrail_intervened"] @pytest.mark.asyncio @@ -2964,7 +2968,9 @@ async def test_native_lifecycle_guardrail_logging_only_scans_assembled_response( from litellm.types.utils import Choices, Message, ModelResponse guardrail = _NativeLifecycleLoggingGuardrail() - assembled = ModelResponse(choices=[Choices(message=Message(role="assistant", content="assembled stream text"))]) + assembled = ModelResponse( + choices=[Choices(message=Message(role="assistant", content="assembled stream text"))] + ) sentinel_result = object() kwargs = { "model": "gpt-5.4-mini",