microsoft/semantic-kernel · error · ArgumentException
Invalid template format: {config.TemplateFormat}
Error message
Invalid template format: {config.TemplateFormat} What it means
Thrown by the LiquidPromptTemplate constructor when `config.TemplateFormat` does not equal `LiquidPromptTemplateFactory.LiquidTemplateFormat` (the liquid format identifier). This is a strict guard: the Liquid template engine only handles Liquid-format configs, and passing a mismatched format (e.g. a Handlebars or semantic-kernel format string) is treated as a programming error rather than a render error.
Source
Thrown at dotnet/src/Extensions/PromptTemplates.Liquid/LiquidPromptTemplate.cs:55
#else
private static Regex RoleRegex() => s_roleRegex;
private static readonly Regex s_roleRegex = new(@"(?<role>system|assistant|user|function|developer):\s+", RegexOptions.Compiled);
#endif
/// <summary>Initializes the <see cref="LiquidPromptTemplate"/>.</summary>
/// <param name="config">Prompt template configuration</param>
/// <param name="allowDangerouslySetContent">Whether to allow dangerously set content in the template</param>
/// <exception cref="ArgumentException">throw if <see cref="PromptTemplateConfig.TemplateFormat"/> is not <see cref="LiquidPromptTemplateFactory.LiquidTemplateFormat"/></exception>
/// <exception cref="ArgumentException">The template in <paramref name="config"/> could not be parsed.</exception>
/// <exception cref="ArgumentNullException">throw if <paramref name="config"/> is null</exception>
/// <exception cref="ArgumentNullException">throw if the template in <paramref name="config"/> is null</exception>
public LiquidPromptTemplate(PromptTemplateConfig config, bool allowDangerouslySetContent = false)
{
Verify.NotNull(config, nameof(config));
Verify.NotNull(config.Template, nameof(config.Template));
if (config.TemplateFormat != LiquidPromptTemplateFactory.LiquidTemplateFormat)
{
throw new ArgumentException($"Invalid template format: {config.TemplateFormat}");
}
this._allowDangerouslySetContent = allowDangerouslySetContent;
this._config = config;
// Parse the template now so we can check for errors, understand variable usage, and
// avoid having to parse on each render.
if (!s_parser.TryParse(config.Template, out this._liquidTemplate, out string error))
{
throw new ArgumentException(error is not null ?
$"The template could not be parsed:{Environment.NewLine}{error}" :
"The template could not be parsed.");
}
// Ideally the prompty author would have explicitly specified input variables. If they specified any,
// assume they specified them all. If they didn't, heuristically try to find the variables, looking for
// variables that are read but never written and that appear to be simple values rather than complex objects.
if (config.InputVariables.Count == 0)View on GitHub (pinned to c028a0c7dc)
Solutions
- Set `config.TemplateFormat = LiquidPromptTemplateFactory.LiquidTemplateFormat` before constructing.
- Use `LiquidPromptTemplateFactory` to create the template so the format is set correctly for you.
- Verify the format string spelling against the constant rather than hard-coding a literal.
Example fix
// before
var config = new PromptTemplateConfig { TemplateFormat = "handlebars", Template = "{{user}}" };
var t = new LiquidPromptTemplate(config);
// after
var config = new PromptTemplateConfig { TemplateFormat = LiquidPromptTemplateFactory.LiquidTemplateFormat, Template = "{{user}}" };
var t = new LiquidPromptTemplate(config); Defensive patterns
Strategy: validation
Validate before calling
if (config.TemplateFormat != LiquidPromptTemplateFactory.LiquidTemplateFormat) {
config.TemplateFormat = LiquidPromptTemplateFactory.LiquidTemplateFormat;
}
var template = new LiquidPromptTemplate(config); Try / catch
try { var t = new LiquidPromptTemplate(config); }
catch (ArgumentException ex) when (ex.Message.Contains("Invalid template format")) {
// log and surface a clear config error to the user
} Prevention
- Prefer LiquidPromptTemplateFactory.Create over manual construction.
- Centralize PromptTemplateConfig creation so the format is always paired with the right engine.
When it happens
Trigger: Constructing `new LiquidPromptTemplate(config)` where `config.TemplateFormat` was set to `PromptTemplateConfig.SemanticKernelTemplateFormat` or a custom string, or reusing a config originally built for another factory.
Common situations: Mixing template engines in one app; copy-pasting a PromptTemplateConfig from a Handlebars example into Liquid code; reading config from JSON/YAML where the format field is wrong or misspelled.
Related errors
- Message must have a role.
- The template could not be parsed:{Environment.NewLine}{error
- Argument '{propertyName}' has a value that doesn't support a
- Configuration not found, please setup the notebooks first us
- AZURE_OPENAI_ENDPOINT is not set.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/b8feb26cad1f6acd.
Report an issue: GitHub.