From ded0967c1804be6da4a7eeedd127c1ba7a2f371b Mon Sep 17 00:00:00 2001 From: Xubin Ren Date: Thu, 2 Apr 2026 05:11:56 +0000 Subject: [PATCH] fix(providers): sanitize azure responses input messages --- nanobot/providers/azure_openai_provider.py | 2 +- tests/providers/test_azure_openai_provider.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/nanobot/providers/azure_openai_provider.py b/nanobot/providers/azure_openai_provider.py index f2f63a5ba..bf6ccae8b 100644 --- a/nanobot/providers/azure_openai_provider.py +++ b/nanobot/providers/azure_openai_provider.py @@ -87,7 +87,7 @@ class AzureOpenAIProvider(LLMProvider): ) -> dict[str, Any]: """Build the Responses API request body from Chat-Completions-style args.""" deployment = model or self.default_model - instructions, input_items = convert_messages(messages) + instructions, input_items = convert_messages(self._sanitize_empty_content(messages)) body: dict[str, Any] = { "model": deployment, diff --git a/tests/providers/test_azure_openai_provider.py b/tests/providers/test_azure_openai_provider.py index 4a18f3bf9..89cea64f0 100644 --- a/tests/providers/test_azure_openai_provider.py +++ b/tests/providers/test_azure_openai_provider.py @@ -150,6 +150,19 @@ def test_build_body_image_conversion(): assert image_block["image_url"] == "https://example.com/img.png" +def test_build_body_sanitizes_single_dict_content_block(): + """Single content dicts should be preserved via shared message sanitization.""" + provider = AzureOpenAIProvider(api_key="k", api_base="https://r.com", default_model="gpt-4o") + messages = [{ + "role": "user", + "content": {"type": "text", "text": "Hi from dict content"}, + }] + + body = provider._build_body(messages, None, None, 4096, 0.7, None, None) + + assert body["input"][0]["content"] == [{"type": "input_text", "text": "Hi from dict content"}] + + # --------------------------------------------------------------------------- # chat() — non-streaming # ---------------------------------------------------------------------------