{"record":{"id":"47afa19fad16ff96","repo":"microsoft/semantic-kernel","slug":"please-provide-valid-ollama-configuration-in-appse","errorCode":null,"errorMessage":"Please provide valid Ollama configuration in appsettings.Development.json file.","messagePattern":"Please provide valid Ollama configuration in appsettings\\.Development\\.json file\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"dotnet/samples/Demos/CopilotAgentPlugins/CopilotAgentPluginsDemoSample/DemoCommand.cs","lineNumber":229,"sourceCode":"        }\n    }\n\n    private async Task ExecuteGoalAsync(Kernel kernel, PromptExecutionSettings promptExecutionSettings)\n    {\n        var goal = AnsiConsole.Ask<string>(\"Enter your goal:\");\n        var result = await kernel.InvokePromptAsync(goal, new KernelArguments(promptExecutionSettings)).ConfigureAwait(false);\n        var panel = new Panel($\"[bold]Result[/]{Environment.NewLine}{Environment.NewLine}[green italic]{Markup.Escape(result.ToString())}[/]\");\n        AnsiConsole.Write(panel);\n    }\n\n    private static (Kernel, PromptExecutionSettings) InitializeKernelForOllama(IConfiguration configuration, bool enableLogging)\n    {\n        var engineConfig = configuration.GetSection(\"Ollama\");\n        var chatModelId = engineConfig[\"ChatModelId\"];\n        var endpoint = engineConfig[\"Endpoint\"];\n        if (string.IsNullOrEmpty(chatModelId) || string.IsNullOrEmpty(endpoint))\n        {\n            throw new InvalidOperationException(\"Please provide valid Ollama configuration in appsettings.Development.json file.\");\n        }\n\n        var builder = Kernel.CreateBuilder();\n        if (enableLogging)\n        {\n            builder.Services.AddLogging(loggingBuilder =>\n                {\n                    loggingBuilder.AddFilter(level => true);\n                    loggingBuilder.AddProvider(new SemanticKernelLoggerProvider());\n                });\n        }\n#pragma warning disable SKEXP0001\n        return (builder.AddOllamaChatCompletion(\n                chatModelId,\n                new Uri(endpoint)).Build(),\n                new OllamaPromptExecutionSettings\n                {\n                    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/CopilotAgentPlugins/CopilotAgentPluginsDemoSample/DemoCommand.cs#L211-L247","documentation":"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.","triggerScenarios":"configuration.GetSection(\"Ollama\")[\"ChatModelId\"] or [\"Endpoint\"] is null or empty string.","commonSituations":"Ollama section missing from appsettings.Development.json, Ollama not running locally so the user skipped config, or endpoint/model keys renamed.","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."],"exampleFix":"// before\nif (string.IsNullOrEmpty(chatModelId) || string.IsNullOrEmpty(endpoint))\n    throw new InvalidOperationException(\"Please provide valid Ollama configuration...\");\n\n// after (appsettings.Development.json)\n{\n  \"Ollama\": { \"ChatModelId\": \"llama3.2\", \"Endpoint\": \"http://localhost:11434\" }\n}","handlingStrategy":"validation","validationCode":"var chatModelId = configuration[\"Ollama:ChatModelId\"];\nvar endpoint = configuration[\"Ollama:Endpoint\"];\nif (string.IsNullOrWhiteSpace(chatModelId) || string.IsNullOrWhiteSpace(endpoint))\n    throw new InvalidOperationException(\"Set Ollama:ChatModelId and Ollama:Endpoint (e.g. http://localhost:11434).\");","typeGuard":"static bool HasOllamaConfig(IConfiguration c) =>\n    !string.IsNullOrEmpty(c[\"Ollama:ChatModelId\"]) && !string.IsNullOrEmpty(c[\"Ollama:Endpoint\"]);","tryCatchPattern":null,"preventionTips":["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."],"tags":["configuration","ollama","kernel","samples"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}