{"record":{"id":"5a5daa4b887699fa","repo":"microsoft/semantic-kernel","slug":"type-self-service-failed-to-complete-the-prompt-5a5daa","errorCode":null,"errorMessage":"{type(self)} service failed to complete the prompt","messagePattern":"(.+?) service failed to complete the prompt","errorType":"exception","errorClass":"ServiceResponseException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/open_ai_handler.py","lineNumber":100,"sourceCode":"            settings_dict = settings.prepare_settings_dict()\n            if self.ai_model_type == OpenAIModelTypes.CHAT:\n                assert isinstance(settings, OpenAIChatPromptExecutionSettings)  # nosec\n                self._handle_structured_output(settings, settings_dict)\n                if settings.tools is None:\n                    settings_dict.pop(\"parallel_tool_calls\", None)\n                response = await self.client.chat.completions.create(**settings_dict)\n            else:\n                response = await self.client.completions.create(**settings_dict)\n\n            self.store_usage(response)\n            return response\n        except BadRequestError as ex:\n            if ex.code == \"content_filter\":\n                raise ContentFilterAIException(\n                    f\"{type(self)} service encountered a content error\",\n                    ex,\n                ) from ex\n            raise ServiceResponseException(\n                f\"{type(self)} service failed to complete the prompt\",\n                ex,\n            ) from ex\n        except Exception as ex:\n            raise ServiceResponseException(\n                f\"{type(self)} service failed to complete the prompt\",\n                ex,\n            ) from ex\n\n    async def _send_embedding_request(self, settings: OpenAIEmbeddingPromptExecutionSettings) -> list[Any]:\n        \"\"\"Send a request to the OpenAI embeddings endpoint.\"\"\"\n        try:\n            response = await self.client.embeddings.create(**settings.prepare_settings_dict())\n\n            self.store_usage(response)\n            return [x.embedding for x in response.data]\n        except Exception as ex:\n            raise ServiceResponseException(","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_handler.py#L82-L118","documentation":"Raised as ServiceResponseException in _send_completion_request when the OpenAI SDK raises a BadRequestError whose code is NOT 'content_filter' — i.e., a 400 error for any other reason (malformed request, unsupported parameters, invalid model name, token-limit violations). It wraps the original BadRequestError as the cause.","triggerScenarios":"Sending a completion/chat request with parameters the OpenAI API rejects: specifying a model name that doesn't exist, max_tokens exceeding the model's limit, incompatible tool/function schemas, unsupported response_format, or deprecated parameters for the requested model.","commonSituations":"Switching to a new model (e.g., o1) that doesn't support certain parameters like temperature; passing tool definitions with invalid JSON schemas; setting max_tokens beyond the model's context window; using parameters valid for one model family on another.","solutions":["Inspect the wrapped BadRequestError (ex.__cause__) for the exact API error message and code","Verify the model name is valid and the parameters you set are supported by that specific model","Remove or adjust unsupported parameters (e.g., drop temperature for o1-family models)","Validate tool/function JSON schemas against the OpenAI function-calling spec before sending"],"exampleFix":"# before — o1 model does not support temperature\nsettings = OpenAIChatPromptExecutionSettings(ai_model_id='o1-preview', temperature=0.7)\n# after\nsettings = OpenAIChatPromptExecutionSettings(ai_model_id='o1-preview')  # no temperature","handlingStrategy":"try-catch","validationCode":"SUPPORTED_PARAMS = {'gpt-4o': {'temperature', 'max_tokens', 'tools', 'tool_choice', 'response_format'}}\nmodel = settings.ai_model_id\nif model in SUPPORTED_PARAMS:\n    for key in settings.prepare_settings_dict():\n        if key not in SUPPORTED_PARAMS[model] and key not in {'model', 'messages', 'stream'}:\n            logger.warning(f'Parameter {key} may not be supported by {model}')","typeGuard":null,"tryCatchPattern":"from openai import BadRequestError\nfrom semantic_kernel.exceptions import ServiceResponseException\n\ntry:\n    response = await service.get_chat_message_content(...)\nexcept ServiceResponseException as e:\n    if isinstance(e.__cause__, BadRequestError):\n        logger.error('OpenAI rejected request: %s (code=%s)', e.__cause__.message, e.__cause__.code)\n        # adjust parameters based on the error and retry","preventionTips":["Check the OpenAI API docs for model-specific parameter support before constructing settings","Log the __cause__ exception details to diagnose the exact rejection reason"],"tags":["openai","bad-request","chat-completion","api-parameters"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}