From 0b272679ac95dc7b7f697686d2b5f483c9eeff2b Mon Sep 17 00:00:00 2001 From: yucheng Date: Tue, 29 Sep 2026 00:10:16 +0000 Subject: [PATCH] test(responses): type the texts-replacing guardrail helper explicitly Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../test_openai_responses_guardrail_handler.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 98d34f156ea..df63ca5f0c7 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 @@ -7,7 +7,7 @@ with guardrail transformations. import copy from collections.abc import Callable -from typing import Any, List, Literal, Optional, Tuple +from typing import Any, Final, List, Literal, Optional, Tuple from unittest.mock import AsyncMock, MagicMock, patch import logging @@ -101,18 +101,18 @@ 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, texts: list[str] | None, **kwargs): - super().__init__(**kwargs) - self.texts = texts + def __init__(self, guardrail_name: str, texts: tuple[str, ...] | None): + super().__init__(guardrail_name=guardrail_name) + self.texts: Final = texts async def apply_guardrail( self, inputs: GenericGuardrailAPIInputs, - request_data: dict, + request_data: dict[str, object], input_type: Literal["request", "response"], logging_obj: LiteLLMLoggingObj | None = None, ) -> GenericGuardrailAPIInputs: - answer = {key: value for key, value in inputs.items() if key != "texts"} + answer: Final = {key: value for key, value in inputs.items() if key != "texts"} return answer if self.texts is None else {**answer, "texts": list(self.texts)} @@ -361,7 +361,7 @@ class TestOpenAIResponsesHandlerInputProcessing: from litellm.llms.base_llm.guardrail_translation.utils import UnappliableRequestRewrite handler = OpenAIResponsesHandler() - guardrail = TextsReplacingGuardrail(guardrail_name="emptier", texts=[]) + guardrail = TextsReplacingGuardrail(guardrail_name="emptier", texts=()) data = {"model": "gpt-4", "instructions": "Be terse", "input": data_input} original = copy.deepcopy(data)