{"record":{"id":"a53fe1cc750f1fb4","repo":"microsoft/autogen","slug":"specified-model-client-doesn-t-support-structured","errorCode":null,"errorMessage":"Specified model_client doesn't support structured output mode.","messagePattern":"Specified model_client doesn't support structured output mode\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py","lineNumber":495,"sourceCode":"        if model_client is not None:\n            self._model_client = model_client\n\n        if model_context is not None:\n            self._model_context = model_context\n        else:\n            self._model_context = UnboundedChatCompletionContext()\n\n        self._system_messaages: List[SystemMessage] = []\n        if system_message is None:\n            self._system_messages = []\n        else:\n            self._system_messages = [SystemMessage(content=system_message)]\n\n        if self._max_retries_on_error > 0:\n            if not self._model_client or not self._model_client.model_info:\n                raise ValueError(\"model_client.model_info must be provided when max_retries_on_error > 0\")\n            if not self._model_client.model_info[\"structured_output\"]:\n                raise ValueError(\"Specified model_client doesn't support structured output mode.\")\n\n    @property\n    def produced_message_types(self) -> Sequence[type[BaseChatMessage]]:\n        \"\"\"The types of messages that the code executor agent produces.\"\"\"\n        return (TextMessage,)\n\n    @property\n    def model_context(self) -> ChatCompletionContext:\n        \"\"\"\n        The model context in use by the agent.\n        \"\"\"\n        return self._model_context\n\n    async def on_messages(self, messages: Sequence[BaseChatMessage], cancellation_token: CancellationToken) -> Response:\n        async for message in self.on_messages_stream(messages, cancellation_token):\n            if isinstance(message, Response):\n                return message\n        raise AssertionError(\"The stream should have returned the final result.\")","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py#L477-L513","documentation":"CodeExecutorAgent requires that when retries are enabled the model must support structured (JSON) output, checked via model_client.model_info[\"structured_output\"]. Retries depend on re-requesting the output in a structured format, so an unsupported model cannot be used with max_retries_on_error > 0.","triggerScenarios":"CodeExecutorAgent(max_retries_on_error=N) with a model whose model_info has structured_output=False (e.g., many open-weight/local models served via clients that declare no JSON-mode support).","commonSituations":"Using local models (llama.cpp, vLLM without guided JSON) or custom clients with hand-written model_info that sets structured_output=False; enabling retries by copy-paste.","solutions":["Set max_retries_on_error=0 (default) when the model lacks structured output support.","Switch to a model/client that declares structured_output=True in model_info.","If you control the model_info dict and the backend actually supports JSON mode (e.g. vLLM guided decoding), correct the flag."],"exampleFix":"// before\nagent = CodeExecutorAgent(\n    name=\"coder\",\n    code_executor=executor,\n    model_client=local_client,  # structured_output: False\n    max_retries_on_error=3,\n)\n\n// after\nagent = CodeExecutorAgent(\n    name=\"coder\",\n    code_executor=executor,\n    model_client=local_client,\n    max_retries_on_error=0,\n)","handlingStrategy":"validation","validationCode":"info = getattr(model_client, \"model_info\", None) or {}\nif max_retries_on_error > 0 and not info.get(\"structured_output\", False):\n    max_retries_on_error = 0  # model can't support structured retry\n\nagent = CodeExecutorAgent(name=\"coder\", code_executor=exec_,\n                          model_client=model_client,\n                          max_retries_on_error=max_retries_on_error)","typeGuard":"def supports_structured_output(client) -> bool:\n    info = getattr(client, \"model_info\", None) or {}\n    return bool(info.get(\"structured_output\", False))","tryCatchPattern":null,"preventionTips":["Check model_info['structured_output'] before enabling retries.","Keep a curated map of which deployed models support JSON mode.","Correct stale model_info flags on custom clients when the backend gains guided-JSON support."],"tags":["validation","constructor","structured-output","model-capabilities"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}