diff --git a/src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Schema.Create.cs b/src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Schema.Create.cs
index 667b3c4d080..df7d6bb4039 100644
--- a/src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Schema.Create.cs
+++ b/src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Schema.Create.cs
@@ -193,7 +193,7 @@ public static JsonElement CreateJsonSchema(
/// Validates the provided JSON schema document.
internal static void ValidateSchemaDocument(JsonElement document, [CallerArgumentExpression("document")] string? paramName = null)
{
- if (document.ValueKind is not JsonValueKind.Object or JsonValueKind.False or JsonValueKind.True)
+ if (document.ValueKind is not (JsonValueKind.Object or JsonValueKind.False or JsonValueKind.True))
{
Throw.ArgumentException(paramName ?? "schema", "The schema document must be an object or a boolean value.");
}
diff --git a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs
index 8ebc20b957e..dcd6836b5da 100644
--- a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs
+++ b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs
@@ -1416,6 +1416,34 @@ public static void TransformJsonSchema_InvalidInput_ThrowsArgumentException(stri
Assert.Throws("schema", () => AIJsonUtilities.TransformSchema(schema, transformOptions));
}
+ [Theory]
+ [InlineData("true")]
+ [InlineData("false")]
+ public static void TransformJsonSchema_BooleanSchemas_Success(string booleanSchema)
+ {
+ // Boolean schemas (true/false) are valid JSON schemas per the spec.
+ // This test verifies they are accepted by TransformSchema.
+ JsonElement schema = JsonDocument.Parse(booleanSchema).RootElement;
+ AIJsonSchemaTransformOptions transformOptions = new() { ConvertBooleanSchemas = true };
+
+ // Should not throw - boolean schemas are valid
+ JsonElement result = AIJsonUtilities.TransformSchema(schema, transformOptions);
+
+ // Verify the transformation happened correctly
+ if (booleanSchema == "true")
+ {
+ // 'true' schema should be converted to empty object
+ Assert.Equal(JsonValueKind.Object, result.ValueKind);
+ }
+ else
+ {
+ // 'false' schema should be converted to {"not": true}
+ Assert.Equal(JsonValueKind.Object, result.ValueKind);
+ Assert.True(result.TryGetProperty("not", out JsonElement notValue));
+ Assert.Equal(JsonValueKind.True, notValue.ValueKind);
+ }
+ }
+
private class DerivedAIContent : AIContent
{
public int DerivedValue { get; set; }