{"record":{"id":"0e420875e16b922f","repo":"microsoft/semantic-kernel","slug":"expected-openaisettings-got-type-settings-nam","errorCode":null,"errorMessage":"Expected OpenAISettings, got {type(settings).__name__}","messagePattern":"Expected OpenAISettings, got (.+?)","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/openai_assistant_agent.py","lineNumber":568,"sourceCode":"    def resolve_placeholders(\n        cls: type[_T],\n        yaml_str: str,\n        settings: \"KernelBaseSettings | None\" = None,\n        extras: dict[str, Any] | None = None,\n    ) -> str:\n        \"\"\"Substitute ${OpenAI:Key} placeholders with fields from OpenAIAgentSettings 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 = OpenAISettings()\n\n        if not isinstance(settings, OpenAISettings):\n            raise AgentInitializationException(f\"Expected OpenAISettings, got {type(settings).__name__}\")\n\n        field_mapping.update({\n            \"ChatModelId\": cls._get_setting(getattr(settings, \"chat_model_id\", None)),\n            \"AgentId\": cls._get_setting(getattr(settings, \"agent_id\", None)),\n            \"ApiKey\": cls._get_setting(getattr(settings, \"api_key\", 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(\":\")\n            if section != \"OpenAI\":\n                return match.group(0)\n\n            # Try short key first (ApiKey), then full (OpenAI:ApiKey)","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_assistant_agent.py#L550-L586","documentation":"Raised by OpenAIAssistantAgent.resolve_placeholders() when the settings argument, after defaulting, is not an instance of OpenAISettings. resolve_placeholders reads chat_model_id/agent_id/api_key attributes via getattr; a wrong settings type would silently yield None for those fields, so the guard rejects it up front. If settings is None the method constructs a default OpenAISettings() first.","triggerScenarios":"Passing a KernelBaseSettings subclass that is not OpenAISettings (e.g. AzureOpenAISettings, a custom settings object, or a plain dict) to resolve_placeholders; a factory handing the wrong settings instance.","commonSituations":"Reusing an Azure OpenAI settings object against the non-Azure assistant agent; custom settings class that mirrors but does not subclass OpenAISettings; refactoring connectors and passing mismatched settings.","solutions":["Pass an OpenAISettings instance (or None to let it default).","If you hold an AzureOpenAISettings, convert/map it into an OpenAISettings before calling.","Type-check settings before the call: assert isinstance(settings, OpenAISettings) or settings is None."],"exampleFix":"# before\nresolve_placeholders(yaml_str, settings=azure_settings)\n\n# after\nfrom semantic_kernel.connectors.ai.open_ai.settings.open_ai_settings import OpenAISettings\nresolve_placeholders(yaml_str, settings=OpenAISettings(api_key=azure_settings.api_key, chat_model_id=azure_settings.chat_model_id))","handlingStrategy":"type-guard","validationCode":"from semantic_kernel.connectors.ai.open_ai.settings.open_ai_settings import OpenAISettings\nassert settings is None or isinstance(settings, OpenAISettings), 'settings must be OpenAISettings or None'","typeGuard":"from semantic_kernel.connectors.ai.open_ai.settings.open_ai_settings import OpenAISettings\ndef is_openai_settings(s) -> bool:\n    return s is None or isinstance(s, OpenAISettings)","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException\ntry:\n    resolve_placeholders(yaml_str, settings=settings)\nexcept AgentInitializationException as e:\n    if 'Expected OpenAISettings' in str(e):\n        resolve_placeholders(yaml_str, settings=OpenAISettings())","preventionTips":["Pass None or an OpenAISettings instance only.","Map Azure settings into OpenAISettings before calling.","Type-check at the boundary."],"tags":["configuration","agents","openai-assistant","type-mismatch","settings"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}