Skip to content

[azure-ai-inference] Support dict response_format for LangChain compatibility#46079

Open
hashwnath wants to merge 1 commit intoAzure:mainfrom
hashwnath:fix/ai-inference-dict-response-format-44201
Open

[azure-ai-inference] Support dict response_format for LangChain compatibility#46079
hashwnath wants to merge 1 commit intoAzure:mainfrom
hashwnath:fix/ai-inference-dict-response-format-44201

Conversation

@hashwnath
Copy link
Copy Markdown

Summary

Fixes #44201

_get_internal_response_format() currently only accepts str ("text", "json_object") and JsonSchemaFormat objects. When LangChain's AzureAIChatCompletionsModel (and other OpenAI-compatible frameworks) pass response_format as an OpenAI-style dict like {"type": "json_schema", "json_schema": {...}}, the function raises ValueError: Unsupported response_format.

This PR adds a dict handling branch that converts:

  • {"type": "text"}ChatCompletionsResponseFormatText
  • {"type": "json_object"}ChatCompletionsResponseFormatJsonObject
  • {"type": "json_schema", "json_schema": {"name": ..., "schema": ..., "strict": ..., "description": ...}}ChatCompletionsResponseFormatJsonSchema

Unsupported dict types raise ValueError with a descriptive message.

The async path (aio/_patch.py) imports _get_internal_response_format from the sync module, so this single fix covers both sync and async clients.

Test Plan

  • Added 11 unit tests in tests/test_response_format_conversion.py:
    • 6 tests for new dict handling (text, json_object, json_schema, json_schema with description, unsupported type, missing type)
    • 5 tests verifying existing behavior is preserved (string text, string json_object, JsonSchemaFormat object, None, unsupported type)
  • All 11 tests pass locally

…sponse_format

Fix _get_internal_response_format to handle OpenAI-style dict
response_format (e.g. {"type": "json_schema", "json_schema": {...}}).
This enables LangChain's AzureAIChatCompletionsModel and other
frameworks that pass response_format as a dict instead of a string
or JsonSchemaFormat object.

Supports dict types: "text", "json_object", and "json_schema".
Raises ValueError for unsupported dict types.

Fixes Azure#44201
@github-actions github-actions bot added AI Model Inference Issues related to the client library for Azure AI Model Inference (\sdk\ai\azure-ai-inference) Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Apr 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Thank you for your contribution @hashwnath! We will review the pull request and get back to you soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Model Inference Issues related to the client library for Azure AI Model Inference (\sdk\ai\azure-ai-inference) Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azure-ai-inference : LangChain AzureAIChatCompletionsModel Does Not Support OpenAI-Style JSON Schema Format

1 participant