Skip to content

feat(azure): add structured output support for AzureAIChatCompletionClient - #8223

Open
Abhinav (abhnvgrg) wants to merge 1 commit into
microsoft:mainfrom
abhnvgrg:abhnvgrg/5957-azure-ai-structured-output
Open

feat(azure): add structured output support for AzureAIChatCompletionClient#8223
Abhinav (abhnvgrg) wants to merge 1 commit into
microsoft:mainfrom
abhnvgrg:abhnvgrg/5957-azure-ai-structured-output

Conversation

@abhnvgrg

Copy link
Copy Markdown

Add structured output support for AzureAIChatCompletionClient

Closes #5957

What

Adds support for passing a Pydantic BaseModel subclass as json_output
to AzureAIChatCompletionClient.create() and create_stream(), enabling
structured output for models hosted on Azure AI Foundry and GitHub Models.

Approach

  • Converts the Pydantic model to a JSON schema via model_json_schema()
    and passes it as JsonSchemaFormat(name=..., schema=..., strict=True) in
    the response_format parameter to the Azure AI Inference SDK's
    client.complete()
  • Validates the response content against the Pydantic model with
    model_validate_json() after receiving the completion
  • Handles both create() and create_stream() paths
  • Checks model_info["structured_output"] and raises a clear error when
    the model doesn't support it
  • Follows the same patterns established by OpenAIChatCompletionClient in
    PR feat: add structured output to model clients #5936

Files changed

  • python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py
    — core implementation
  • python/packages/autogen-ext/src/autogen_ext/models/azure/config/__init__.py
    — type updates (if needed)
  • python/packages/autogen-ext/tests/models/test_azure_ai_model_client.py
    — unit tests with mocked Azure SDK

Tests

  • Structured output with create() — validates Pydantic parsing
  • Structured output with create_stream() — validates streamed JSON parsing
  • Model capability check — raises when structured_output is False
  • Response format verification — confirms JsonSchemaFormat is passed to SDK
  • All existing tests remain green

Local validation

uv run pytest packages/autogen-ext/tests/models/test_azure_ai_model_client.py -v
25 passed

uv run ruff check --select E9,F63,F7,F82 packages/autogen-ext/
All checks passed!

@abhnvgrg

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for structured output for AzureAIChatCompletionClient.

1 participant