agentscope-ai/agentscope · error · StructuredOutputError
Failed to get the completed response from model {model_name}
Error message
Failed to get the completed response from model {model_name}. What it means
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).
Source
Thrown at src/agentscope/model/_base.py:693
# avoid duplicating the retry logic in ``__call__``), we must
# replicate that accumulation here, otherwise the stream may
# end without ever producing an ``is_last=True`` chunk.
acc_res = _StreamAccumulator()
async for chunk in res:
if chunk.is_last:
completed_response = chunk
break
acc_res.append_chat_response(chunk)
acc_res.id = chunk.id
if completed_response is None:
completed_response = acc_res.build()
else:
completed_response = res
if completed_response is None or not completed_response.content:
raise StructuredOutputError(
f"Failed to get the completed response from model "
f"{model_name}.",
)
structured_output: dict[str, Any] | None = None
try:
for _ in completed_response.content:
if isinstance(_, ToolCallBlock) and _.name == func_name:
structured_output = _json_loads_with_repair(
_.input,
input_schema,
)
break
if structured_output is None:
raise StructuredOutputError(
"Failed to generate structured output for model.",
)View on GitHub (pinned to e90f1c7592)
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
Example fix
# before
res = await model.generate_structured_output(msgs, Schema) # empty content
# after
for attempt in range(3):
try:
res = await model.generate_structured_output(msgs, Schema)
break
except StructuredOutputError:
if attempt == 2:
raise Defensive patterns
Strategy: retry
Try / catch
from agentscope.model import StructuredOutputError
for attempt in range(3):
try:
return await model.generate_structured_output(msgs, Schema)
except StructuredOutputError:
if attempt == 2:
raise
await asyncio.sleep(2 ** attempt) Prevention
- Set a generous max_tokens
- Monitor finish_reason in raw provider logs for empty completions
When it happens
Trigger: Model returns an empty completion (empty content string), stream finished without accumulating any content, or provider returns finish_reason content_filter with no text.
Common situations: 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.
Related errors
- Model call failed after retries, but no exception was raised
- "AgentScope streaming model yielded no chunks."
- "AgentScope embedding model returned no embeddings."
- The input messages cannot be empty for the `generate_structu
- No structured-output strategy is available for {self.model}.
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/8d32a5144a08ac17.
Report an issue: GitHub.