{"record":{"id":"827d565e7159fdf9","repo":"microsoft/semantic-kernel","slug":"expected-openaisettings-got-type-settings-nam-827d56","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_responses_agent.py","lineNumber":605,"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, \"responses_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":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_responses_agent.py#L587-L623","documentation":"Raised by the placeholder-substitution helper when the settings argument is provided but is not an instance of OpenAISettings. The method substitutes ${OpenAI:Key}-style placeholders from settings fields; a foreign object type cannot be safely read for those fields. (If settings is None it defaults to OpenAISettings(), so this only fires for non-None wrong types.)","triggerScenarios":"Passing a settings object of the wrong class to the substitution routine — e.g. an AzureOpenAISettings, a plain dict, or an OpenAIChatCompletion settings instance — when the Responses Agent expects OpenAISettings specifically.","commonSituations":"Sharing a settings singleton across agent types, or passing the chat-completions settings into a Responses Agent by mistake. Also when a refactor renamed the settings class and a caller still hands in the old type.","solutions":["Pass an OpenAISettings instance (or omit settings to let it default to OpenAISettings()).","If you have another settings object, construct OpenAISettings from its values first.","Add an isinstance(settings, OpenAISettings) check before calling the substitution method."],"exampleFix":"// before\nresult = OpenAIResponsesAgent._substitute_placeholders(yaml, settings=azure_settings)\n\n// after\nresult = OpenAIResponsesAgent._substitute_placeholders(yaml, settings=OpenAISettings())","handlingStrategy":"type-guard","validationCode":"from semantic_kernel.connectors.ai.open_ai.settings.open_ai_settings import OpenAISettings\nif settings is not None and not isinstance(settings, OpenAISettings):\n    settings = OpenAISettings()","typeGuard":"from semantic_kernel.connectors.ai.open_ai.settings.open_ai_settings import OpenAISettings\ndef is_openai_settings(obj) -> bool:\n    return isinstance(obj, OpenAISettings)","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException\ntry:\n    result = OpenAIResponsesAgent._substitute_placeholders(yaml, settings=settings)\nexcept AgentInitializationException as e:\n    if 'OpenAISettings' in str(e):\n        result = OpenAIResponsesAgent._substitute_placeholders(yaml)  # defaults\n    raise","preventionTips":["Pass OpenAISettings (or None) to the substitution helper.","Do not reuse another agent type's settings object.","Add an isinstance check before calling if the source is dynamic."],"tags":["declarative-spec","settings","type-check"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}