{"record":{"id":"5b84be5670bad8d3","repo":"microsoft/semantic-kernel","slug":"type-agent-failed-to-complete-the-request","errorCode":null,"errorMessage":"{type(agent)} failed to complete the request","messagePattern":"(.+?) failed to complete the request","errorType":"exception","errorClass":"AgentExecutionException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py","lineNumber":626,"sourceCode":"        try:\n            response: Response = await agent.client.responses.create(\n                input=cls._prepare_chat_history_for_request(\n                    chat_history, store_output_enabled if store_output_enabled is not None else agent.store_enabled\n                ),\n                instructions=merged_instructions or agent.instructions,\n                previous_response_id=previous_response_id,\n                store=store_output_enabled,\n                tools=tools,  # type: ignore\n                stream=stream,\n                **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\",","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py#L608-L644","documentation":"Raised as an AgentExecutionException when agent.client.responses.create throws an openai.BadRequestError that is NOT a content_filter (any other 400 error). BadRequestError from the OpenAI SDK means the request was malformed or invalid (bad parameters, unsupported model feature, invalid tools schema, etc.). The original error is chained as the cause.","triggerScenarios":"A BadRequestError (non-content_filter) escapes responses.create in _get_response. Caused by invalid request parameters: unsupported tool type, malformed tool/function JSON schema, incompatible response_options for the model, previous_response_id pointing to a non-existent/foreign response, store enabled with an unsupported configuration, or model id typos.","commonSituations":"Passing response_options keys the model does not support; malformed function/tool definitions; referencing a previous_response_id that expired or belongs to another org; using image input on a model without vision; mismatched API/SDK versions where new fields are required; typos in model deployment name on Azure.","solutions":["Inspect the chained BadRequestError (__cause__) for the exact API error message and parameter name.","Validate that all tool/function schemas are well-formed JSON schemas with required fields (name, description, parameters).","Ensure response_options keys are supported by the target model and SDK version.","If chaining responses via store/previous_response_id, confirm the referenced response_id still exists and belongs to the same deployment.","Verify the model id / Azure deployment name is correct and supports the features used (vision, tools, structured output)."],"exampleFix":"# before\ntools = [{\"type\": \"function\", \"name\": \"bad\"}]  # missing required schema fields\n# after - provide a complete, valid function tool definition\ntools = [{\n    \"type\": \"function\",\n    \"name\": \"get_weather\",\n    \"description\": \"Get the weather for a city\",\n    \"parameters\": {\n        \"type\": \"object\",\n        \"properties\": {\"city\": {\"type\": \"string\"}},\n        \"required\": [\"city\"],\n    },\n}]","handlingStrategy":"validation","validationCode":"# Validate tool/function schemas before invoking:\nimport jsonschema\ndef validate_tool(tool):\n    spec = tool if isinstance(tool, dict) else tool.model_dump()\n    for key in (\"name\", \"parameters\"):\n        assert key in spec, f\"tool missing required field: {key}\"\n    jsonschema.Draft7Validator.check_schema(spec[\"parameters\"])\nfor t in tools:\n    validate_tool(t)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import AgentExecutionException\ntry:\n    async for is_final, msg in agent.invoke(thread=thread):\n        ...\nexcept AgentExecutionException as ex:\n    if \"failed to complete the request\" in str(ex):\n        cause = ex.__cause__  # the BadRequestError\n        log.error(\"Bad request: %s\", cause)\n    raise","preventionTips":["Validate function/tool JSON schemas before passing them to the agent.","Keep response_options keys within the model's documented capabilities.","When chaining responses via store/previous_response_id, confirm the id is still valid."],"tags":["openai-responses","bad-request","validation","api-contract"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}