Set missingKey: error in a OneLLM prompt definition to stop rendering instead of sending <no value> to the model.
dotnet add package RecursiveAI.OneLlmRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
Save as summary.flow (also in the zip):
name: ticket-summary model: gpt-6-luna missingKey: error initialPrompts: - user: - text: 'Summarize: {{ .inputs.ticket }}'
The example is the full program below: unzip it and dotnet run.
With no ticket input, the example catches TemplateException and prints map has no entry for key "ticket".
The full program
This C# program runs summary.flow twice. The first run omits ticket; the second provides it. A local scripted provider records which requests reach it. The program prints the recorded prompt, not a model response. It uses no API key or network connection. gpt-6-luna is a model name in OneLLM’s OpenAI catalog, used here as a placeholder: ScriptedProvider plays its queued reply without calling that model.
To run the flow against OpenAI, choose a supported model in summary.flow, set OPENAI_API_KEY, and call RunScriptAsync with a plain Runtime and the ticket input instead of registering ScriptedProvider.
using OneLlm; using OneLlm.Templating; using OneLlm.Testing; var provider = new ScriptedProvider("openai"); var runtime = new Runtime(); runtime.Providers.Set("openai", provider); try { await runtime.RunScriptAsync("summary.flow"); throw new InvalidOperationException("Expected a missing ticket error."); } catch (TemplateException error) { Console.WriteLine(error.Detail); Console.WriteLine($"Provider requests: {provider.Requests.Count}"); } provider.EnqueueText("Acknowledged."); // Local stand-in, not a model reply. await runtime.RunScriptAsync("summary.flow", new Dictionary<string, object?> { ["ticket"] = "The receipt did not arrive." }); // Print the prompt the provider actually received, not its scripted reply. Console.WriteLine(provider.Requests.Single().Messages.Last().GetUserText());
map has no entry for key "ticket" Provider requests: 0 Summarize: The receipt did not arrive.
A missing key in a prompt body stops that turn; an earlier turn in the same flow may already have run.
Variations
Give an optional input a default. Add this at the top level of summary.flow, alongside missingKey, when you want a fallback rather than a required ticket:
inputs: ticket: No ticket provided.
Caller-supplied inputs override definition defaults. Keep missingKey: error to catch other missing keys.
Related recipes
The short answer
Set missingKey: error at the top level of the prompt definition. Then reference your required inputs under .inputs in the template and supply their values to Runtime.RunScriptAsync. OneLLM throws TemplateException when a prompt tries to read a missing map key. Without the option, a missing value can appear in the prompt as <no value>. For plain C# templates without a .flow file, set strict mode on Template.Render.
How does missingKey: error differ from a default value?
A default supplies a key even if the caller omits it. If ticket must come from the caller, leave it out of the definition’s inputs map and pass it explicitly from C#. Otherwise the template can read the definition’s default and has no missing key to report. Also distinguish an absent key from a present but empty value: if an empty ticket is invalid, validate its contents before running the flow. Strict mode checks lookup failures, not whether the input is useful text.
Does a missing variable stop every request in a prompt flow?
Only requests for turns that haven’t happened yet. OneLLM renders the system prompt before the first provider request, then renders each user prompt before sending that turn. In this example the first user turn is the one that needs ticket, so the provider receives no requests. In a flow where only a later turn uses a required input, earlier turns can succeed before the missing input stops the run. Validate all caller-required values up front if you need to reject bad input before any turn. Keep those requirements out of when conditions: the scripted run reference says “a when that fails to render counts as true.”