{"record":{"id":"115d7eb7c289132f","repo":"agentscope-ai/agentscope","slug":"the-input-messages-cannot-be-empty-for-the-genera","errorCode":null,"errorMessage":"The input messages cannot be empty for the `generate_structured_output` method.","messagePattern":"The input messages cannot be empty for the `generate_structured_output` method\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/model/_base.py","lineNumber":493,"sourceCode":"        - ``no_think``: thinking disabled + forced ``tool_choice`` (skipped\n          when the provider exposes no thinking toggle)\n        - ``none``: current config + no ``tool_choice``\n\n        An explicit ``tool_choice`` in ``kwargs`` bypasses the strategy\n        ladder and is forwarded unchanged.\n\n        Args:\n            messages (`list[Msg]`):\n                The context for LLM to generate the structured output.\n            structured_model (`Type[BaseModel] | dict`):\n                A Pydantic model or a dict of JSON schemas.\n\n        Returns:\n            `StructuredResponse`:\n                The structured response generated by the model.\n        \"\"\"\n        if len(messages) == 0:\n            raise ValueError(\n                \"The input messages cannot be empty for the \"\n                \"`generate_structured_output` method.\",\n            )\n\n        user_tool_choice = kwargs.pop(\"tool_choice\", None)\n        if user_tool_choice is None:\n            forced_tc = ToolChoice(mode=\"generate_structured_output\")\n            disable_kwargs = self._get_disable_thinking_kwargs()\n            # (name, extra `_call_api` kwargs, tool_choice), best first.\n            # The no-think strategy only applies when the provider can\n            # toggle it.\n            strategies = (\n                (\"forced\", {}, forced_tc),\n                (\"auto\", {}, ToolChoice(mode=\"auto\")),\n                *(\n                    ((\"no_think\", disable_kwargs, forced_tc),)\n                    if disable_kwargs\n                    else ()","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/model/_base.py#L475-L511","documentation":"generate_structured_output requires a non-empty messages list; calling it with [] raises this ValueError immediately. The messages provide the prompt context the model needs to produce structured output, so an empty list is rejected upfront.","triggerScenarios":"Calling model.generate_structured_output([], MySchema) or passing a messages list that was built from an empty conversation / filtered to nothing.","commonSituations":"Programmatically building a message list from user input that turns out empty; slicing history incorrectly (e.g. messages[10:]) so the list is empty; refactoring a call path that previously checked length.","solutions":["Pass at least one message, typically the instruction prompt: generate_structured_output([Msg('user', 'extract fields: ...')], Schema)","Guard the call site: if not messages: skip or supply a default prompt","Log the message list length before calling to find where it becomes empty"],"exampleFix":"# before\nres = await model.generate_structured_output([], Schema)\n\n# after\nres = await model.generate_structured_output(\n    [Msg('user', 'Extract the fields from the given text.')], Schema)\n","handlingStrategy":"validation","validationCode":"if not messages:\n    raise ValueError('nothing to structure')  # or supply a default prompt\nres = await model.generate_structured_output(messages, Schema)","typeGuard":"def has_messages(msgs: list) -> bool:\n    return isinstance(msgs, list) and len(msgs) > 0","tryCatchPattern":null,"preventionTips":["Guard all LLM call sites with a non-empty messages check","Log message count before model calls in debug builds"],"tags":["agentscope","structured-output","empty-input","validation"],"backgroundTag":"empty-request-payload","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}