{"record":{"id":"b8feb26cad1f6acd","repo":"microsoft/semantic-kernel","slug":"invalid-template-format-config-templateformat","errorCode":null,"errorMessage":"Invalid template format: {config.TemplateFormat}","messagePattern":"Invalid template format: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Extensions/PromptTemplates.Liquid/LiquidPromptTemplate.cs","lineNumber":55,"sourceCode":"#else\n    private static Regex RoleRegex() => s_roleRegex;\n    private static readonly Regex s_roleRegex = new(@\"(?<role>system|assistant|user|function|developer):\\s+\", RegexOptions.Compiled);\n#endif\n\n    /// <summary>Initializes the <see cref=\"LiquidPromptTemplate\"/>.</summary>\n    /// <param name=\"config\">Prompt template configuration</param>\n    /// <param name=\"allowDangerouslySetContent\">Whether to allow dangerously set content in the template</param>\n    /// <exception cref=\"ArgumentException\">throw if <see cref=\"PromptTemplateConfig.TemplateFormat\"/> is not <see cref=\"LiquidPromptTemplateFactory.LiquidTemplateFormat\"/></exception>\n    /// <exception cref=\"ArgumentException\">The template in <paramref name=\"config\"/> could not be parsed.</exception>\n    /// <exception cref=\"ArgumentNullException\">throw if <paramref name=\"config\"/> is null</exception>\n    /// <exception cref=\"ArgumentNullException\">throw if the template in <paramref name=\"config\"/> is null</exception>\n    public LiquidPromptTemplate(PromptTemplateConfig config, bool allowDangerouslySetContent = false)\n    {\n        Verify.NotNull(config, nameof(config));\n        Verify.NotNull(config.Template, nameof(config.Template));\n        if (config.TemplateFormat != LiquidPromptTemplateFactory.LiquidTemplateFormat)\n        {\n            throw new ArgumentException($\"Invalid template format: {config.TemplateFormat}\");\n        }\n\n        this._allowDangerouslySetContent = allowDangerouslySetContent;\n        this._config = config;\n\n        // Parse the template now so we can check for errors, understand variable usage, and\n        // avoid having to parse on each render.\n        if (!s_parser.TryParse(config.Template, out this._liquidTemplate, out string error))\n        {\n            throw new ArgumentException(error is not null ?\n                $\"The template could not be parsed:{Environment.NewLine}{error}\" :\n                 \"The template could not be parsed.\");\n        }\n\n        // Ideally the prompty author would have explicitly specified input variables. If they specified any,\n        // assume they specified them all. If they didn't, heuristically try to find the variables, looking for\n        // variables that are read but never written and that appear to be simple values rather than complex objects.\n        if (config.InputVariables.Count == 0)","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Extensions/PromptTemplates.Liquid/LiquidPromptTemplate.cs#L37-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar config = new PromptTemplateConfig { TemplateFormat = \"handlebars\", Template = \"{{user}}\" };\nvar t = new LiquidPromptTemplate(config);\n// after\nvar config = new PromptTemplateConfig { TemplateFormat = LiquidPromptTemplateFactory.LiquidTemplateFormat, Template = \"{{user}}\" };\nvar t = new LiquidPromptTemplate(config);","handlingStrategy":"validation","validationCode":"if (config.TemplateFormat != LiquidPromptTemplateFactory.LiquidTemplateFormat) {\n    config.TemplateFormat = LiquidPromptTemplateFactory.LiquidTemplateFormat;\n}\nvar template = new LiquidPromptTemplate(config);","typeGuard":null,"tryCatchPattern":"try { var t = new LiquidPromptTemplate(config); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid template format\")) {\n    // log and surface a clear config error to the user\n}","preventionTips":["Prefer LiquidPromptTemplateFactory.Create over manual construction.","Centralize PromptTemplateConfig creation so the format is always paired with the right engine."],"tags":["liquid","prompt-template","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}