{"record":{"id":"8d32a5144a08ac17","repo":"agentscope-ai/agentscope","slug":"failed-to-get-the-completed-response-from-model-m","errorCode":null,"errorMessage":"Failed to get the completed response from model {model_name}.","messagePattern":"Failed to get the completed response from model (.+?)\\.","errorType":"exception","errorClass":"StructuredOutputError","httpStatus":null,"severity":"error","filePath":"src/agentscope/model/_base.py","lineNumber":693,"sourceCode":"            # avoid duplicating the retry logic in ``__call__``), we must\n            # replicate that accumulation here, otherwise the stream may\n            # end without ever producing an ``is_last=True`` chunk.\n            acc_res = _StreamAccumulator()\n\n            async for chunk in res:\n                if chunk.is_last:\n                    completed_response = chunk\n                    break\n                acc_res.append_chat_response(chunk)\n                acc_res.id = chunk.id\n\n            if completed_response is None:\n                completed_response = acc_res.build()\n        else:\n            completed_response = res\n\n        if completed_response is None or not completed_response.content:\n            raise StructuredOutputError(\n                f\"Failed to get the completed response from model \"\n                f\"{model_name}.\",\n            )\n\n        structured_output: dict[str, Any] | None = None\n        try:\n            for _ in completed_response.content:\n                if isinstance(_, ToolCallBlock) and _.name == func_name:\n                    structured_output = _json_loads_with_repair(\n                        _.input,\n                        input_schema,\n                    )\n                    break\n\n            if structured_output is None:\n                raise StructuredOutputError(\n                    \"Failed to generate structured output for model.\",\n                )","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/model/_base.py#L675-L711","documentation":"After invoking the model with a structured-output strategy, the completed response was None or had empty content, so agentscope raises StructuredOutputError. The API call technically returned but yielded no usable text (e.g. empty choices/content, streaming accumulation failure, or content filtered).","triggerScenarios":"Model returns an empty completion (empty content string), stream finished without accumulating any content, or provider returns finish_reason content_filter with no text.","commonSituations":"Safety filter blocking the output; max_tokens set so low the model emits nothing; provider outage returning empty bodies; prompt asking model to return nothing.","solutions":["Retry the call — transient empty responses from providers are common","Increase max_tokens and simplify/strengthen the prompt so the model actually emits the JSON","Inspect the raw provider response (enable verbose logging) to see finish_reason/empty content cause","If content filtering is the cause, adjust the prompt or safety settings"],"exampleFix":"# before\nres = await model.generate_structured_output(msgs, Schema)  # empty content\n\n# after\nfor attempt in range(3):\n    try:\n        res = await model.generate_structured_output(msgs, Schema)\n        break\n    except StructuredOutputError:\n        if attempt == 2:\n            raise","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from agentscope.model import StructuredOutputError\nfor attempt in range(3):\n    try:\n        return await model.generate_structured_output(msgs, Schema)\n    except StructuredOutputError:\n        if attempt == 2:\n            raise\n        await asyncio.sleep(2 ** attempt)","preventionTips":["Set a generous max_tokens","Monitor finish_reason in raw provider logs for empty completions"],"tags":["agentscope","structured-output","empty-response","retry"],"backgroundTag":"empty-model-response","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}