{"record":{"id":"5c8797d134587a2a","repo":"FoundationAgents/MetaGPT","slug":"prompt-or-messages-is-required","errorCode":null,"errorMessage":"prompt or messages is required!","messagePattern":"prompt or messages is required!","errorType":"validation","errorClass":"InputRequired","httpStatus":null,"severity":"error","filePath":"metagpt/provider/dashscope_api.py","lineNumber":120,"sourceCode":"    request_data.add_parameters(**kwargs)\n    request.data = request_data\n    return request\n\n\nclass AGeneration(Generation, BaseAioApi):\n    @classmethod\n    async def acall(\n        cls,\n        model: str,\n        prompt: Any = None,\n        history: list = None,\n        api_key: str = None,\n        messages: List[Message] = None,\n        plugins: Union[str, Dict[str, Any]] = None,\n        **kwargs,\n    ) -> Union[GenerationResponse, AsyncGenerator[GenerationResponse, None]]:\n        if (prompt is None or not prompt) and (messages is None or not messages):\n            raise InputRequired(\"prompt or messages is required!\")\n        if model is None or not model:\n            raise ModelRequired(\"Model is required!\")\n        task_group, function = \"aigc\", \"generation\"  # fixed value\n        if plugins is not None:\n            headers = kwargs.pop(\"headers\", {})\n            if isinstance(plugins, str):\n                headers[\"X-DashScope-Plugin\"] = plugins\n            else:\n                headers[\"X-DashScope-Plugin\"] = json.dumps(plugins)\n            kwargs[\"headers\"] = headers\n        input, parameters = cls._build_input_parameters(model, prompt, history, messages, **kwargs)\n\n        api_key, model = BaseAioApi._validate_params(api_key, model)\n        request = build_api_arequest(\n            model=model,\n            input=input,\n            task_group=task_group,\n            task=Generation.task,","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/provider/dashscope_api.py#L102-L138","documentation":"DashScope generation entry (Generation.acall) requires either prompt or messages; if both are None/empty, InputRequired('prompt or messages is required!') is raised immediately, before any network call. It is a pure argument-validation guard.","triggerScenarios":"Calling Generation.acall(model='qwen-plus') with neither prompt nor messages, or with prompt='' and messages=[]; template code where the prompt variable ended up empty.","commonSituations":"Building prompts dynamically and shipping an empty string; passing messages only as history (history alone does not satisfy the check); config-driven prompt templates resolving to empty.","solutions":["Pass a non-empty prompt or a non-empty messages list.","Add your own precondition check/log before calling so empty prompts are caught with better context.","If messages-based, ensure the messages list itself (not history) carries the conversation."],"exampleFix":"// before\nresp = await Generation.acall(model=\"qwen-plus\", prompt=\"\", messages=[])\n\n// after\nresp = await Generation.acall(model=\"qwen-plus\", prompt=\"Summarize this document...\")","handlingStrategy":"validation","validationCode":"def has_prompt(prompt, messages) -> bool:\n    return bool(prompt) or bool(messages)\n\nassert has_prompt(prompt, messages), \"prompt or messages required\"","typeGuard":null,"tryCatchPattern":"try:\n    resp = await Generation.acall(model=model, prompt=prompt, messages=messages)\nexcept Exception as e:\n    if \"prompt or messages is required\" in str(e):\n        raise ValueError(\"refusing to call LLM with empty prompt\") from e\n    raise","preventionTips":["Reject empty prompts at the application layer with a descriptive error.","Log prompt length before dispatch to catch silent empty-string bugs."],"tags":["dashscope","validation","empty-prompt"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}