Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Bug: CreateFunctionFromPrompty does not deserialise boolean parameter values correctly #11304

Open
DavidJFowler opened this issue Apr 1, 2025 · 0 comments · May be fixed by #11336
Open
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@DavidJFowler
Copy link

DavidJFowler commented Apr 1, 2025

Describe the bug
Boolean model parameters are deserialised as string values. This causes an exception on calling OpenAIPromptExecutionSettings.FromExecutionSettings

To Reproduce
Steps to reproduce the behavior:

  1. Create a dotnet console app
  2. Add references to Microsoft.SemanticKernel 1.44.0, Microsoft.SemanticKernel.Prompty 1.44.0-alpha
  3. Program.cs:
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;

#pragma warning disable SKEXP0010, SKEXP0040 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

var kernel = new Kernel();

var kernelFunction = kernel.CreateFunctionFromPrompty("""
  ---
  name: SomePrompt
  description: This is the description.
  model:
      api: chat
      configuration:
          type: azure_openai_beta
      parameters:
          logprobs: true
  ---
  Abc---def
  """);

PromptExecutionSettings settings = kernelFunction.ExecutionSettings!["default"];

Console.WriteLine(settings.ExtensionData!["logprobs"].GetType());   // shows System.String but should be System.Boolean

var executionSettings = OpenAIPromptExecutionSettings.FromExecutionSettings(settings);  // throws exception

Console.WriteLine(executionSettings.Logprobs);

Expected behavior
Program runs without exception and outputs correct value of LogProbs property.

Actual behavior
Throws exception

System.Text.Json.JsonException
  HResult=0x80131500
  Message=The JSON value could not be converted to System.Nullable`1[System.Boolean]. Path: $.logprobs | LineNumber: 0 | BytePositionInLine: 84.
  Source=System.Text.Json
  StackTrace:
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo`1 jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
   at Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIPromptExecutionSettings.FromExecutionSettings(PromptExecutionSettings executionSettings, Nullable`1 defaultMaxTokens)
   at Program.<Main>$(String[] args) in C:\Users\Developer\source\repos\ConsoleApp4\Program.cs:line 26

  This exception was originally thrown at this call stack:
    System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedBoolean(System.Text.Json.JsonTokenType)
    System.Text.Json.Utf8JsonReader.GetBoolean()
    System.Text.Json.Serialization.Converters.NullableConverter<T>.Read(ref System.Text.Json.Utf8JsonReader, System.Type, System.Text.Json.JsonSerializerOptions)
    System.Text.Json.Serialization.Metadata.JsonPropertyInfo<T>.ReadJsonAndSetMember(object, ref System.Text.Json.ReadStack, ref System.Text.Json.Utf8JsonReader)
    System.Text.Json.Serialization.Converters.ObjectDefaultConverter<T>.OnTryRead(ref System.Text.Json.Utf8JsonReader, System.Type, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.ReadStack, out T)
    System.Text.Json.Serialization.JsonConverter<T>.TryRead(ref System.Text.Json.Utf8JsonReader, System.Type, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.ReadStack, out T, out bool)
    System.Text.Json.Serialization.JsonConverter<T>.ReadCore(ref System.Text.Json.Utf8JsonReader, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.ReadStack)

Inner Exception 1:
InvalidOperationException: Cannot get the value of a token type 'String' as a boolean.

@DavidJFowler DavidJFowler added the bug Something isn't working label Apr 1, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Apr 1, 2025
@github-actions github-actions bot changed the title Bug: CreateFunctionFromPrompty does not deserialise boolean parameter values correctly .Net: Bug: CreateFunctionFromPrompty does not deserialise boolean parameter values correctly Apr 1, 2025
@markwallace-microsoft markwallace-microsoft self-assigned this Apr 1, 2025
@markwallace-microsoft markwallace-microsoft moved this to Sprint: In Progress in Semantic Kernel Apr 1, 2025
@markwallace-microsoft markwallace-microsoft moved this from Sprint: In Progress to Sprint: In Review in Semantic Kernel Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Status: Sprint: In Review
2 participants