LLTSharp 1.1.0
dotnet add package LLTSharp --version 1.1.0
NuGet\Install-Package LLTSharp -Version 1.1.0
<PackageReference Include="LLTSharp" Version="1.1.0" />
<PackageVersion Include="LLTSharp" Version="1.1.0" />
<PackageReference Include="LLTSharp" />
paket add LLTSharp --version 1.1.0
#r "nuget: LLTSharp, 1.1.0"
#:package LLTSharp@1.1.0
#addin nuget:?package=LLTSharp&version=1.1.0
#tool nuget:?package=LLTSharp&version=1.1.0
LLTSharp
A flexible and expressive template engine for Large Language Model (LLM) prompts and structured message generation in C#.
LLT is designed to make prompt engineering and content generation as powerful and maintainable as regular C# code.
✨ Key Features
- Razor-inspired DSL with
@if,@foreach, expressions, metadata, and inline variables - Message-oriented syntax for LLM role structures (system, user, assistant)
- Powerful metadata filtering — select the best template by language, model, or custom qualifiers
- Composable templates — reuse and render nested templates inside others
- Deterministic formatting — preserves whitespace and indentation, ensuring predictable output
- Expression evaluator — supports arithmetic, logic, method access, array indexing, and ternary operators
- Library-driven workflow — import templates from assemblies, files, or strings
📦 Installation
Install the package from NuGet:
dotnet add package LLTSharp
Or via the Package Manager Console:
Install-Package LLTSharp
💡 Example
var parser = new LLTParser();
var templateStr = """
@template GreetingTemplate
{
Greetings, @name!
@if age > 18
{
You are an adult.
}
else
{
You are too young!
}
Have a nice day.
}
""";
var template = parser.Parse(templateStr).First();
var adult = new { name = "Andrew", age = 20 };
var young = new { name = "Alice", age = 15 };
Console.WriteLine(template.Render(adult));
Console.WriteLine(template.Render(young));
Output:
Greetings, Andrew!
You are an adult.
Have a nice day.
Greetings, Alice!
You are too young!
Have a nice day.
🧩 Template Library Usage
Multiple templates can be stored, versioned, and retrieved by language or model ID:
var lib = new TemplateLibrary();
lib.ImportFromString("""
@template greeting
{
@metadata { lang: 'en' }
Hello!
}
@template greeting
{
@metadata { lang: 'en', model: 'gpt-4' }
Hello GPT-4!
}
@template greeting
{
@metadata { lang: 'es' }
Hola!
}
""");
var template = lib.Retrieve("greeting", new LanguageMetadata("en"), new TargetModelMetadata("gpt-4"));
Console.WriteLine(template.Render()); // Hello GPT-4!
Templates are resolved by metadata specificity, similar to CSS selector priority.
💬 Message Templates for LLM Chats
LLT supports special @messages syntax for structured chat prompts:
@messages template ChatBot
{
@metadata { language: 'en', version: 1 }
@system message {
You are a helpful assistant.
Here is your instructions:
@foreach instruction in instructions {
Instruction: @instruction
}
}
@foreach name in names {
@message {
@role 'user'
Hello, I am @name!
}
}
}
Rendered result: a sequence of chat messages with proper roles (system, user, assistant).
🧠 Supported Syntax
- Inline expressions:
@(a + b * c) - Conditionals:
@if cond { ... } else if other { ... } else { ... } - Loops:
@foreach item in items { @item } - Variables:
@let x = 5 @x = 10 @x - Nested or external templates:
@render 'other_template' - Comments:
@// line comment @* block comment *@
🧾 Formatting & Scoping Rules
- Whitespace and indentation in source templates are fully preserved
@letvariables are lexically scoped- Loop variables do not leak outside their block
- Nested
@ifand@foreachblocks behave predictably, matching C#‑like logical semantics
🏗️ Architecture Overview
- LLTParser – parses source text into ASTs (
TemplateNode,TemplateExpressionNode, etc.) - Template – runtime object capable of rendering with dynamic context
- TemplateLibrary – registry and loader for collections of templates with filtering
- Metadata System – extensible mechanism for attaching attributes such as language, model, or custom version
- ChatMessage Model – unified representation for structured message templates (
system,user,assistant)
🔖 License
MIT License © 2025
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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. |
-
.NETStandard 2.0
- Microsoft.Extensions.AI.Abstractions (>= 9.10.0)
- RCParsing (>= 4.7.1)
-
net6.0
- Microsoft.Extensions.AI.Abstractions (>= 9.10.0)
- RCParsing (>= 4.7.1)
-
net8.0
- Microsoft.Extensions.AI.Abstractions (>= 9.10.0)
- RCParsing (>= 4.7.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.