microsoft/semantic-kernel · critical · InvalidOperationException
Please provide valid Ollama configuration in appsettings.Dev
Error message
Please provide valid Ollama configuration in appsettings.Development.json file.
What it means
InitializeKernelForOllama reads Ollama:ChatModelId and Ollama:Endpoint from configuration and throws InvalidOperationException if either is null/empty before building the Ollama-backed kernel. Endpoint is required so the connector can reach the local/remote Ollama instance.
Source
Thrown at dotnet/samples/Demos/CopilotAgentPlugins/CopilotAgentPluginsDemoSample/DemoCommand.cs:229
}
}
private async Task ExecuteGoalAsync(Kernel kernel, PromptExecutionSettings promptExecutionSettings)
{
var goal = AnsiConsole.Ask<string>("Enter your goal:");
var result = await kernel.InvokePromptAsync(goal, new KernelArguments(promptExecutionSettings)).ConfigureAwait(false);
var panel = new Panel($"[bold]Result[/]{Environment.NewLine}{Environment.NewLine}[green italic]{Markup.Escape(result.ToString())}[/]");
AnsiConsole.Write(panel);
}
private static (Kernel, PromptExecutionSettings) InitializeKernelForOllama(IConfiguration configuration, bool enableLogging)
{
var engineConfig = configuration.GetSection("Ollama");
var chatModelId = engineConfig["ChatModelId"];
var endpoint = engineConfig["Endpoint"];
if (string.IsNullOrEmpty(chatModelId) || string.IsNullOrEmpty(endpoint))
{
throw new InvalidOperationException("Please provide valid Ollama configuration in appsettings.Development.json file.");
}
var builder = Kernel.CreateBuilder();
if (enableLogging)
{
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddFilter(level => true);
loggingBuilder.AddProvider(new SemanticKernelLoggerProvider());
});
}
#pragma warning disable SKEXP0001
return (builder.AddOllamaChatCompletion(
chatModelId,
new Uri(endpoint)).Build(),
new OllamaPromptExecutionSettings
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(View on GitHub (pinned to c028a0c7dc)
Solutions
- Add an Ollama section: { "Ollama": { "ChatModelId": "llama3.2", "Endpoint": "http://localhost:11434" } }.
- Ensure Ollama is installed and the named model is pulled (`ollama pull <model>`).
- Verify the endpoint URL is reachable from the host running the sample.
- Set via environment variables Ollama__ChatModelId / Ollama__Endpoint if you prefer not to edit JSON.
Example fix
// before
if (string.IsNullOrEmpty(chatModelId) || string.IsNullOrEmpty(endpoint))
throw new InvalidOperationException("Please provide valid Ollama configuration...");
// after (appsettings.Development.json)
{
"Ollama": { "ChatModelId": "llama3.2", "Endpoint": "http://localhost:11434" }
} Defensive patterns
Strategy: validation
Validate before calling
var chatModelId = configuration["Ollama:ChatModelId"];
var endpoint = configuration["Ollama:Endpoint"];
if (string.IsNullOrWhiteSpace(chatModelId) || string.IsNullOrWhiteSpace(endpoint))
throw new InvalidOperationException("Set Ollama:ChatModelId and Ollama:Endpoint (e.g. http://localhost:11434)."); Type guard
static bool HasOllamaConfig(IConfiguration c) =>
!string.IsNullOrEmpty(c["Ollama:ChatModelId"]) && !string.IsNullOrEmpty(c["Ollama:Endpoint"]); Prevention
- Ensure Ollama is installed and the model is pulled before running.
- Use env vars Ollama__ChatModelId / Ollama__Endpoint for CI.
- Verify the endpoint URL is reachable from the host.
When it happens
Trigger: configuration.GetSection("Ollama")["ChatModelId"] or ["Endpoint"] is null or empty string.
Common situations: Ollama section missing from appsettings.Development.json, Ollama not running locally so the user skipped config, or endpoint/model keys renamed.
Related errors
- Invalid kernel selection. {selectedKernelName} is not a vali
- Please provide valid AzureOpenAI configuration in appsetting
- Please provide valid OpenAI configuration in appsettings.Dev
- Configuration is not setup correctly.
- Please provide valid MSGraph configuration in appsettings.De
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/47afa19fad16ff96.
Report an issue: GitHub.