litellm - ✅(Solved) Fix [Bug]: Structured Output Not Working for Azure AI Foundry Provider [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#23280Fetched 2026-04-08 00:37:45
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Author
Timeline (top)
labeled ×4closed ×1commented ×1cross-referenced ×1

When using LiteLLM with the azure_ai provider and passing response_format containing a JSON schema (structured output), requests would fail or return unstructured responses for the vast majority of Azure AI Foundry models.

Error Message

  • Fail with an API error — the model endpoint rejects the raw response_format payload because it does not natively support structured output.

Root Cause

AzureAIStudioConfig (in litellm/llms/azure_ai/chat/transformation.py) inherits map_openai_params() from OpenAIConfigOpenAIGPTConfig._map_openai_params(), which is a pure passthrough — it copies response_format into the outgoing request body as-is with no structured output logic whatsoever.

By contrast, AzureOpenAIConfig (in litellm/llms/azure/chat/gpt_transformation.py) already had proper handling:

  1. Check if the model supports native structured output via supports_response_schema().
  2. If supported → pass response_format through natively.
  3. If not supported → convert the JSON schema to a forced tool call via BaseConfig._add_response_format_to_tools().

AzureAIStudioConfig had none of this logic, so every request with a JSON schema was sent raw to the endpoint.

Additionally, 43 out of 75 azure_ai/* models in model_prices_and_context_window.json were missing the supports_response_schema flag entirely, meaning the helper supports_response_schema() had no data to make the right decision for those models.

Fix Action

Fixed

PR fix notes

PR #23283: fix(azure_ai): add structured output support for Azure AI Foundry provider

Description (problem / solution / changelog)

Summary

Fixes structured output (response_format with JSON schema) for the azure_ai provider (Azure AI Foundry, *.services.ai.azure.com endpoints).

  • AzureAIStudioConfig inherited a pure passthrough map_openai_params() from OpenAIGPTConfig with no structured output logic, causing API errors or silent schema-ignoring for most Foundry models
  • Added map_openai_params() override that mirrors the existing AzureOpenAIConfig approach: native passthrough for supported models, tool call fallback via _add_response_format_to_tools() for unsupported models
  • Added supports_response_schema flags for 43 previously-untagged azure_ai chat models in model_prices_and_context_window.json
  • Added 6 unit tests covering all branches of the new logic

Changes

  • litellm/llms/azure_ai/chat/transformation.py — added map_openai_params() override
  • model_prices_and_context_window.json — added supports_response_schema: false for 43 azure_ai chat models (Llama, Phi, Mistral, DeepSeek, JAIS, Jamba, Kimi, MAI-DS, Ministral)
  • tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.py — 6 new structured output tests, all passing

Closes #23280

Changed files

  • litellm/llms/azure_ai/chat/transformation.py (modified, +72/-7)
  • model_prices_and_context_window.json (modified, +82/-41)
  • tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.py (modified, +254/-14)

Code Example

import litellm

response = litellm.completion(
    model="azure_ai/gpt-4o",
    messages=[{"role": "user", "content": "Return a JSON object with name and age."}],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "person",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "age": {"type": "integer"}
                },
                "required": ["name", "age"]
            }
        }
    }
)

---
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Summary

When using LiteLLM with the azure_ai provider and passing response_format containing a JSON schema (structured output), requests would fail or return unstructured responses for the vast majority of Azure AI Foundry models.

Problem Description

LiteLLM supports structured output via the response_format parameter, which accepts a JSON schema:

import litellm

response = litellm.completion(
    model="azure_ai/gpt-4o",
    messages=[{"role": "user", "content": "Return a JSON object with name and age."}],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "person",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "age": {"type": "integer"}
                },
                "required": ["name", "age"]
            }
        }
    }
)

For the azure_ai provider (Azure AI Foundry endpoints, *.services.ai.azure.com), this would either:

  • Fail with an API error — the model endpoint rejects the raw response_format payload because it does not natively support structured output.
  • Return unstructured output — the schema was silently ignored.

The azure provider (Azure OpenAI) worked correctly. Only azure_ai (Azure AI Foundry) was affected.

Root Cause

AzureAIStudioConfig (in litellm/llms/azure_ai/chat/transformation.py) inherits map_openai_params() from OpenAIConfigOpenAIGPTConfig._map_openai_params(), which is a pure passthrough — it copies response_format into the outgoing request body as-is with no structured output logic whatsoever.

By contrast, AzureOpenAIConfig (in litellm/llms/azure/chat/gpt_transformation.py) already had proper handling:

  1. Check if the model supports native structured output via supports_response_schema().
  2. If supported → pass response_format through natively.
  3. If not supported → convert the JSON schema to a forced tool call via BaseConfig._add_response_format_to_tools().

AzureAIStudioConfig had none of this logic, so every request with a JSON schema was sent raw to the endpoint.

Additionally, 43 out of 75 azure_ai/* models in model_prices_and_context_window.json were missing the supports_response_schema flag entirely, meaning the helper supports_response_schema() had no data to make the right decision for those models.

Impact

All Azure AI Foundry models without native structured output support (Llama, Phi, Mistral, DeepSeek, JAIS, Jamba, Kimi, MAI-DS, Ministral, and others) would fail or misbehave when response_format with a JSON schema was used.

Fix

1. litellm/llms/azure_ai/chat/transformation.py

Added a map_openai_params() override to AzureAIStudioConfig with the following logic:

  • JSON schema + supported model → pass response_format through natively.
  • JSON schema + unsupported model → convert to a forced tool call via _add_response_format_to_tools() (same fallback used by Azure OpenAI).
  • Plain {"type": "json_object"} (no schema) → pass through directly.
  • All other params → copy through unchanged.

2. model_prices_and_context_window.json

Added supports_response_schema flags for 43 previously-untagged azure_ai chat models. All were set to false since none of them (Llama, Phi, Mistral, DeepSeek, etc.) support native structured output on Foundry endpoints.

3. tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.py

Added 6 unit tests covering the new behavior:

TestScenario
test_should_pass_through_response_format_for_supported_modelNative passthrough for supported models
test_should_convert_to_tool_call_for_unsupported_modelTool call fallback for unsupported models
test_should_pass_through_json_object_format_without_schemaPlain json_object passthrough
test_should_preserve_other_params_alongside_response_formatOther params unaffected
test_should_handle_response_schema_key_variantHandles response_schema key variant
test_should_append_to_existing_toolsSchema tool appended to user's existing tools

Files Changed

FileChange
litellm/llms/azure_ai/chat/transformation.pyAdded map_openai_params() override with structured output logic
model_prices_and_context_window.jsonAdded supports_response_schema: false for 43 azure_ai chat models
tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.pyAdded 6 structured output unit tests

Steps to Reproduce

  1. Create connection between Azure AI Foundry and LiteLLM
  2. Configure your application that is using structured output to retrieve data from LiteLLM
  3. No structured output will be retrieved

Relevant log output

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.81.16

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

To fix the issue with Azure AI Foundry models not supporting structured output, follow these steps:

  1. Update AzureAIStudioConfig:

    • In litellm/llms/azure_ai/chat/transformation.py, override the map_openai_params() method to handle structured output logic.
    • Add conditions to check if the model supports native structured output and handle accordingly.
  2. Update model_prices_and_context_window.json:

    • Add supports_response_schema flags for the 43 previously untagged azure_ai chat models and set them to false.
  3. Add unit tests:

    • In tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.py, add unit tests to cover the new behavior, including scenarios for supported and unsupported models, plain JSON objects, and preservation of other parameters.

Example Code

# In litellm/llms/azure_ai/chat/transformation.py
class AzureAIStudioConfig:
    # ...

    def map_openai_params(self, params):
        if 'response_format' in params and params['response_format'].get('type') == 'json_schema':
            if self.supports_response_schema():
                # Pass response_format through natively for supported models
                return params
            else:
                # Convert to a forced tool call for unsupported models
                return self._add_response_format_to_tools(params)
        # ...
        return params

    def supports_response_schema(self):
        # Check if the model supports native structured output
        # Return True if supported, False otherwise
        pass

Verification

To verify the fix, run the added unit tests and check that they pass. Additionally, test the application with different scenarios, such as:

  • Using a supported model with a JSON schema
  • Using an unsupported model with a JSON schema
  • Using a plain JSON object without a schema
  • Preserving other parameters alongside the response format

Extra Tips

  • Ensure that the supports_response_schema flag is correctly set for each model in model_prices_and_context_window.json.
  • Consider adding more unit tests to cover additional scenarios and edge cases.
  • Review the documentation for Azure AI Foundry and LiteLLM to ensure that the fix is consistent with their APIs and requirements.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING