langchain-ai/deepagents · error · ValueError

question text must not be blank

Error message

question text must not be blank

What it means

`_validate_question_text` in libs/code/deepagents_code/_ask_user_types.py raises ValueError when an ask_user question's `text` is empty or whitespace-only. Question text must contain at least one non-whitespace character for the prompt UI to render meaningfully.

Source

Thrown at libs/code/deepagents_code/_ask_user_types.py:184

    annotation it runs before `min_length=1`, which therefore never rejects
    anything — that constraint is kept only because it is what puts
    `minLength: 1` in the JSON schema the model reads. Swapping the two moves
    the empty-string rejection onto `min_length` and changes the error the
    model sees from this function's message to `string_too_short`. A string
    like `"   "` would render as a visually blank prompt.

    Args:
        text: The parsed `question` text to check.

    Returns:
        The same `text`, unchanged.

    Raises:
        ValueError: If `text` has no non-whitespace character.
    """
    if not text.strip():
        msg = "question text must not be blank"
        raise ValueError(msg)
    return text


def _validate_choice(choice: Choice) -> Choice:
    """Reject a choice whose `value` is blank.

    A blank value would render as an unlabelled option the user can select but
    whose answer reads as "no answer".

    Attached to the item annotation inside `Question.choices`, not to `Choice`
    itself, so `TypeAdapter(Choice)` does not apply it.

    Callers must pass a parsed `Choice`. A missing `value` never reaches here —
    it is a required key, so pydantic rejects it as `choices.N.value: Field
    required` before the choice-level validators run. On a raw dict this would
    raise `KeyError`, which is not a `ValidationError` and would halt the run.

    Args:

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Set a non-empty, descriptive `text` string on the question before calling ask_user
  2. If text is generated dynamically, add a fallback default when the value strips to empty
  3. Check the model's tool-call arguments for truncated or dropped `text` values and strengthen the tool description/example
  4. Wrap construction in validation that re-prompts the model when text is blank

Example fix

# before
{"question_type": "multiple_choice", "text": "  ", "choices": [...]}
# after
{"question_type": "multiple_choice", "text": "Which database should we migrate to?", "choices": [...]}
Defensive patterns

Strategy: validation

Validate before calling

if not question.get("text", "").strip():
    raise ValueError("question text must not be blank")

Type guard

def has_question_text(q: dict) -> bool:
    return isinstance(q.get("text"), str) and bool(q["text"].strip())

Try / catch

try:
    ask_user(questions=questions)
except ValueError as exc:
    if "question text must not be blank" in str(exc):
        questions = [q for q in questions if q.get("text", "").strip()]
        if questions:
            ask_user(questions=questions)
    else:
        raise

Prevention

When it happens

Trigger: An agent calling the `ask_user` tool with a question whose `text` field is `""` or `" "`, or building an `AskUserRequest` programmatically with blank text — validation runs at libs/code/deepagents_code/_ask_user_types.py:184.

Common situations: An LLM generating a question with an empty text field from a malformed tool call; template code interpolating a variable that is empty; tests or scripts constructing Question dicts manually with omitted/blank text.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/6ddf5bf1f0cfa69d. Report an issue: GitHub.