datawhalechina/hello-agents · error · WorkflowExecutionError

需求不能为空

Error message

需求不能为空

What it means

Raised by _validate_requirement after stripping the input: a requirement that is all whitespace (or empty) is rejected. The strip-then-check means ' ' fails exactly like ''. This guards the LLM pipeline from being invoked with a prompt that contains no actual requirement text.

Source

Thrown at Co-creation-projects/zenith191-RequirementClarifierAgent/src/workflow.py:121

            quality=quality,
        )

    @staticmethod
    def save_report(result: WorkflowResult, output_path: str | Path) -> Path:
        """以 UTF-8 保存最终 Markdown 报告。"""

        path = Path(output_path)
        path.parent.mkdir(parents=True, exist_ok=True)
        path.write_text(result.report.rstrip() + "\n", encoding="utf-8")
        return path

    @staticmethod
    def _validate_requirement(requirement: str) -> str:
        if not isinstance(requirement, str):
            raise WorkflowExecutionError("需求必须是字符串")
        requirement = requirement.strip()
        if not requirement:
            raise WorkflowExecutionError("需求不能为空")
        if len(requirement) > MAX_REQUIREMENT_LENGTH:
            raise WorkflowExecutionError(
                f"需求文本不能超过 {MAX_REQUIREMENT_LENGTH} 个字符"
            )
        return requirement

    @staticmethod
    def _run_agent(stage: str, agent: AgentLike, prompt: str) -> str:
        try:
            response = agent.run(prompt)
        except Exception as exc:
            raise WorkflowExecutionError(f"{stage}阶段执行失败:{exc}") from exc
        if not isinstance(response, str) or not response.strip():
            raise WorkflowExecutionError(f"{stage}阶段返回了空结果")
        return response.strip()

    def _run_tool(
        self, name: str, parameters: dict[str, object], stage: str

View on GitHub (pinned to 606a07d341)

Solutions

  1. Check and reject empty input in the UI/API layer before invoking the workflow.
  2. Trim user input client-side and server-side; require a minimum length.
  3. For batch jobs, skip blank lines/records instead of passing them to run().

Example fix

# before
result = workflow.run(user_input)

# after
if not (user_input := user_input.strip()):
    raise ValueError("requirement is empty")
result = workflow.run(user_input)
Defensive patterns

Strategy: validation

Validate before calling

requirement = (requirement or "").strip()
if not requirement:
    raise ValueError("requirement must be non-empty")
result = workflow.run(requirement)

Type guard

def is_nonempty_requirement(v: object) -> bool:
    return isinstance(v, str) and len(v.strip()) > 0

Try / catch

try:
    result = workflow.run(requirement)
except WorkflowExecutionError as e:
    if "不能为空" in str(e):
        return "Please provide a requirement"  # e.g. an API 400 response
    raise

Prevention

When it happens

Trigger: Calling run('') or run(' \n\t') — e.g. an empty textarea submitted, a blank line read from a file loop, or a variable that defaulted to ''.

Common situations: Web form submitted without required-field validation; batch-processing a file where some entries are blank; whitespace from copy-paste or template rendering ('{{ requirement }}' with missing variable).

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/439ae66a400111c3. Report an issue: GitHub.