semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net: CreatePlanAsync() is throwing a JsonReaderException

Open deepinderdeol opened this issue 3 years ago • 7 comments

I am getting a JsonReader exception on creating a plan - have tried with both ActionPlanner and SequentialPlanner.

Tested with Microsoft.SemanticKernel version 1.0.0-beta3

This is the code snippet:

var planner = new ActionPlanner(kernel); var plan = await planner.CreatePlanAsync(goal);

And here is the exception info:

Microsoft.SemanticKernel.Diagnostics.SKException: 'Plan parsing error, invalid JSON'

Microsoft.SemanticKernel.Diagnostics.SKException HResult=0x80131500 Message=Plan parsing error, invalid JSON Source=Microsoft.SemanticKernel.Planners.Core StackTrace: at Microsoft.SemanticKernel.Planners.ActionPlanner.ParsePlannerResult(FunctionResult plannerResult) at Microsoft.SemanticKernel.Planners.ActionPlanner.d__8.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

Inner Exception 1: JsonException: '{' is an invalid start of a property name. Expected a '"'. Path: $ | LineNumber: 0 | BytePositionInLine: 1.

Inner Exception 2: JsonReaderException: '{' is an invalid start of a property name. Expected a '"'. LineNumber: 0 | BytePositionInLine: 1.

deepinderdeol avatar Oct 25 '23 05:10 deepinderdeol

This can happen when the planner returns back invalid JSON (which can happen because the LLM isn't always perfect). We recommend improving the descriptions of your plugins and adding a try/catch whenever you create a new plan so that you can recover from an error like this.

madsbolaris avatar Oct 25 '23 16:10 madsbolaris

Okay, thanks for the update. I will try to make it work.

Fyi - this is the example I was referring to, with some edits for adding description for input:

https://learn.microsoft.com/en-us/semantic-kernel/ai-orchestration/planners/?tabs=Csharp

    [SKFunction, Description("Given a number, take the square root of that number")]
    public double Sqrt(
        [Description("The input number for which square root is to be calculated.")] double input)
    {
        return System.Math.Sqrt(input);
    }

deepinderdeol avatar Oct 25 '23 17:10 deepinderdeol

Update: For the same plugin -

  • Stepwise Planner works
  • Sequential Planner fails to make a plan
  • Action Planner throws the Json exception reported above

deepinderdeol avatar Oct 25 '23 19:10 deepinderdeol

@matthewbolanos - Am hitting this error sporadically with same prompt and same input but at different times. Is there a way to expose JSON somewhere so that there is a better idea to fix the problem?

sanket-t-shah avatar Oct 28 '23 08:10 sanket-t-shah

@matthewbolanos - Am hitting this error sporadically with same prompt and same input but at different times. Is there a way to expose JSON somewhere so that there is a better idea to fix the problem?

I am facing similar issue

kanchanpathak06 avatar Feb 23 '24 01:02 kanchanpathak06

These planners have been deprecated. Are you able to share what version of Semantic Kernel you are using?

madsbolaris avatar Feb 28 '24 11:02 madsbolaris

I use 0.4.5.dev0 and even tried 0.5.1.dev0 versions both had plannera in them . So are all planners deprecated?

On Wed, Feb 28, 2024, 3:03 AM Matthew Bolaños @.***> wrote:

These planners have been deprecated. Are you able to share what version of Semantic Kernel you are using?

— Reply to this email directly, view it on GitHub https://github.com/microsoft/semantic-kernel/issues/3289#issuecomment-1968742128, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJCCK6RMXTGXVWIFAABC2G3YV4FG5AVCNFSM6AAAAAA6OX7ADGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRYG42DEMJSHA . You are receiving this because you commented.Message ID: @.***>

kanchanpathak06 avatar Feb 28 '24 13:02 kanchanpathak06