From fdcc1494be1bd7875150750ab9c7b97fa9acdd1a Mon Sep 17 00:00:00 2001 From: yucheng Date: Tue, 29 Sep 2026 22:59:32 +0000 Subject: [PATCH] test(responses): annotate new guardrail tests with return types Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../guardrail_hooks/test_panw_prisma_airs.py | 6 ++--- ...test_openai_responses_guardrail_handler.py | 24 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py index 7e095c3f474..0691bda5b84 100644 --- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py @@ -4792,7 +4792,7 @@ class TestPanwAirsLatestRoleMessageOnlyEveryRequestShape: ) async def test_flag_true_with_skip_system_still_scans_only_the_latest_turn_on_responses( self, history_tail: Sequence[Mapping[str, object]] - ): + ) -> None: from litellm.llms.openai.responses.guardrail_translation.handler import ( OpenAIResponsesHandler, ) @@ -4812,7 +4812,7 @@ class TestPanwAirsLatestRoleMessageOnlyEveryRequestShape: assert [call.kwargs["content"] for call in mock_api.call_args_list] == [self.LATEST] @pytest.mark.asyncio - async def test_flag_false_responses_scans_instructions_and_full_history(self): + async def test_flag_false_responses_scans_instructions_and_full_history(self) -> None: from litellm.llms.openai.responses.guardrail_translation.handler import ( OpenAIResponsesHandler, ) @@ -4971,7 +4971,7 @@ class TestPanwAirsLatestRoleMessageOnlyEveryRequestShape: ] @pytest.mark.asyncio - async def test_flag_true_texts_short_of_the_input_items_fall_back_to_scanning_everything(self): + async def test_flag_true_texts_short_of_the_input_items_fall_back_to_scanning_everything(self) -> None: handler = make_handler(experimental_use_latest_role_message_only=True) reasoning = {"type": "reasoning", "id": "rs_1", "content": [{"type": "reasoning_text", "text": "thinking"}]} inputs: GenericGuardrailAPIInputs = { diff --git a/tests/unit/llms/openai/responses/test_openai_responses_guardrail_handler.py b/tests/unit/llms/openai/responses/test_openai_responses_guardrail_handler.py index 766e24bb237..21ae6d62262 100644 --- a/tests/unit/llms/openai/responses/test_openai_responses_guardrail_handler.py +++ b/tests/unit/llms/openai/responses/test_openai_responses_guardrail_handler.py @@ -70,7 +70,7 @@ class MockGuardrail(CustomGuardrail): class RecordingMaskingGuardrail(MockGuardrail): """MockGuardrail that also records the texts and structured message contents it was shown""" - def __init__(self, **kwargs): + def __init__(self, **kwargs) -> None: super().__init__(**kwargs) self.seen_texts: List[List[str]] = [] self.seen_message_contents: List[List[object]] = [] @@ -101,7 +101,7 @@ class LastTextDroppingGuardrail(CustomGuardrail): class TextsReplacingGuardrail(CustomGuardrail): """Answers with the given texts list, or without a texts key at all when given None""" - def __init__(self, guardrail_name: str, texts: tuple[str, ...] | None): + def __init__(self, guardrail_name: str, texts: tuple[str, ...] | None) -> None: super().__init__(guardrail_name=guardrail_name) self.texts: Final = texts @@ -292,7 +292,7 @@ class TestOpenAIResponsesHandlerInputProcessing: assert result["input"][1]["content"] == " [GUARDRAILED]" @pytest.mark.asyncio - async def test_instructions_over_string_input_are_scanned_first_and_rewritten_in_place(self): + async def test_instructions_over_string_input_are_scanned_first_and_rewritten_in_place(self) -> None: handler = OpenAIResponsesHandler() guardrail = RecordingMaskingGuardrail(guardrail_name="test") data = {"model": "gpt-4", "instructions": "Be terse", "input": "Hello"} @@ -305,7 +305,7 @@ class TestOpenAIResponsesHandlerInputProcessing: assert result["input"] == "Hello [GUARDRAILED]" @pytest.mark.asyncio - async def test_instructions_over_list_input_are_scanned_first_and_rewritten_in_place(self): + async def test_instructions_over_list_input_are_scanned_first_and_rewritten_in_place(self) -> None: handler = OpenAIResponsesHandler() guardrail = RecordingMaskingGuardrail(guardrail_name="test") data = { @@ -328,7 +328,7 @@ class TestOpenAIResponsesHandlerInputProcessing: ] @pytest.mark.asyncio - async def test_empty_instructions_are_not_scanned(self): + async def test_empty_instructions_are_not_scanned(self) -> None: handler = OpenAIResponsesHandler() guardrail = RecordingMaskingGuardrail(guardrail_name="test") data = {"model": "gpt-4", "instructions": "", "input": "Hello"} @@ -340,7 +340,7 @@ class TestOpenAIResponsesHandlerInputProcessing: assert result["input"] == "Hello [GUARDRAILED]" @pytest.mark.asyncio - async def test_text_answer_missing_the_instructions_row_is_rejected_and_leaves_request_untouched(self): + async def test_text_answer_missing_the_instructions_row_is_rejected_and_leaves_request_untouched(self) -> None: from litellm.llms.base_llm.guardrail_translation.utils import UnappliableRequestRewrite handler = OpenAIResponsesHandler() @@ -416,7 +416,7 @@ class TestSkipSystemMessageScopesInstructions: assert rewritten == "Hello [GUARDRAILED]" @pytest.mark.asyncio - async def test_system_input_items_leave_scope_and_user_items_still_align_with_structured_messages(self): + async def test_system_input_items_leave_scope_and_user_items_still_align_with_structured_messages(self) -> None: handler = OpenAIResponsesHandler() guardrail = _skipping_system(RecordingMaskingGuardrail(guardrail_name="test")) data = { @@ -441,7 +441,7 @@ class TestSkipSystemMessageScopesInstructions: ] @pytest.mark.asyncio - async def test_only_system_content_means_nothing_is_scanned(self): + async def test_only_system_content_means_nothing_is_scanned(self) -> None: handler = OpenAIResponsesHandler() guardrail = _skipping_system(RecordingMaskingGuardrail(guardrail_name="test")) data = {"model": "gpt-4", "instructions": "Be terse", "input": [{"role": "system", "content": "Rules"}]} @@ -453,7 +453,7 @@ class TestSkipSystemMessageScopesInstructions: assert result == original @pytest.mark.asyncio - async def test_structured_rewrite_of_the_scoped_rows_keeps_the_skipped_system_prompt(self): + async def test_structured_rewrite_of_the_scoped_rows_keeps_the_skipped_system_prompt(self) -> None: handler = OpenAIResponsesHandler() data = { "model": "gpt-5.6", @@ -477,7 +477,7 @@ class TestSkipSystemMessageScopesInstructions: ] @pytest.mark.asyncio - async def test_full_coverage_claim_over_only_the_scoped_rows_still_keeps_the_skipped_system_prompt(self): + async def test_full_coverage_claim_over_only_the_scoped_rows_still_keeps_the_skipped_system_prompt(self) -> None: handler = OpenAIResponsesHandler() data = { "model": "gpt-5.6", @@ -499,7 +499,7 @@ class TestSkipSystemMessageScopesInstructions: ] @pytest.mark.asyncio - async def test_full_coverage_claim_over_the_whole_request_is_installed_without_a_second_merge(self): + async def test_full_coverage_claim_over_the_whole_request_is_installed_without_a_second_merge(self) -> None: handler = OpenAIResponsesHandler() data = { "model": "gpt-5.6", @@ -2879,7 +2879,7 @@ class TestPerMessageRewriteWriteBack: assert [_texts(item) for item in result["input"]] == [["My SSN is " + REDACTED_SSN + "."]] @pytest.mark.asyncio - async def test_texts_only_per_message_answer_over_a_string_input_lands_on_instructions_and_input(self): + async def test_texts_only_per_message_answer_over_a_string_input_lands_on_instructions_and_input(self) -> None: guardrail = _per_message_redactor() data = _string_input_request()