Skip to content

Python: Raise NotImplementedError for get_web_search_tool() on AzureOpenAICha…#4480

Open
max-montes wants to merge 1 commit intomicrosoft:mainfrom
max-montes:fix/azure-openai-web-search-not-supported
Open

Python: Raise NotImplementedError for get_web_search_tool() on AzureOpenAICha…#4480
max-montes wants to merge 1 commit intomicrosoft:mainfrom
max-montes:fix/azure-openai-web-search-not-supported

Conversation

@max-montes
Copy link

Motivation and Context

Azure OpenAI's Chat Completions API does not support the web_search_options parameter. Previously, calling get_web_search_tool() on AzureOpenAIChatClient inherited the base OpenAI implementation, producing a config that caused a 400 error at runtime. Now raises NotImplementedError at tool creation time with a message directing users to OpenAIChatClient or AzureOpenAIResponsesClient.

Fixes #3629

Description

Contribution Checklist

  • [ X] The code builds clean without any errors or warnings
  • [ X] The PR follows the Contribution Guidelines
  • [ X] All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings March 4, 2026 20:54
@github-actions github-actions bot changed the title Raise NotImplementedError for get_web_search_tool() on AzureOpenAICha… Python: Raise NotImplementedError for get_web_search_tool() on AzureOpenAICha… Mar 4, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Mar 4, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/azure
   _chat_client.py80495%315, 317, 330–331
TOTAL22607279587% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4697 25 💤 0 ❌ 0 🔥 1m 21s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Prevents a known runtime failure when users attempt to enable web search with AzureOpenAIChatClient (Azure OpenAI Chat Completions), by failing fast at tool creation time and adding a regression test tied to #3629.

Changes:

  • Override AzureOpenAIChatClient.get_web_search_tool() to raise NotImplementedError with guidance on supported alternatives.
  • Add a unit regression test ensuring the method raises on Azure chat client usage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
python/packages/core/agent_framework/azure/_chat_client.py Adds a get_web_search_tool() override that raises early with a clear message for unsupported Azure Chat Completions web search.
python/packages/core/tests/azure/test_azure_chat_client.py Adds a regression test asserting the new NotImplementedError behavior.

)

@staticmethod
def get_web_search_tool(**kwargs: Any) -> dict[str, Any]:
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_web_search_tool is overriding the OpenAI chat client factory method but uses a generic **kwargs signature. Consider matching the upstream signature (e.g., keyword-only web_search_options) so help()/docs/autocomplete stay consistent across clients and type-checkers can provide the expected parameter hints, even though this implementation always raises.

Suggested change
def get_web_search_tool(**kwargs: Any) -> dict[str, Any]:
def get_web_search_tool(*, web_search_options: Any | None = None) -> dict[str, Any]:

Copilot uses AI. Check for mistakes.
assert any(term in second_response.text.lower() for term in ["miami", "sunny", "72"])


def test_get_web_search_tool_raises_not_implemented(azure_openai_unit_test_env: dict[str, str]) -> None:
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test requests the azure_openai_unit_test_env fixture but doesn’t use it. If the environment setup isn’t required for this assertion, consider removing the fixture parameter to keep the test focused and avoid unnecessary fixture setup.

Suggested change
def test_get_web_search_tool_raises_not_implemented(azure_openai_unit_test_env: dict[str, str]) -> None:
def test_get_web_search_tool_raises_not_implemented() -> None:

Copilot uses AI. Check for mistakes.
…tClient

Azure OpenAI's Chat Completions API does not support the web_search_options
parameter. Previously, calling get_web_search_tool() on AzureOpenAIChatClient
inherited the base OpenAI implementation, producing a config that caused a
400 error at runtime. Now raises NotImplementedError at tool creation time
with a message directing users to OpenAIChatClient or
AzureOpenAIResponsesClient.

Fixes microsoft#3629

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@max-montes max-montes force-pushed the fix/azure-openai-web-search-not-supported branch from 5bc21a2 to fbd8eb5 Compare March 4, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: HostedWebSearchTool failed with AzureOpenAIChatClient

3 participants