PromptEngine 0.6.3

dotnet add package PromptEngine --version 0.6.3
                    
NuGet\Install-Package PromptEngine -Version 0.6.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PromptEngine" Version="0.6.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PromptEngine" Version="0.6.3" />
                    
Directory.Packages.props
<PackageReference Include="PromptEngine" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PromptEngine --version 0.6.3
                    
#r "nuget: PromptEngine, 0.6.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PromptEngine@0.6.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PromptEngine&version=0.6.3
                    
Install as a Cake Addin
#tool nuget:?package=PromptEngine&version=0.6.3
                    
Install as a Cake Tool

PromptEngine - Prompt Engineering Framework for C#

A comprehensive prompt-engineering framework for C# agent/LLM development, with compile-time validation, code generation, and runtime safety checks.

Features

  • Compile-time validation (analyzer) — catch template errors at build time
  • Runtime validation — verify template changes in production or CI
  • Type-safe — strong typing for context and templates
  • Mustache templating — industry-standard template syntax
  • Agent Framework integration — works with Microsoft Agent Framework and Semantic Kernel
  • Multi-template support — manage multiple prompts in one project

Packages

Package Description NuGet
PromptEngine Complete package including the runtime library, Roslyn analyzer, and source generator NuGet

Quick Start

1. Install Package

# Single package includes everything: runtime library, analyzer, and source generator
dotnet add package PromptEngine

Add your prompt files to the project as AdditionalFiles so the generator can discover them.

  1. In Visual Studio, set each prompt file's Build Action to C# analyzer additional file in the Properties window; or
  2. Edit your project file:
<ItemGroup>
   <AdditionalFiles Include="Prompts/**/*.md" />
</ItemGroup>

Then all files under Prompts/ with the .md extension will be included.

2. Create a Prompt Template (Markdown)

Create a file Prompts/Summarize.md:

# Summarize Request for {{{UserName}}}

## Input

```text
{{{InputText}}}
```

## Requirements
- Provide a concise summary in {{{MaxWords}}} words or less.
- Focus on key ideas and main points.

## Additional Instructions
{{{Instructions}}}

Note: PromptEngine uses Mustache template syntax. See the Mustache documentation to learn more.

3. Define the Context Class

using PromptEngine.Core.Attributes;

[PromptContext("Prompts/Summarize.md", TemplateName = "Summarize")]
public class SummarizeContext
{
    public string UserName { get; set; } = string.Empty;
    public string InputText { get; set; } = string.Empty;
    public string MaxWords { get; set; } = "100";
    public string Instructions { get; set; } = "Focus on key points";
}

TemplateName if not set, defaults to the file name without extension of the prompt file.

4. Build and Use

The source generator creates a SummarizePromptBuilder class and a SummarizePromptExtensions extension class:

var context = new SummarizeContext
{
    UserName = "Alice",
    InputText = "AI is transforming industries...",
    MaxWords = "50",
    Instructions = "Keep it neutral"
};

// Use the generated builder
string prompt = context.BuildSummarizePrompt();
// or use below:
//string prompt = SummarizePromptBuilder.Build(context)
Console.WriteLine(prompt);

Template Syntax

PromptEngine uses Mustache template syntax, a logic-less templating system widely used across languages.

Basic Variables

Reference context properties using double curly braces:

Hello {{UserName}}, welcome!

Sections (Conditionals and Loops)

Use sections to conditionally render content or iterate over collections:

{{#HasItems}}
  You have items:
  {{#Items}}
    - {{Name}}: {{Description}}
  {{/Items}}
{{/HasItems}}

Inverted Sections

Render content when a value is false or empty:

{{^HasItems}}
  No items available.
{{/HasItems}}

Nested Properties

Access nested object properties using dot notation:

User: {{User.Name}} ({{User.Email}})

Comments

Add comments that won't appear in the output:

{{! This is a comment and will not be rendered }}

Case Sensitivity

Property lookups are case-sensitive, so {{UserName}}, {{username}}, and {{USERNAME}} reference different properties.

Escaping

All variables are HTML-escaped by default. Use triple braces for unescaped output:

Escaped: {{Content}}
Unescaped: {{{RawHtmlContent}}}

Compile-time Validation

The analyzer provides compile-time template validation during the build.

If your template uses undefined placeholders, you'll get a compile error:

error PE003: Template uses undefined placeholder '{{UndefinedVariable}}' not found in context class 'SummarizeContext'

If you have unused properties in your context, you'll get an info diagnostic:

info PE004: Context property 'UnusedProperty' in class 'SummarizeContext' is not used in template

Runtime Validation

Validate templates at runtime or in CI/CD using the PromptEngine package:

using PromptEngine.Core.Runtime;

var validator = new PromptRuntimeValidator();
validator.LoadMetadataFromDirectory("./bin/Debug/net10.0");

var result = validator.ValidateAll();

if (!result.IsValid)
{
    Console.WriteLine(result.ToString());
    throw new InvalidOperationException("Template validation failed");
}

Agent Framework Integration

Register with dependency injection:

using PromptEngine.Agent.Extensions;

var builder = Host.CreateDefaultBuilder(args)
    .ConfigureServices((context, services) =>
    {
        services.AddPromptEngine();
    });

Use in your agents:

public class MyAgent
{
    private readonly IPromptManager _promptManager;

    public MyAgent(IPromptManager promptManager)
    {
        _promptManager = promptManager;
    }

    public async Task SummarizeAsync(string text)
    {
        var context = new SummarizeContext
        {
            UserName = "User",
            InputText = text,
            MaxWords = "100",
            Instructions = "Keep tone helpful"
        };

        string prompt = SummarizePromptBuilder.Build(context);
        // Use prompt with your LLM...
    }
}

Project Structure

YourProject/
├── Prompts/
│ ├── Summarize.md
│ └── Translate.md
├── Contexts/
│ ├── SummarizeContext.cs
│ └── TranslateContext.cs
└── Program.cs

Add this to your project file to include prompt templates for the generator:

<ItemGroup>
   <AdditionalFiles Include="Prompts/**/*.md" />
</ItemGroup>

Advanced Features

Multiple Templates

[PromptContext("Prompts/Summarize.md", TemplateName = "Summarize")]
public class SummarizeContext { /* ... */ }

[PromptContext("Prompts/Translate.md", TemplateName = "Translate")]
public class TranslateContext { /* ... */ }

Custom Template Path Resolution

The analyzer searches for templates in MSBuild AdditionalFiles. Prefer providing relative paths under your project and include them via <AdditionalFiles />.

Troubleshooting

  • Analyzer does not find templates
  • Ensure your .md files are included via <AdditionalFiles />, and the paths in PromptContext match. Relative paths are recommended. The generator discovers these files at compile time.
  • Placeholders not replaced at runtime
  • Confirm the context properties are public and names match (case-sensitive by default). Use Mustache syntax with double curly braces {{PropertyName}}. The analyzer enforces this at compile time via PE003 / PE004.
  • Template syntax errors
  • Ensure you're using proper Mustache syntax: {{Variable}} for properties, {{#Section}}...{{/Section}} for conditionals/loops, and {{^Inverted}}...{{/Inverted}} for inverted sections.

Requirements

  • .NET 8.0 or later

Contributing

Contributions are welcome! Please submit issues and pull requests.

License

MIT License — see the LICENSE file for details.

Support

For questions and support:


Made with love for the C# AI/Agent community

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.6.3 312 11/17/2025
0.6.2 256 11/10/2025
0.6.1 185 11/7/2025
0.6.0 178 11/7/2025
0.5.3 200 11/4/2025
0.5.2 210 11/3/2025
0.5.1 209 11/3/2025
0.5.0 207 11/3/2025
0.5.0-preview.12 165 11/3/2025
0.5.0-preview.10 164 11/3/2025
0.5.0-preview.9 160 11/3/2025
0.5.0-preview.8 156 11/3/2025
0.5.0-preview.7 159 11/3/2025