Skip to content

.Net: Handlebars prompt template doesn't deserialize JSON response when Content-Type includes charset #5127

@vsomayaji

Description

@vsomayaji

Describe the bug
If the Content-Type header of a REST API JSON response includes a charset (e.g. Content-Type: application/json; charset=utf-8), the Handlebars prompt template handles the response as a string instead of as deserialized JSON.

To Reproduce
The issue appears to be due to how the Content-Type is matched here:

if (resultAsObject is RestApiOperationResponse restApiOperationResponse)
{
// Deserialize any JSON content or return the content as a string
if (string.Equals(restApiOperationResponse.ContentType, "application/json", StringComparison.OrdinalIgnoreCase))
{
var parsedJson = JsonValue.Parse(restApiOperationResponse.Content.ToString());
return KernelHelpersUtils.DeserializeJsonNode(parsedJson);
}
return restApiOperationResponse.Content;
}

Expected behavior
The JSON response should be deserialized.

Platform

  • Language: C#
  • Source: Microsoft.SemanticKernel.PromptTemplates.Handlebars version 1.4.0

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codebugSomething isn't working

Type

No type

Projects

Status

Sprint: Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions