microsoft/semantic-kernel · error · AgentExecutionException
{type(agent)} failed to complete the request
Error message
{type(agent)} failed to complete the request What it means
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.
Source
Thrown at python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py:626
try:
response: Response = await agent.client.responses.create(
input=cls._prepare_chat_history_for_request(
chat_history, store_output_enabled if store_output_enabled is not None else agent.store_enabled
),
instructions=merged_instructions or agent.instructions,
previous_response_id=previous_response_id,
store=store_output_enabled,
tools=tools, # type: ignore
stream=stream,
**response_options,
)
except BadRequestError as ex:
if ex.code == "content_filter":
raise ContentFilterAIException(
f"{type(agent)} encountered a content error",
ex,
) from ex
raise AgentExecutionException(
f"{type(agent)} failed to complete the request",
ex,
) from ex
except Exception as ex:
raise AgentExecutionException(
f"{type(agent)} service failed to complete the request",
ex,
) from ex
if response is None:
raise AgentInvokeException("Response is None")
return response
@classmethod
async def _poll_until_completed(
cls: type[_T],
agent: "OpenAIResponsesAgent",
response: Response,
polling_options: "RunPollingOptions",View on GitHub (pinned to c028a0c7dc)
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).
Example fix
# before
tools = [{"type": "function", "name": "bad"}] # missing required schema fields
# after - provide a complete, valid function tool definition
tools = [{
"type": "function",
"name": "get_weather",
"description": "Get the weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}] Defensive patterns
Strategy: validation
Validate before calling
# Validate tool/function schemas before invoking:
import jsonschema
def validate_tool(tool):
spec = tool if isinstance(tool, dict) else tool.model_dump()
for key in ("name", "parameters"):
assert key in spec, f"tool missing required field: {key}"
jsonschema.Draft7Validator.check_schema(spec["parameters"])
for t in tools:
validate_tool(t) Try / catch
from semantic_kernel.exceptions import AgentExecutionException
try:
async for is_final, msg in agent.invoke(thread=thread):
...
except AgentExecutionException as ex:
if "failed to complete the request" in str(ex):
cause = ex.__cause__ # the BadRequestError
log.error("Bad request: %s", cause)
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Tool spec must include a 'type' field.
- ImageContent must have either a data_uri or uri set to be us
- Invalid choice
- Invalid kernel selection. {selectedKernelName} is not a vali
- Unsupported image format.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/5b84be5670bad8d3.
Report an issue: GitHub.