{"record":{"id":"981d817ac5e20c58","repo":"microsoft/semantic-kernel","slug":"failed-to-validate-settings-exc","errorCode":null,"errorMessage":"Failed to validate settings: {exc}","messagePattern":"Failed to validate settings: (.+?)","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/azure_chat_completion.py","lineNumber":99,"sourceCode":"            env_file_path (str | None): Use the environment settings file as a fallback to using env vars.\n            env_file_encoding (str | None): The encoding of the environment settings file, defaults to 'utf-8'.\n            instruction_role (str | None): The role to use for 'instruction' messages, for example, summarization\n                prompts could use `developer` or `system`. (Optional)\n            credential (TokenCredential): The credential to use for authentication.\n        \"\"\"\n        try:\n            azure_openai_settings = AzureOpenAISettings(\n                api_key=api_key,\n                base_url=base_url,\n                endpoint=endpoint,\n                chat_deployment_name=deployment_name,\n                api_version=api_version,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n                token_endpoint=token_endpoint,\n            )\n        except ValidationError as exc:\n            raise ServiceInitializationError(f\"Failed to validate settings: {exc}\") from exc\n\n        if not azure_openai_settings.chat_deployment_name:\n            raise ServiceInitializationError(\"chat_deployment_name is required.\")\n\n        super().__init__(\n            deployment_name=azure_openai_settings.chat_deployment_name,\n            endpoint=azure_openai_settings.endpoint,\n            base_url=azure_openai_settings.base_url,\n            api_version=azure_openai_settings.api_version,\n            service_id=service_id,\n            api_key=azure_openai_settings.api_key.get_secret_value() if azure_openai_settings.api_key else None,\n            ad_token=ad_token,\n            ad_token_provider=ad_token_provider,\n            token_endpoint=azure_openai_settings.token_endpoint,\n            default_headers=default_headers,\n            ai_model_type=OpenAIModelTypes.CHAT,\n            client=async_client,\n            instruction_role=instruction_role,","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/azure_chat_completion.py#L81-L117","documentation":"When constructing AzureChatCompletionService, the AzureOpenAISettings pydantic model is validated from constructor arguments and environment variables. If pydantic raises a ValidationError, it's caught and re-raised as ServiceInitializationError with the message 'Failed to validate settings' plus the full validation error detail. This is a construction-time configuration error.","triggerScenarios":"Passing invalid constructor values to AzureChatCompletionService (malformed endpoint URL, wrong api_version format, invalid base_url) or having malformed AZURE_OPENAI_* environment variables that fail pydantic validation.","commonSituations":"Typo in AZURE_OPENAI_ENDPOINT (missing https://); AZURE_OPENAI_API_VERSION in wrong format; .env file not loaded (python-dotenv not called); invalid characters in env values; SDK upgrade adding new required or constrained fields.","solutions":["Read the ValidationError detail in the exception message — pydantic specifies each failing field and the reason.","Fix the flagged fields: ensure endpoint is a valid https URL, api_version is YYYY-MM-DD-preview format.","Verify your .env file is loaded (call load_dotenv() or pass env_file_path).","Pass settings explicitly in the constructor to bypass env var issues during debugging."],"exampleFix":"// before\nservice = AzureChatCompletionService(deployment_name='gpt-4', endpoint='localhost:8080')\n// after\nservice = AzureChatCompletionService(\n    deployment_name='gpt-4',\n    endpoint='https://my-resource.openai.azure.com/',\n    api_key='...',\n    api_version='2024-02-15-preview'\n)","handlingStrategy":"try-catch","validationCode":"def validate_azure_chat_settings_kwargs(endpoint: str, api_version: str) -> None:\n    if endpoint and not endpoint.startswith('https://'):\n        raise ValueError(f'endpoint must be an https URL, got: {endpoint}')\n    if api_version:\n        import re\n        if not re.match(r'^\\d{4}-\\d{2}-\\d{2}', api_version):\n            raise ValueError(f'api_version should be YYYY-MM-DD format, got: {api_version}')","typeGuard":"def are_azure_chat_args_valid(endpoint: str, api_version: str) -> bool:\n    import re\n    if endpoint and not endpoint.startswith('https://'):\n        return False\n    if api_version and not re.match(r'^\\d{4}-\\d{2}-\\d{2}', api_version):\n        return False\n    return True","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\n\ntry:\n    service = AzureChatCompletionService(endpoint=ep, api_key=key, deployment_name=dep)\nexcept ServiceInitializationError as e:\n    print(f'Settings validation failed: {e}')\n    # read the pydantic error detail to fix the specific field","preventionTips":["Ensure AZURE_OPENAI_ENDPOINT is a valid https URL.","Ensure AZURE_OPENAI_API_VERSION follows YYYY-MM-DD format.","Call load_dotenv() before constructing services.","Pass constructor args explicitly during debugging to isolate env issues."],"tags":["azure-openai","chat-completion","initialization","settings","pydantic","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}