prompty icon indicating copy to clipboard operation
prompty copied to clipboard

Cannot use sub-object in prompty template

Open MRayermannMSFT opened this issue 9 months ago • 3 comments

Hi! We're using prompty templates with SemanticKernel (C#), but running into difficulties when trying to use a sub-object in our templates. I'll give an example.

We have classes like

public class Context
{
    public PagesContext Pages { get; set; }
}

public class PagesContext 
{
   public required IEnumerable<Page> OpenPages { get; set; }

   public required IEnumerable<Page> BookmarkedPages { get; set; }
}

public class Page
{
    public required string Id { get; set; }

    public required string Name { get; set; }
}

We have an instance of the Context class, key named "context", in the KernelArguments we pass to IPromptTemplate.RenderAsync

And in our prompty template, we try to do something like this:

{% for page in context.Pages.BookmarkedPages %}
    - Name: {{ page.name }}, ID: {{ page.id }}
{% endfor %}

We've tried these three syntaxes:

  • context.PagesContext.BookmarkedPages
  • context["PagesContext"]["BookmarkedPages"]
  • context['PagesContext']['BookmarkedPages']

None seem to work.

So is what we want possible, and if so, how do we do it?

MRayermannMSFT avatar Feb 21 '25 18:02 MRayermannMSFT

We are currently reworking the .NET runtime as we speak (well @markwallace-microsoft and I). We have an updated schema to support new agentic scenarios and are working to get the runtime up to speed.

sethjuarez avatar Mar 23 '25 08:03 sethjuarez

FYI, we've been able to update to SemanticKernel 1.40.1.

MRayermannMSFT avatar Mar 24 '25 15:03 MRayermannMSFT

OH! Did that fix it?

sethjuarez avatar Mar 25 '25 14:03 sethjuarez