{"record":{"id":"ce18a051b498a08a","repo":"langchain-ai/deepagents","slug":"ask-user-requires-at-least-one-question","errorCode":null,"errorMessage":"ask_user requires at least one question","messagePattern":"ask_user requires at least one question","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/_ask_user_types.py","lineNumber":368,"sourceCode":"\n    Per-question rules live on `ValidatedQuestion`; this covers the one rule\n    about the list itself. Attached both to the tool's `questions` parameter\n    and to `AskUserRequest.questions`, so the client re-validation boundary\n    rejects an empty list too — `AskUserMenu([])` would otherwise build a\n    titled prompt with no question widgets and nothing focusable.\n\n    Args:\n        questions: The parsed `questions` argument to check.\n\n    Returns:\n        The same `questions`, unchanged.\n\n    Raises:\n        ValueError: If the list is empty.\n    \"\"\"\n    if not questions:\n        msg = \"ask_user requires at least one question\"\n        raise ValueError(msg)\n    return questions\n\n\nclass AskUserRequest(TypedDict):\n    \"\"\"Request payload sent via interrupt when asking the user questions.\"\"\"\n\n    type: Literal[\"ask_user\"]\n    \"\"\"Discriminator tag, always `'ask_user'`.\"\"\"\n\n    questions: Annotated[list[ValidatedQuestion], AfterValidator(_validate_questions)]\n    \"\"\"Questions to present to the user.\n\n    `ValidatedQuestion` rather than `Question`, and carrying\n    `_validate_questions`, so every rule the tool applies also applies where\n    `tui.textual_adapter` re-validates this payload. A choice question with no\n    `choices` would otherwise reach the client and degrade to a text box, and\n    an empty list would render a prompt with no questions in it.\n    \"\"\"","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/_ask_user_types.py#L350-L386","documentation":"`_validate_questions` raises ValueError when the ask_user call receives an empty question list. The ask_user tool exists to collect answers, so at least one question must be submitted.","triggerScenarios":"An agent invoking `ask_user` with `questions: []`, or code building an `AskUserRequest` from a dynamically filtered list that ended up empty — raised at libs/code/deepagents_code/_ask_user_types.py:368.","commonSituations":"An LLM emitting an empty questions array in the tool call; logic that filters questions by some condition and passes the (possibly empty) remainder; template code with a loop that appends nothing before submitting.","solutions":["Always pass at least one validated question to ask_user","If questions are built dynamically, skip the ask_user call entirely when the list is empty instead of sending it","Check the model's tool-call arguments for an omitted/empty `questions` array and reinforce the tool description","Guard the call site with a length check before invoking the tool"],"exampleFix":"# before\nask_user(questions=[])\n# after\nquestions = build_questions(context)\nif questions:\n    ask_user(questions=questions)\nelse:\n    proceed_without_input()","handlingStrategy":"validation","validationCode":"if not questions:\n    raise ValueError(\"ask_user requires at least one question\")","typeGuard":"def has_questions(questions: list) -> bool:\n    return len(questions) > 0","tryCatchPattern":"try:\n    ask_user(questions=questions)\nexcept ValueError as exc:\n    if \"requires at least one question\" in str(exc):\n        # skip asking and proceed with defaults\n        ...\n    else:\n        raise","preventionTips":["Guard ask_user call sites with a non-empty check on the questions list","Skip the ask_user tool call entirely when dynamic question building yields nothing","Enforce minItems=1 on the questions array in the tool schema where possible","Add a unit test covering the empty-questions path of your question builder"],"tags":["validation","ask-user","dcode","valueerror"],"backgroundTag":"schema-validation-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}