Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

  • Understand the issue: ToolJson class strips extra JSON properties (like $defs/definitions) when converting AI function declarations to OpenAI tool parameters
  • Identify the fix: Add JsonExtensionData to preserve unknown properties in ToolJson
  • Implement the fix in OpenAIClientExtensions.cs
  • Add unit test to verify $defs and other properties are preserved
  • Run targeted tests to validate changes (all 74 conversion tests passed on all 3 frameworks)
  • Update code comment to reflect new behavior (removed "remove extra properties" wording)
  • Run code review (no issues found)
  • Run codeql_checker (no issues found)
Original prompt

This section details on the original issue you should resolve

<issue_title>[API Question]: ToolJson doesn't have definitions object?</issue_title>
<issue_description>

public string Type { get; set; } = "object";

It appears that by the ToolsJson not having a "definitions" object prevents tool calling behavior using Microsoft.Extensions.AI from matching that of using the OpenAI client despite nearly identical setup. This causes problems when using reference types in function declaration signatures when creating a AIFunctionDeclaration via AIFunctionFactory.CreateDeclaration as the definitions for object types are not provided to the model in the prompt, leading to a failure of the model to create a valid / deserializable arguments.

</issue_description>

<agent_instructions>OpenAI accepts other properties on the top-level JSON object without error, both in strict and non-strict mode; we shouldn't be unnecessarily be stripping them off.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@stephentoub I'm not following. Can you share a minimal repro of the problem you're hitting?

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Microsoft Reviewers: Open in CodeFlow

…defs

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ToolsJson structure to include definitions object Preserve extra JSON schema properties in ToolJson serialization Jan 31, 2026
Copilot AI requested a review from stephentoub January 31, 2026 04:17
@stephentoub stephentoub marked this pull request as ready for review January 31, 2026 04:21
@stephentoub stephentoub requested a review from a team as a code owner January 31, 2026 04:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where ToolJson was stripping extra top-level JSON schema properties (such as $defs and definitions) during serialization roundtrip, causing function calls with reference types to fail.

Changes:

  • Added [JsonExtensionData] attribute to ToolJson class to preserve unrecognized schema properties
  • Added comprehensive test verifying $defs property preservation through the conversion pipeline

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIClientExtensions.cs Added ExtensionData property with [JsonExtensionData] attribute to ToolJson class to preserve extra schema properties like $defs and definitions
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIConversionTests.cs Added test AsOpenAIChatTool_PreservesExtraTopLevelPropertiesLikeDefs that validates $defs property is preserved during function declaration to OpenAI tool conversion

…rties

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This was referenced Feb 11, 2026
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.

[API Question]: ToolJson doesn't have definitions object?

3 participants