From 479ac6ea95f36f66380534b8d5606993e50a8d13 Mon Sep 17 00:00:00 2001 From: Jean Carlos NUnez Date: Fri, 3 Apr 2026 16:05:38 -0500 Subject: [PATCH] refactor(test): move inline imports to module level in test_custom_guardrail Per project style guide (CLAUDE.md): imports must be at module level. Moved CustomGuardrail, log_guardrail_information, GuardrailEventHooks, Mode, and GenericGuardrailAPIInputs from inline test method imports to the top of the file. Co-Authored-By: Claude Sonnet 4.6 --- .../integrations/test_custom_guardrail.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/tests/test_litellm/integrations/test_custom_guardrail.py b/tests/test_litellm/integrations/test_custom_guardrail.py index bb24e2224d3..e5fd542028a 100644 --- a/tests/test_litellm/integrations/test_custom_guardrail.py +++ b/tests/test_litellm/integrations/test_custom_guardrail.py @@ -2,9 +2,10 @@ from unittest.mock import AsyncMock import pytest -from litellm.integrations.custom_guardrail import CustomGuardrail +from litellm.integrations.custom_guardrail import CustomGuardrail, log_guardrail_information from litellm.proxy._types import CallTypes, UserAPIKeyAuth -from litellm.types.utils import GuardrailTracingDetail +from litellm.types.guardrails import GuardrailEventHooks, Mode +from litellm.types.utils import GenericGuardrailAPIInputs, GuardrailTracingDetail class TestCustomGuardrailDeploymentHook: @@ -949,13 +950,6 @@ class TestLogGuardrailInformationApplyGuardrailEventType: guardrail_mode should be GuardrailEventHooks.pre_call (a string), not a GuardrailMode dict. """ - from litellm.integrations.custom_guardrail import ( - CustomGuardrail, - log_guardrail_information, - ) - from litellm.types.guardrails import GuardrailEventHooks, Mode - from litellm.types.utils import GenericGuardrailAPIInputs - # Build a Mode object (tags-based routing), which is what custom-code # guardrails use. Without the fix, this becomes a GuardrailMode dict # in the logged data, triggering .replace is not a function in the UI. @@ -997,13 +991,6 @@ class TestLogGuardrailInformationApplyGuardrailEventType: When apply_guardrail is called with input_type='response', the logged guardrail_mode should be GuardrailEventHooks.post_call (a string). """ - from litellm.integrations.custom_guardrail import ( - CustomGuardrail, - log_guardrail_information, - ) - from litellm.types.guardrails import GuardrailEventHooks, Mode - from litellm.types.utils import GenericGuardrailAPIInputs - mode = Mode(tags={}, default="post_call") class _TestGuardrail(CustomGuardrail):