{"record":{"id":"dbd49959ffa09058","repo":"microsoft/semantic-kernel","slug":"expected-azureopenaisettings-got-type-settings","errorCode":null,"errorMessage":"Expected AzureOpenAISettings, got {type(settings).__name__}","messagePattern":"Expected AzureOpenAISettings, got (.+?)","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/azure_assistant_agent.py","lineNumber":252,"sourceCode":"    def resolve_placeholders(\n        cls: type[Self],\n        yaml_str: str,\n        settings: \"KernelBaseSettings | None\" = None,\n        extras: dict[str, Any] | None = None,\n    ) -> str:\n        \"\"\"Substitute ${AzureOpenAI:Key} placeholders with fields from AzureOpenAIAgentSettings and extras.\"\"\"\n        import re\n\n        pattern = re.compile(r\"\\$\\{([^}]+)\\}\")\n\n        # Build the mapping only if settings is provided and valid\n        field_mapping: dict[str, Any] = {}\n\n        if settings is None:\n            settings = AzureOpenAISettings()\n\n        if not isinstance(settings, AzureOpenAISettings):\n            raise AgentInitializationException(f\"Expected AzureOpenAISettings, got {type(settings).__name__}\")\n\n        field_mapping.update({\n            \"ChatModelId\": cls._get_setting(getattr(settings, \"chat_deployment_name\", None)),\n            \"AgentId\": cls._get_setting(getattr(settings, \"agent_id\", None)),\n            \"ApiKey\": cls._get_setting(getattr(settings, \"api_key\", None)),\n            \"ApiVersion\": cls._get_setting(getattr(settings, \"api_version\", None)),\n            \"BaseUrl\": cls._get_setting(getattr(settings, \"base_url\", None)),\n            \"Endpoint\": cls._get_setting(getattr(settings, \"endpoint\", None)),\n            \"TokenEndpoint\": cls._get_setting(getattr(settings, \"token_endpoint\", None)),\n        })\n\n        if extras:\n            field_mapping.update(extras)\n\n        def replacer(match: re.Match[str]) -> str:\n            \"\"\"Replace the matched placeholder with the corresponding value from field_mapping.\"\"\"\n            full_key = match.group(1)  # for example, OpenAI:ApiKey\n            section, _, key = full_key.partition(\":\")","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/azure_assistant_agent.py#L234-L270","documentation":"Raised by AzureAssistantAgent.resolve_placeholders() when a caller passes a non-None settings object that is not an instance of AzureOpenAISettings. resolve_placeholders reads fields like chat_deployment_name and api_key directly off the object, so a wrong type yields silent garbage or AttributeError later; the guard fails fast instead.","triggerScenarios":"Calling AzureAssistantAgent.resolve_placeholders(yaml_str, settings=<some other settings object>) where settings is e.g. an OpenAISettings, a plain dict, or a custom pydantic model. Passing None is fine (it defaults to AzureOpenAISettings()); only a non-None, wrong-type value triggers this.","commonSituations":"Reusing an OpenAISettings (non-Azure) instance by mistake; feeding a manually-built dataclass/dict as 'settings'; refactoring shared config holders and changing the concrete class without updating call sites.","solutions":["Pass an AzureOpenAISettings instance, or pass None to let the method build one from env.","If you have a shared config object, construct AzureOpenAISettings(...) from its fields before calling resolve_placeholders.","Double-check imports: ensure you imported AzureOpenAISettings from semantic_kernel.connectors.ai.open_ai.settings, not OpenAISettings."],"exampleFix":"# before\nAzureAssistantAgent.resolve_placeholders(yaml, settings=openai_settings)  # wrong type\n# after\nAzureAssistantAgent.resolve_placeholders(yaml, settings=AzureOpenAISettings())  # or None","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"from semantic_kernel.connectors.ai.open_ai.settings import AzureOpenAISettings\n\ndef is_azure_openai_settings(s) -> bool:\n    return isinstance(s, AzureOpenAISettings)\n\n# before calling resolve_placeholders\nif settings is not None and not is_azure_openai_settings(settings):\n    settings = AzureOpenAISettings()  # or raise explicitly","tryCatchPattern":null,"preventionTips":["Always pass either None or an explicit AzureOpenAISettings instance to resolve_placeholders.","Avoid sharing generic config objects; convert to AzureOpenAISettings at the boundary.","Add a static type annotation on the settings parameter so type checkers catch mismatches."],"tags":["azure-openai","declarative-spec","semantic-kernel","agents","type-validation","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}