{"record":{"id":"ad37dc4a86b8b2e1","repo":"microsoft/semantic-kernel","slug":"failed-to-create-azure-openai-settings-exc","errorCode":null,"errorMessage":"Failed to create Azure OpenAI settings: {exc}","messagePattern":"Failed to create Azure OpenAI settings: (.+?)","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/azure_assistant_agent.py","lineNumber":99,"sourceCode":"            credential: The credential to use for authentication.\n            kwargs: Additional keyword arguments\n\n        Returns:\n            An Azure OpenAI client instance and the configured deployment name (model)\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_scope,\n            )\n        except ValidationError as exc:\n            raise AgentInitializationException(f\"Failed to create Azure OpenAI settings: {exc}\") from exc\n\n        if (\n            azure_openai_settings.api_key is None\n            and ad_token_provider is None\n            and ad_token is None\n            and azure_openai_settings.token_endpoint\n            and credential\n        ):\n            ad_token = get_entra_auth_token(credential, azure_openai_settings.token_endpoint)\n\n        # If we still have no credentials, we can't proceed\n        if not azure_openai_settings.api_key and not ad_token and not ad_token_provider and not credential:\n            raise AgentInitializationException(\n                \"Please provide either an api_key, ad_token, ad_token_provider or credential for authentication.\"\n            )\n\n        merged_headers = dict(copy(default_headers)) if default_headers else {}\n        if default_headers:","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/azure_assistant_agent.py#L81-L117","documentation":"While constructing the AsyncAzureOpenAI client, the agent builds an AzureOpenAISettings object from supplied args/env. If pydantic validation of those settings fails, the ValidationError is wrapped as AgentInitializationException(\"Failed to create Azure OpenAI settings\"). The wrapped error text enumerates which fields failed validation.","triggerScenarios":"Calling the agent/client factory with arguments or environment variables that fail AzureOpenAISettings validation — e.g. malformed endpoint URL, invalid api_version format, unreadable env_file_path, or a field whose value violates its type/constraint.","commonSituations":"Missing or malformed AZURE_OPENAI_* env vars; pointing env_file_path at a non-existent .env; supplying api_version as a non-string or unsupported value; endpoint not a valid URL; env_file_encoding mismatch.","solutions":["Read the wrapped ValidationError in exc.__cause__ to see exactly which settings field(s) failed.","Correct the offending env var or constructor argument (URL format, api_version string, file path).","Ensure the .env file exists at env_file_path and uses the specified env_file_encoding.","Validate settings explicitly with AzureOpenAISettings() in isolation to surface errors before constructing the agent."],"exampleFix":"// before\nAzureOpenAIAssistantAgent(..., env_file_path=\"missing.env\")\n# -> Failed to create Azure OpenAI settings\n\n// after\nAzureOpenAIAssistantAgent(..., env_file_path=\".env\")  # valid file with AZURE_OPENAI_* vars","handlingStrategy":"try-catch","validationCode":"from semantic_kernel.connectors.ai.open_ai import AzureOpenAISettings\n\ndef settings_build_ok(**kwargs) -> bool:\n    try:\n        AzureOpenAISettings(**kwargs)\n        return True\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import AgentInitializationException\n\ntry:\n    agent = AzureOpenAIAssistantAgent(...)\nexcept AgentInitializationException as e:\n    cause = e.__cause__  # pydantic ValidationError with field details\n    logger.error(\"settings invalid: %s\", cause)","preventionTips":["Validate AzureOpenAISettings() standalone before building the agent.","Keep AZURE_OPENAI_* env vars well-formed and the .env file present.","Read the wrapped ValidationError to fix the precise failing field."],"tags":["azure","config","initialization","settings","agentinit"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}