langchain-ai/deepagents · error · ValueError
{question_type} question {question_text!r} must not define '
Error message
{question_type} question {question_text!r} must not define 'choices' What it means
The counterpart of error 17: `_validate_question` raises ValueError when a NON-choice question type (e.g. free text) defines a `choices` list. Only choice-type questions may carry choices; extra ones on free-text questions are rejected.
Source
Thrown at libs/code/deepagents_code/_ask_user_types.py:265
Returns:
The same `question`, unchanged.
Raises:
ValueError: If the question violates one of the rules above.
"""
question_type = question["type"]
question_text = question["question"]
choices = question.get("choices")
if question_type in CHOICE_QUESTION_TYPES:
if not choices:
msg = (
f"{question_type} question {question_text!r} requires a "
f"non-empty 'choices' list"
)
raise ValueError(msg)
elif choices:
msg = f"{question_type} question {question_text!r} must not define 'choices'"
raise ValueError(msg)
return question
class Question(TypedDict):
"""A question to ask the user."""
question: Annotated[
str,
AfterValidator(_validate_question_text),
Field(description="The question text to display.", min_length=1),
]
type: Annotated[
QuestionType,
Field(
description=(
"Question type. 'text' for free-form input, 'multiple_choice' for "
"picking exactly one predefined option, 'multi_select' for picking "View on GitHub (pinned to a1af029e6e)
Solutions
- Remove the `choices` key from free-text questions
- Verify `question_type` is spelled correctly so choice questions are recognized as choice types
- If the agent generates the question dict, constrain the schema/examples so choices only appear for choice types
- Move the option list into a `multiple_choice` or `multi_select` question instead of decorating a text question
Example fix
// before
{"question_type": "text", "text": "Describe the bug?", "choices": [{"value": "a"}]}
// after
{"question_type": "text", "text": "Describe the bug?"} Defensive patterns
Strategy: validation
Validate before calling
if q["question_type"] not in CHOICE_QUESTION_TYPES and q.get("choices"):
raise ValueError(f"{q['question_type']} question must not define 'choices'") Type guard
def choices_match_type(q: dict) -> bool:
is_choice = q.get("question_type") in CHOICE_QUESTION_TYPES
return is_choice == bool(q.get("choices")) Try / catch
try:
ask_user(questions=questions)
except ValueError as exc:
if "must not define 'choices'" in str(exc):
questions = [{k: v for k, v in q.items() if k != "choices"} for q in questions]
ask_user(questions=questions)
else:
raise Prevention
- Attach `choices` only to multiple_choice/multi_select questions
- Check question_type spelling so choice questions classify correctly
- Use a single question-construction helper that keys extra fields off the type
- Review LLM tool-call args for stray choices fields on text questions
When it happens
Trigger: An ask_user question whose `question_type` is not in CHOICE_QUESTION_TYPES but whose dict includes a non-empty `choices` key — raised at libs/code/deepagents_code/_ask_user_types.py:265.
Common situations: An LLM adding a `choices` field to every question regardless of type; reusing one question-building helper that always attaches choices; a `question_type` typo that makes a choice question classify as free 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
- question text must not be blank
- choice has a blank 'value': {choice!r}
- {question_type} question {question_text!r} requires a non-em
- ask_user requires at least one question
- Could not parse embedded resource block. Block expected eith
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/faba10e164b6fd38.
Report an issue: GitHub.