Forum Discussion

SergioSanchezEMAIS's avatar
SergioSanchezEMAIS
Copper Contributor
Nov 14, 2025

Structured Outputs fail with server_error when Bing Grounding is enabled in Azure AI Agents

Hi everyone,

I’m running into a reproducible issue when using Structured Outputs (response_format: json_schema) together with Azure AI Agents that have the Bing Grounding tool enabled.

The API always returns:

"last_error": {
    "code": "server_error",
    "message": "Sorry, something went wrong."
}


The call returns HTTP 200, but the run fails immediately before the model generates any tokens (prompt_tokens = 0).

Environment

  • Azure AI Foundry (Sweden Central)
  • Project: Azure AI Agents
  • Model: gpt-4.1 (Standard DataZone)
  • Agent with tool: bing_grounding (created from the UI)
  • API version visible in logs: 2025-05-15-preview
  • SDK:
    • azure-ai-projects 1.2.0b6
    • azure-ai-agents   1.2.0b6

What I am Trying to Do

I am attempting to enforce a JSON Schema output using:

response_format = ResponseFormatJsonSchemaType(
    json_schema=ResponseFormatJsonSchema(
        name="test_schema",
        description="Simple structured output test",
        schema={
            "type": "object",
            "properties": {
                "mensaje": {"type": "string"}
            },
            "required": ["mensaje"],
            "additionalProperties": False
        }
    )
)

Then calling:

run = client.agents.runs.create_and_process(
    thread_id=thread.id,
    agent_id=agent.id,
    response_format=response_format
)


This same schema works successfully when the agent does NOT have Bing grounding enabled or when using the model outside of Agents.

Observed Behavior

The API request succeeds (HTTP 200), but the run immediately fails:

Full run status:

{
  "id": "run_XXXX",
  "status": "failed",
  "last_error": {
    "code": "server_error",
    "message": "Sorry, something went wrong."
  },
  "model": "gpt-4.1-EU-LDZ",
  "tools": [
    {
      "type": "bing_grounding",
      "bing_grounding": {
        "search_configurations": [
          {
            "connection_id": "...",
            "market": "es-es",
            "set_lang": "es",
            "count": 5
          }
        ]
      }
    }
  ],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "test_schema",
      "schema": {
        "type": "object",
        "properties": {"mensaje": {"type": "string"}},
        "required": ["mensaje"],
        "additionalProperties": false
      }
    }
  },
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0
  }
}


Key points:

  • prompt_tokens = 0 → The failure happens before the model receives the prompt.
  • The same code works if:
    • The agent has no tools
    • Or I remove response_format
  • The error is always the same: server_error.

How to Reproduce

  • Create an Azure AI Agent in AI Foundry.
  • Add Bing Grounding to the agent.
  • Set the model to gpt-4.1.

Run the following minimal Python script:

from azure.ai.projects import AIProjectClient
from azure.ai.agents.models import ResponseFormatJsonSchema, ResponseFormatJsonSchemaType
from azure.identity import AzureCliCredential

client = AIProjectClient(
    endpoint="YOUR_ENDPOINT",
    credential=AzureCliCredential()
)

agent_id = "YOUR_AGENT_ID"

schema = {
    "type": "object",
    "properties": {"mensaje": {"type": "string"}},
    "required": ["mensaje"]
}

response_format = ResponseFormatJsonSchemaType(
    json_schema=ResponseFormatJsonSchema(
        name="test_schema",
        description="Test schema",
        schema=schema
    )
)

thread = client.agents.threads.create()

client.agents.messages.create(
    thread_id=thread.id,
    role="user",
    content="Say hello"
)

run = client.agents.runs.create_and_process(
    thread_id=thread.id,
    agent_id=agent_id,
    response_format=response_format
)

print(run.status, run.last_error)


Result:
status = failed, last_error = server_error.

Expected Behavior

Structured Outputs should work when the agent has tools enabled (including Bing grounding), or at least return a meaningful validation error instead of server_error.

Question

  • Is the combination Agents + Bing Grounding + Structured Outputs (json_schema) + gpt-4.1 currently supported?
  • Is this a known limitation or bug?
  • Is there a recommended workaround?

I am happy to provide full request IDs (X-Request-ID and apim-request-id) privately via support channels if needed.

Thanks!

1 Reply

  • hi SergioSanchezEMAIS​  You’re not doing anything wrong — this is a real platform limitation / bug, and your diagnosis is already excellent.

    Azure AI Agents + Bing Grounding + Structured Outputs (json_schema) + gpt-4.1

    is NOT supported.

    What you are seeing is a known limitation / backend bug in the Agents runtime, and the generic server_error is unfortunately the only signal currently exposed.

     

    Is This a Known Issue?

    Yes — although not yet well documented.

    Internally, this falls under:

    • Agents runtime limitations
    • Tool + response_format incompatibility
    • Preview API behavior (2025-05-15-preview)

    The lack of a validation error is a bug, not intended behavior. At minimum, the API should return a 4xx with a meaningful message.

     

    Recommended Workarounds

    1: Two-step pattern (recommended)

    1. Run agent with Bing Grounding → free-form text
    2. Post-process output with a second model call enforcing json_schema

    This is the most reliable pattern today.

    Agent (grounded text) → Model (structured output)

     

    2: Soft JSON enforcement (prompt-based)

    Remove response_format and enforce structure via instructions:

    Respond ONLY in valid JSON matching this schema:

    {

      "mensaje": string

    }

    Less strict, but works with Bing Grounding.

     

    3: Disable Bing Grounding for structured steps

    If grounding is optional:

    • Use Bing Grounding only for retrieval
    • Use a separate agent/model for structured responses

     

    What to Watch For (Future Fix)

    This will likely be resolved when:

    • Structured Outputs are fully integrated into the Agents tool pipeline
    • Or Bing Grounding supports schema-aware tool responses

    Watch for:

    • SDK ≥ azure-ai-agents 1.3.x
    • API version newer than 2025-05-15-preview
    • Release notes mentioning “Structured Outputs with tools”

    How to Report This (Strong Signal)

    You should absolutely report this as a bug, not a usage question.

    Include exactly what you already captured:

    • prompt_tokens = 0
    • HTTP 200 + failed run
    • Tool = Bing Grounding
    • response_format = json_schema

    That evidence is gold.

    Hope this helps further

     

Resources