ProgramPromptTemplate

Models & Types · AiDotNet.Evolution.Prompts

One piece of prompt text with named {placeholder} slots, parsed once and rendered many times.

For Beginners

This is a fill-in-the-blanks piece of text. The blanks are written as {name}, and rendering means handing over a value for each blank and getting the finished text back. If you need a real curly brace in the output — for example when the text shows a JSON example — write it twice, as {{ or }}. The list of blanks a template contains is worked out as soon as the template is created, so mistakes surface while you are setting things up rather than in the middle of a long run.

How It Works

A template is immutable and its placeholders are discovered when it is constructed, not when it is rendered. That single decision is what allows a whole template set to be checked at configure time: the set knows which names each template asks for and can compare them against the names the prompt builder is able to supply, long before any model is called. Rendering itself is a pure function of the text and the supplied values — no clocks, no culture, no ambient state — so the same inputs always produce the same characters.

The placeholder syntax matches the one the reference OpenEvolve templates use, so existing template files transfer unchanged: {name} marks a slot, and {{ and }} escape literal braces (which is how the JSON example inside the shipped evaluation template survives). Unlike upstream, an unbalanced or malformed brace is rejected here rather than raising an error from deep inside a formatting call during a run.

Line endings are normalized to line feeds when the template is created. Without that, a template file checked out with Windows line endings and the same file checked out with Unix ones would produce different prompt text and different template hashes, which would break both cross-machine reproducibility and checkpoint resume for a reason that has nothing to do with the wording.

Constructors

Constructor Summary
ProgramPromptTemplate(string text) Initializes a template from its text, normalizing line endings and parsing its placeholders.

Properties

Property Summary
IReadOnlyList<string> Placeholders { get; } Gets the distinct placeholder names this template contains, in first-appearance order.
bool IsConstant { get; } Gets whether this template contains no placeholders and renders to a constant string.
string Text { get; } Gets the template text with every line ending normalized to a line feed.

Methods

Method Summary
bool ContainsPlaceholder(string name) Reports whether this template contains a placeholder with the given name.
string Render(IReadOnlyDictionary<string, string> values) Renders the template by substituting a value for every placeholder.
string ToString() Returns a short description that never echoes the template text.

Fields

Field Summary
int MaxTextLength The largest template text accepted, in characters.