.NET: Support primitives and arrays for SO#3696
Merged
SergeyMenshykh merged 4 commits intomicrosoft:feature-sofrom Feb 6, 2026
Merged
.NET: Support primitives and arrays for SO#3696SergeyMenshykh merged 4 commits intomicrosoft:feature-sofrom
SergeyMenshykh merged 4 commits intomicrosoft:feature-sofrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for primitives, arrays, and enums in structured output by automatically wrapping non-object JSON schemas. Previously, the structured output feature only supported object types at the root level, which caused LLMs to reject requests for primitive or array types.
Changes:
- Wraps primitives, arrays, and enums in a JSON object schema with a "data" property when used as structured output types
- Unwraps the response from the agent when deserializing wrapped types
- Adds comprehensive unit tests and an integration test for primitive and array type handling
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgentStructuredOutput.cs |
Implements schema wrapping logic with EnsureObjectSchema, SchemaRepresentsObject, and helper methods to wrap non-object schemas |
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse{T}.cs |
Adds IsWrappedInObject property and UnwrapDataProperty method to unwrap responses from wrapped schemas |
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIAgentStructuredOutputTests.cs |
Adds unit tests for schema wrapping, response unwrapping, and end-to-end scenarios |
dotnet/tests/AgentConformance.IntegrationTests/StructuredOutputRunTests.cs |
Adds integration test for primitive type structured output |
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIAgentStructuredOutputTests.cs
Show resolved
Hide resolved
westey-m
approved these changes
Feb 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
The new solution for structured output is not handling primitives and arrays, which means that LLMs will reject requests where the SO schema does not have an object as the root.
Description