microsoft/semantic-kernel · critical · ServiceInitializationError
Unable to configure learn resources settings.
Error message
Unable to configure learn resources settings.
What it means
Raised by the sample service configurator when constructing ServiceSettings from the .env file fails Pydantic validation. ServiceInitializationError wraps the ValidationError, meaning required environment variables (API keys, endpoints, deployment IDs) are missing or malformed. This is the top-level 'your AI service is not configured' error for the learning samples.
Source
Thrown at python/samples/sk_service_configurator.py:38
"""
Configure the AI service for the kernel
Args:
kernel (Kernel): The kernel to configure
use_chat (bool): Whether to use the chat completion model, or the text completion model
env_file_path (str | None): The absolute or relative file path to the .env file.
env_file_encoding (str | None): The desired type of encoding. Defaults to utf-8.
Returns:
Kernel: The configured kernel
"""
try:
settings = ServiceSettings(
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
except ValidationError as ex:
raise ServiceInitializationError("Unable to configure learn resources settings.", ex) from ex
if "global_llm_service" not in settings.model_fields_set:
print("GLOBAL_LLM_SERVICE not set, trying to use Azure OpenAI.")
# The service_id is used to identify the service in the kernel.
# This can be updated to a custom value if needed.
# It should match the execution setting's key in a config.json file.
service_id = "default"
# Configure AI service used by the kernel. Load settings from the .env file.
if settings.global_llm_service == "OpenAI":
if use_chat:
# <OpenAIKernelCreation>
kernel.add_service(OpenAIChatCompletion(service_id=service_id))
# </OpenAIKernelCreation>
else:
# <OpenAITextCompletionKernelCreation>
kernel.add_service(OpenAITextCompletion(service_id=service_id))View on GitHub (pinned to c028a0c7dc)
Solutions
- Create/populate the .env file with the required keys for your provider (OPENAI_API_KEY, or AZURE_OPENAI_KEY + AZURE_OPENAI_ENDPOINT + AZURE_OPENAI_DEPLOYMENT_NAME).
- Confirm env var names exactly match ServiceSettings field names / aliases.
- Set GLOBAL_LLM_SERVICE to 'OpenAI' or 'Azure' to match the credentials you provided.
- Read the wrapped ValidationError (ex) in the traceback — it lists exactly which fields failed.
Example fix
# .env OPENAI_API_KEY=sk-... # or Azure: AZURE_OPENAI_KEY=... AZURE_OPENAI_ENDPOINT=https://<resource>.openai.azure.com AZURE_OPENAI_DEPLOYMENT_NAME=<deployment> GLOBAL_LLM_SERVICE=OpenAI
Defensive patterns
Strategy: try-catch
Validate before calling
# Validate required env vars exist before constructing the kernel.
import os
missing = [k for k in ('OPENAI_API_KEY',) if not os.getenv(k)] and [] or []
# Best: let ServiceSettings validate, then read its ValidationError detail for exact fields. Try / catch
from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError
try:
kernel = create_kernel_from_env(...)
except ServiceInitializationError as e:
# e.__cause__ is the Pydantic ValidationError listing the bad fields
print('Fix these settings:', e.__cause__)
raise Prevention
- Keep a complete .env with all required provider keys.
- Match env var names to ServiceSettings field aliases.
- Set GLOBAL_LLM_SERVICE to match your provider.
- Read the wrapped ValidationError to find the exact failing fields.
When it happens
Trigger: ServiceSettings(...) raises ValidationError — e.g. missing OPENAI_API_KEY / AZURE_OPENAI_KEY / endpoint / deployment env vars, or wrong types/values.
Common situations: No .env file or one missing the required keys; env var names don't match what ServiceSettings expects; wrong GLOBAL_LLM_SERVICE value; copy-paste errors (extra quotes, spaces) in keys.
Related errors
- Failed to initialize the booking sample settings.
- Failed to get a response from the chat completion service.
- Failed to create Azure OpenAI settings: {exc}
- Failed to create OpenAI settings.
- Configuration not found, please setup the notebooks first us
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/71b4c65e34cdff42.
Report an issue: GitHub.