Skip to content

.Net: Fix: KernelJsonSchemaBuilder now excludes read-only properties from generated schema#13554

Open
sajidkamaljoy wants to merge 1 commit intomicrosoft:mainfrom
sajidkamaljoy:fix-json-schema-bug
Open

.Net: Fix: KernelJsonSchemaBuilder now excludes read-only properties from generated schema#13554
sajidkamaljoy wants to merge 1 commit intomicrosoft:mainfrom
sajidkamaljoy:fix-json-schema-bug

Conversation

@sajidkamaljoy
Copy link

Motivation

Currently, KernelJsonSchemaBuilder includes read-only properties (properties with no setter) in the generated JSON schema. This causes the AI to attempt to generate values for fields it cannot write to (e.g., computed properties), which wastes tokens and can lead to hallucinated data that is silently ignored.

Changes

  • Modified KernelJsonSchemaBuilder.GetDefaultOptions to include a JsonTypeInfo modifier.
  • The modifier (ExcludeReadOnlyProperties) inspects the JsonTypeInfo and removes any property where Set is null.
  • Added a regression test in KernelJsonSchemaTests to verify that read-only properties are absent from the generated schema while writable properties remain.

Validation

  • Added new unit test ItShouldExcludeReadOnlyPropertiesFromSchema.
  • Ran all tests in SemanticKernel.UnitTests.Functions.

@sajidkamaljoy sajidkamaljoy requested a review from a team as a code owner February 16, 2026 20:31
@moonbox3 moonbox3 added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Feb 16, 2026
@github-actions github-actions bot changed the title Fix: KernelJsonSchemaBuilder now excludes read-only properties from generated schema .Net: Fix: KernelJsonSchemaBuilder now excludes read-only properties from generated schema Feb 16, 2026
@sajidkamaljoy
Copy link
Author

@sajidkamaljoy please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

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

Labels

kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants