.Net: fix: prevent duplicate "null" in JSON Schema type arrays for nullable parameters by roli-lpci · Pull Request #13635 · microsoft/semantic-kernel

@roli-lpci @claude

… parameters

InsertNullTypeIfRequired() uses jsonArray.Contains(NullType) to check
for existing "null" entries before adding one. JsonArray.Contains()
compares JsonNode objects by reference equality — JsonNode does not
override Equals(). The NullType constant ("null") creates a new
JsonNode on implicit conversion, so the guard always fails and "null"
is always added as a duplicate.

This produces invalid schemas like ["string", "null", "null"] for
Nullable<T> parameters with = null defaults, causing HTTP 400 from
OpenAI's strict-mode API.

The fix replaces .Contains() with a value-based .Any() check, following
the existing pattern used in NormalizeAdditionalProperties in the same
file.

Fixes microsoft#13527

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@moonbox3 moonbox3 added .NET

Issue or Pull requests regarding .NET code

kernel

Issues or pull requests impacting the core kernel

labels

Mar 5, 2026

@github-actions github-actions bot changed the title fix: prevent duplicate "null" in JSON Schema type arrays for nullable parameters .Net: fix: prevent duplicate "null" in JSON Schema type arrays for nullable parameters

Mar 5, 2026