Skip to content

Python: Fix HostedWebSearchTool failing with AzureOpenAIChatClient#3876

Open
hashwnath wants to merge 2 commits intomicrosoft:mainfrom
hashwnath:fix/azure-websearch-tool-unsupported
Open

Python: Fix HostedWebSearchTool failing with AzureOpenAIChatClient#3876
hashwnath wants to merge 2 commits intomicrosoft:mainfrom
hashwnath:fix/azure-websearch-tool-unsupported

Conversation

@hashwnath
Copy link

@hashwnath hashwnath commented Feb 12, 2026

Motivation and Context

Fixes #3629

AzureOpenAIChatClient inherits _prepare_tools_for_openai() from RawOpenAIChatClient, which extracts web search tools into a top-level web_search_options parameter. Azure OpenAI's Chat Completions API does not support this parameter (it's OpenAI-only), resulting in:

Error code: 400 - Unknown parameter: 'web_search_options'

Description

Override _prepare_tools_for_openai() in AzureOpenAIChatClient to gracefully filter out web search tools and log a warning, rather than letting the request fail.

This ensures robust handling: requests with multiple tools (e.g., weather + web search) will still succeed for the supported tools, while the user is clearly warned that web search is not supported on this endpoint. The warning directs users to use OpenAIChatClient or AzureOpenAIResponsesClient if web search is required.

Changes

  • azure/_chat_client.py: Added _prepare_tools_for_openai() override that filters out {"type": "web_search"} tools and logs a warning
  • tests/azure/test_azure_chat_client.py: Added tests verifying that web search tools are filtered out with a warning and that normal tools are preserved

Contribution Checklist

…#3629)

Override _prepare_tools_for_openai() in AzureOpenAIChatClient to raise
ServiceInvalidRequestError when web search tools are used, since Azure
OpenAI's Chat Completions API does not support the web_search_options
parameter.

Fixes microsoft#3629
@github-actions github-actions bot changed the title Fix HostedWebSearchTool failing with AzureOpenAIChatClient Python: Fix HostedWebSearchTool failing with AzureOpenAIChatClient Feb 12, 2026
Changed _prepare_tools_for_openai to filter out unsupported web search
tools and log a warning, rather than raising ServiceInvalidRequestError.
This ensures that requests with multiple tools don't fail entirely just
because a web search tool was included.
@hashwnath
Copy link
Author

@microsoft-github-policy-service agree [company="{MAQ Software(Microsoft Partner)}"]

@microsoft-github-policy-service

@hashwnath the command you issued was incorrect. Please try again.

Examples are:

@microsoft-github-policy-service agree

and

@microsoft-github-policy-service agree company="your company"

@hashwnath
Copy link
Author

@microsoft-github-policy-service agree company="MAQ Software"

)

@override
def _prepare_tools_for_openai(self, tools: Sequence[Any]) -> dict[str, Any]:
Copy link
Member

Choose a reason for hiding this comment

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

thanks for looking into this, however we also should have the:

@staticmethod
    def get_web_search_tool(
        *,
        web_search_options: WebSearchOptions | None = None,
    ) -> dict[str, Any]:

raise a NotSupportedError in the azure chat client so that people do not switch from OpenAI to Azure OpenAI and keep that in.

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