agentscope-ai/agentscope · error · RuntimeError

No structured-output strategy is available for {self.model}.

Error message

No structured-output strategy is available for {self.model}.

What it means

After iterating all structured-output strategies, agentscope found none that succeeded (or none applicable), with last_error unset, so it raises RuntimeError stating no strategy is available for the model. It usually means the model/provider lacks JSON-mode/tool-based structured output support or every strategy was skipped.

Source

Thrown at src/agentscope/model/_base.py:587

                            )
                            await asyncio.sleep(self.retry_delay)
                            continue
                        raise  # retries exhausted -> give up
                    if not isinstance(e, fallback):
                        raise
                    # Structured-output compatibility failure: try the next
                    # strategy.
                    logger.debug(
                        "Structured output strategy '%s' failed for %s: %s. "
                        "Trying next.",
                        name,
                        self.model,
                        e,
                    )
                    break

        if last_error is None:
            raise RuntimeError(
                f"No structured-output strategy is available for "
                f"{self.model}.",
            )
        if first_error is not None and first_error is not last_error:
            raise last_error from first_error
        raise last_error

    async def _call_api_with_structured_output(
        self,
        model_name: str,
        messages: list[Msg],
        structured_model: Type[BaseModel] | dict,
        tool_choice: ToolChoice | None = None,
        **kwargs: Any,
    ) -> StructuredResponse:
        """Run a single structured-output attempt via a forced tool call.

        Constructs a ``generate_structured_output`` tool, asks the LLM to

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Use a model/provider with JSON or tool-calling support (e.g. OpenAI, DashScope qwen-max, Gemini) for structured output
  2. If you implemented a custom model, override the structured-output support indicators (e.g. supports_json_schema / tool calling) so a strategy is selected
  3. Check earlier in logs: strategy failures usually print the underlying per-strategy error — fix that root cause
  4. Fall back to normal generate() + manual json.loads/Pydantic parsing if the model cannot do native structured output

Example fix

# before
res = await model.generate_structured_output(msgs, Schema)  # local model, no JSON mode

# after
res = await model.generate(msgs)
data = Schema.model_validate_json(res.content)
Defensive patterns

Strategy: fallback

Try / catch

try:
    res = await model.generate_structured_output(msgs, Schema)
except RuntimeError:
    # model lacks structured-output support: fall back to plain generation
    raw = await model.generate(msgs)
    res = Schema.model_validate_json(raw.content)

Prevention

When it happens

Trigger: Calling generate_structured_output with a model whose provider implements none of the supported strategies (no response_format/json schema support, no tool calling), or all strategies returning None without setting last_error.

Common situations: Using a small local/open-source model without native JSON mode; a custom ModelBase subclass that doesn't override the strategy hooks; upgrading agentscope where strategy detection changed; wrong model type string.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/b2a1ec824923693c. Report an issue: GitHub.