{"record":{"id":"ca2a846e2ee5aaad","repo":"microsoft/semantic-kernel","slug":"response-is-none","errorCode":null,"errorMessage":"Response is None","messagePattern":"Response is None","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py","lineNumber":636,"sourceCode":"                **response_options,\n            )\n        except BadRequestError as ex:\n            if ex.code == \"content_filter\":\n                raise ContentFilterAIException(\n                    f\"{type(agent)} encountered a content error\",\n                    ex,\n                ) from ex\n            raise AgentExecutionException(\n                f\"{type(agent)} failed to complete the request\",\n                ex,\n            ) from ex\n        except Exception as ex:\n            raise AgentExecutionException(\n                f\"{type(agent)} service failed to complete the request\",\n                ex,\n            ) from ex\n        if response is None:\n            raise AgentInvokeException(\"Response is None\")\n        return response\n\n    @classmethod\n    async def _poll_until_completed(\n        cls: type[_T],\n        agent: \"OpenAIResponsesAgent\",\n        response: Response,\n        polling_options: \"RunPollingOptions\",\n    ):\n        count = 0\n        while response.status != \"completed\":\n            await asyncio.sleep(polling_options.get_polling_interval(count).total_seconds())\n            response = await agent.client.responses.retrieve(response.id)\n            count += 1\n        return response\n\n    @classmethod\n    async def get_messages(","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py#L618-L654","documentation":"Raised as an AgentInvokeException(\"Response is None\") defensively at the end of _get_response, after the try/except around responses.create. It guards the (theoretically possible but rare) case where the SDK returns None instead of raising, so downstream code that assumes a Response object does not fail with an AttributeError.","triggerScenarios":"agent.client.responses.create completes without raising but returns None (or a falsy value). This should not happen with the current OpenAI SDK under normal operation; it would indicate a SDK bug, a custom/mock client returning None, or an unusual transport edge case.","commonSituations":"Using a mock/fake client in tests that forgets to return a Response; an openai SDK regression; a custom AsyncOpenAI-compatible client that returns None on certain errors instead of raising; SDK version skew.","solutions":["If testing with a mock client, ensure responses.create returns a valid Response object (or raises).","Upgrade the openai SDK to a stable release if using a custom client.","Inspect logs for the request that produced a None response to identify the trigger.","If using a proxy/gateway, confirm it returns a well-formed Responses payload."],"exampleFix":"# In tests, ensure the fake client returns a Response:\nmock_client.responses.create = AsyncMock(return_value=make_response(status=\"completed\"))","handlingStrategy":"validation","validationCode":"# In tests, ensure the fake client returns a Response object:\nassert mock_client.responses.create.return_value is not None","typeGuard":"from openai.types.responses import Response\ndef is_valid_response(obj) -> bool:\n    return isinstance(obj, Response) and getattr(obj, \"status\", None) is not None","tryCatchPattern":"from semantic_kernel.exceptions import AgentInvokeException\ntry:\n    async for _, m in agent.invoke(thread=thread):\n        ...\nexcept AgentInvokeException as ex:\n    if str(ex) == \"Response is None\":\n        # indicates SDK/mock regression - investigate the client\n        ...","preventionTips":["Ensure mock/fake clients in tests return a valid Response or raise.","Keep the openai SDK at a version compatible with semantic-kernel.","Log the raw response object during development to catch regressions."],"tags":["openai-responses","defensive","sdk","testing"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}