diff --git a/litellm/llms/openai/chat/guardrail_translation/handler.py b/litellm/llms/openai/chat/guardrail_translation/handler.py index b9ddf18a96c..095a3f29d2b 100644 --- a/litellm/llms/openai/chat/guardrail_translation/handler.py +++ b/litellm/llms/openai/chat/guardrail_translation/handler.py @@ -313,11 +313,11 @@ class OpenAIChatCompletionsHandler(BaseTranslation): structured_messages[index] for index in scoped_message_indices ] tools: Final = data.get("tools") - if tools and isinstance(tools, list) and not scan_only_tool_results: + if tools and not scan_only_tool_results: inputs["tools"] = cast("list[ChatCompletionToolParam]", tools) # cast-ok: raw request json model: Final = data.get("model") - if model and isinstance(model, str): - inputs["model"] = model + if model: + inputs["model"] = cast("str", model) # cast-ok: base forwarded the raw model value return inputs, structured_messages, scoped_message_indices def _not_run_reason( diff --git a/tests/test_litellm/llms/openai/chat/guardrail_translation/test_openai_chat_guardrail_handler.py b/tests/test_litellm/llms/openai/chat/guardrail_translation/test_openai_chat_guardrail_handler.py index f2a175ad313..16781c11297 100644 --- a/tests/test_litellm/llms/openai/chat/guardrail_translation/test_openai_chat_guardrail_handler.py +++ b/tests/test_litellm/llms/openai/chat/guardrail_translation/test_openai_chat_guardrail_handler.py @@ -280,3 +280,35 @@ class TestOpenAIChatHandlerAttachmentsDefaultScope: assert guardrail.inputs["texts"] == ["look"] assert "files" not in guardrail.inputs assert "images" not in guardrail.inputs + + +class TestOpenAIChatHandlerToolsAndModelForwarding: + @pytest.mark.asyncio + async def test_tools_dict_is_forwarded_verbatim_to_inputs(self): + guardrail = ScanningGuardrail() + tools = {"name": "lookup", "parameters": {"query": "str"}} + data = { + "model": "gpt-4o", + "tools": tools, + "messages": [{"role": "user", "content": "hi"}], + } + + await OpenAIChatCompletionsHandler().process_input_messages(data=data, guardrail_to_apply=guardrail) + + assert guardrail.calls == 1 + assert guardrail.inputs is not None + assert guardrail.inputs["tools"] == tools + + @pytest.mark.asyncio + async def test_model_list_is_forwarded_verbatim_to_inputs(self): + guardrail = ScanningGuardrail() + data = { + "model": ["gpt-4o"], + "messages": [{"role": "user", "content": "hi"}], + } + + await OpenAIChatCompletionsHandler().process_input_messages(data=data, guardrail_to_apply=guardrail) + + assert guardrail.calls == 1 + assert guardrail.inputs is not None + assert guardrail.inputs["model"] == ["gpt-4o"]