Share via

Azure OpenAI: `apply_patch` works alone, but seems unavailable when a custom tool is included in the same request

Jhonatan Oliveira 0 Reputation points
2026-03-18T22:53:34.49+00:00

We are seeing unexpected tool behavior in Azure OpenAI and would like to check whether this is expected, a recent platform change, or a known issue.

Scenario

In our application, we send tool-enabled requests to Azure OpenAI models. We observed that:

  • when the request includes only the built-in apply_patch tool, the model can use it correctly
  • when the request includes apply_patch plus any custom tool in the same request, the model behaves as if apply_patch is not available

In the second case, when asked to make a code change, the model typically responds that it does not have access to a writing/editing tool.

Repro steps

  1. Send a request to an Azure OpenAI model
  2. Include:
    • built-in tool: apply_patch
    • one custom tool
  3. Ask the model to make a code change
  4. Observe that the model does not use apply_patch

Then repeat the same test with only:

  • built-in tool: apply_patch

In that case, the model uses apply_patch correctly.

What makes this confusing

This same integration pattern had been working for us previously, and the behavior appears to have changed around March 13, 2026.

Models where we reproduced it

We observed the same pattern on multiple GPT deployments, including:

  • gpt-5.3-codex
  • gpt-5.4
  • gpt-5.4-mini

Questions

  1. Is this expected behavior in Azure OpenAI when built-in tools are combined with custom tools?
  2. Is there any Azure-specific limitation or requirement for mixing built-in tools and user-defined tools in the same request?
  3. Has anyone else observed this behavior recently?
  4. Is there a recommended workaround?

We can share a minimal repro payload if that would help.

Azure OpenAI Service
Azure OpenAI Service

An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.

{count} votes

2 answers

Sort by: Most helpful
  1. Karnam Venkata Rajeswari 565 Reputation points Microsoft External Staff Moderator
    2026-03-25T09:09:44.65+00:00

    Hello Jhonatan Oliveira,

    Welcome to Microsoft Q&A and Thank you for reaching out.

    Thank you for sharing the detailed scenario and reproduction steps.

    When multiple tools are made available in a single request, the model may prioritize tool selection differently depending on the request context. In scenarios that involve file or code edits, keeping the request scope narrow has shown more predictable results.

    The below suggested workarounds are based on the practical steps to maintain stable workflows which focus on reducing ambiguity in tool selection and preserving continuity in code-editing workflows, based on current tool-enabled request behaviour.

    1. Consider separating code editing and custom tool usage into distinct requests to maintain consistent behaviour.
    • Use one request that includes only the built‑in apply_patch tool when code changes are required
    • Then perform all file creation, updates, or deletions within this request
    • Send a follow‑up request for any custom tool execution, after code edits are completed
    • This separation helps ensure the editing tool is clearly available for code‑related tasks.
    1. Please keep the code‑editing requests scoped only to apply_patch for requests that involve modifying files.Include only the apply_patch built‑in tool while excluding the custom or function‑based tools.This allows the model to focus solely on generating structured diffs.This minimizes tool selection ambiguity during edit operations.

    3. As a general best practice, please confirm whether the requests are sent using a currently supported GA API version.

    1. Please avoid using deprecated or preview API versions
    2. Consider aligning  requests with the versions listed in the official API lifecycle documentation to ensure compatibility with the latest supported features.

    4. As a validation step verify tool declaration structure follows the documented schema.

    • Please Declare built‑in and custom tools using the standard tools array
    • Please avoid mixing legacy function formats with newer tool definitions
    • Please avoid forcing tool selection during mixed‑tool testing
    • This helps rule out payload inconsistencies during troubleshooting.

      

    References:

     

    Thank you!

    Please 'Upvote'(Thumbs-up) and 'Accept' as answer if the reply was helpful. This will be benefitting other community members who face the same issue.

    0 comments No comments

  2. Q&A Assist
    2026-03-18T22:53:59.62+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more
    1. This is not expected behavior based on the current Azure OpenAI / Foundry tool model. The OpenAI-compatible tool system in Azure AI Foundry explicitly supports mixing multiple tool types in a single request, including:
      • built-in tools such as apply_patch, shell, image_generation, code_interpreter, file_search, etc.
      • user-defined tools (custom / function)
      In the REST schema, all of these are just different values of the type discriminator on OpenAI.ToolChoiceParam and are designed to coexist:
      • apply_patchOpenAI.SpecificApplyPatchParam
      • shellOpenAI.SpecificFunctionShellParam
      • custom / function → user-defined tools
      There is no documented rule that apply_patch becomes unavailable when a custom tool is present.
    2. Azure-specific limitations/requirements for mixing tools From the documented components:
      • OpenAI.ToolChoiceParamType allows multiple values: allowed_tools, function, mcp, custom, apply_patch, shell, file_search, web_search_preview, image_generation, code_interpreter, etc.
      • OpenAI.SpecificApplyPatchParam is used when the model must be forced to call apply_patch:
             {
               "tool_choice": {
                 "type": "apply_patch"
               }
             }
        
      • Similarly, OpenAI.SpecificFunctionShellParam forces the shell tool.
      The documented behavior is that tool_choice can be used to:
      • let the model choose among all provided tools, or
      • force a specific built-in tool (like apply_patch) when a tool call is required.
      There is no Azure-specific limitation documented that forbids combining apply_patch with custom tools in the same tools array. The platform explicitly supports apply_patch as a tool type and ToolChoiceApplyPatch / SpecificApplyPatchParam as a way to force its use.
    3. Whether others have observed this recently The provided context does not contain any Q&A or incident notes describing the exact regression pattern ("apply_patch works alone but not when combined with a custom tool" around March 13, 2026). There is no documented known issue matching that description in the context.
    4. Recommended workarounds Based on the documented tool-choice primitives, the following workarounds are supported and align with the current API surface:
      1. Force apply_patch when code changes are required
      When the request is specifically about editing files or applying diffs, use the tool_choice discriminator to force the apply_patch tool instead of leaving the choice fully open:
      • In REST, set tool_choice.type to apply_patch (using OpenAI.SpecificApplyPatchParam).
      • In the Python agent server models, use ToolChoiceApplyPatch:
        • ToolChoiceApplyPatch / SpecificApplyPatchParam are explicitly documented as: "Forces the model to call the apply_patch tool when executing a tool call."
      This ensures that even if other tools are present, the model must call apply_patch for the current turn.
      1. Use separate turns for selection vs. patching
      If the interaction mixes higher-level reasoning (custom tools) and file editing in the same conversation, split it into two steps:
      • Turn 1: Allow all tools (including custom tools) to decide what should be changed.
      • Turn 2: When ready to apply a change, send a new request with:
        • the same conversation context (messages),
        • the apply_patch tool included,
        • tool_choice forced to apply_patch.
      This pattern is fully compatible with the documented ToolChoiceApplyPatch / SpecificApplyPatchParam behavior.
      1. Validate tool schemas and names
      Although not explicitly called out in the context, ensure that:
      • the apply_patch tool is defined using the correct schema (ApplyPatchTool in the agent server SDKs, or the correct built-in tool definition in REST), and
      • custom tools do not reuse reserved names or shapes that could confuse the model.
      The SDK types:
      • ApplyPatchTool: "Allows the assistant to create, delete, or update files using unified diffs."
      • ResponseApplyPatchToolCall: represents the tool call result for apply_patch.
      Using these types as-is helps ensure the platform recognizes apply_patch correctly.
    5. Next steps Because the context does not document any breaking change on March 13, 2026, and the schema explicitly supports mixing tool types, the behavior described most likely requires:
      • inspecting the exact tools array and tool_choice payload being sent, and
      • opening an Azure support ticket with a minimal repro payload if the issue persists while using tool_choice.type = "apply_patch".
      That will allow the product group to confirm whether this is a regression or a model-behavior change for the specific GPT versions in use.

    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.