Register a C# helper to format values as the prompt renders. No model needed.
dotnet add package RecursiveAI.OneLlmRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
{{ ticket .id }} calls ticket with the id value; the function name and its arguments are separated by spaces.
using OneLlm.Templating; var functions = new TemplateFunctions() .Add("ticket", id => $"SUP-{id}"); var parse = new TemplateParseOptions { Functions = functions }; var values = new Dictionary<string, object?> { ["id"] = "42" }; const string prompt = "Summarize {{ ticket .id }}."; Console.WriteLine( Template.Render(prompt, values, parse));
If ticket isn’t in the function registry passed at parse time, TemplateException reports an undefined function.
Unzip the example, then dotnet run.
Summarize SUP-42.Variations
Pass the ID through a pipeline. Replace the prompt constant with this equivalent template, where the left side becomes the function’s argument:
const string prompt = "Summarize {{ .id | ticket }}.";
Related recipes
The short answer
Create a TemplateFunctions registry, add a named C# delegate, and pass that registry in TemplateParseOptions.Functions. The action {{ ticket .id }} calls ticket with the scope’s id value. Here Add uses the overload for a single string argument. The delegate returns SUP-42 for input 42, and the renderer inserts that string into the prompt. It doesn’t ask a model to format the ID.
How do you pass arguments to a custom template function?
Use spaces between the function name and its arguments, not C# call syntax. A dot before id tells the template to look up that field in the current scope. In a pipeline, the prior result becomes the last argument of the next call; with only one argument, {{ .id | ticket }} and {{ ticket .id }} mean the same thing.
Match the delegate’s argument kind to the data you supply. Here the ID is the string "42"; the one-string Add overload declares ArgKind.Text. For a helper that takes a number or Boolean, the function reference describes declaring argument kinds explicitly with the TemplateFunction API. Keep formatting in the delegate and leave input lookup in the template so the same formatter can process IDs from different fields.
Why is my custom function undefined in the template?
The parser needs to know the function name before it can accept the action. Pass the registry you added ticket to as a parse option, and check that you used the same spelling and case in the template. If you use Template.Parse separately so you can render with different input maps, pass the registry at that call; changing the input dictionary can’t register a new function. Finish adding functions before rendering. A new registry starts with the standard helpers, but adding an existing name replaces that function for templates that use your registry. Use a distinct name when you want to keep the original behavior.