{"record":{"id":"71b4c65e34cdff42","repo":"microsoft/semantic-kernel","slug":"unable-to-configure-learn-resources-settings","errorCode":null,"errorMessage":"Unable to configure learn resources settings.","messagePattern":"Unable to configure learn resources settings\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"critical","filePath":"python/samples/sk_service_configurator.py","lineNumber":38,"sourceCode":"    \"\"\"\n    Configure the AI service for the kernel\n\n    Args:\n        kernel (Kernel): The kernel to configure\n        use_chat (bool): Whether to use the chat completion model, or the text completion model\n        env_file_path (str | None): The absolute or relative file path to the .env file.\n        env_file_encoding (str | None): The desired type of encoding. Defaults to utf-8.\n\n    Returns:\n        Kernel: The configured kernel\n    \"\"\"\n    try:\n        settings = ServiceSettings(\n            env_file_path=env_file_path,\n            env_file_encoding=env_file_encoding,\n        )\n    except ValidationError as ex:\n        raise ServiceInitializationError(\"Unable to configure learn resources settings.\", ex) from ex\n\n    if \"global_llm_service\" not in settings.model_fields_set:\n        print(\"GLOBAL_LLM_SERVICE not set, trying to use Azure OpenAI.\")\n\n    # The service_id is used to identify the service in the kernel.\n    # This can be updated to a custom value if needed.\n    # It should match the execution setting's key in a config.json file.\n    service_id = \"default\"\n\n    # Configure AI service used by the kernel. Load settings from the .env file.\n    if settings.global_llm_service == \"OpenAI\":\n        if use_chat:\n            # <OpenAIKernelCreation>\n            kernel.add_service(OpenAIChatCompletion(service_id=service_id))\n            # </OpenAIKernelCreation>\n        else:\n            # <OpenAITextCompletionKernelCreation>\n            kernel.add_service(OpenAITextCompletion(service_id=service_id))","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/samples/sk_service_configurator.py#L20-L56","documentation":"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.","triggerScenarios":"ServiceSettings(...) raises ValidationError — e.g. missing OPENAI_API_KEY / AZURE_OPENAI_KEY / endpoint / deployment env vars, or wrong types/values.","commonSituations":"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.","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."],"exampleFix":"# .env\nOPENAI_API_KEY=sk-...\n# or Azure:\nAZURE_OPENAI_KEY=...\nAZURE_OPENAI_ENDPOINT=https://<resource>.openai.azure.com\nAZURE_OPENAI_DEPLOYMENT_NAME=<deployment>\nGLOBAL_LLM_SERVICE=OpenAI","handlingStrategy":"try-catch","validationCode":"# Validate required env vars exist before constructing the kernel.\nimport os\nmissing = [k for k in ('OPENAI_API_KEY',) if not os.getenv(k)] and [] or []\n# Best: let ServiceSettings validate, then read its ValidationError detail for exact fields.","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\ntry:\n    kernel = create_kernel_from_env(...)\nexcept ServiceInitializationError as e:\n    # e.__cause__ is the Pydantic ValidationError listing the bad fields\n    print('Fix these settings:', e.__cause__)\n    raise","preventionTips":["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."],"tags":["configuration","env","ai-service","pydantic","semantic-kernel","sample"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}