langchain-ai/deepagents · error · ValueError
Invalid approval mode: {mode!r}
Error message
Invalid approval mode: {mode!r} What it means
When `mode` is given to `approval_mode_payload`, it is converted with `ApprovalMode(mode)`. Any value that is not a valid ApprovalMode (or is of an unusable type) raises TypeError/ValueError, which is re-raised as this ValueError naming the offending value.
Source
Thrown at libs/code/deepagents_code/approval_mode.py:157
API. `True` maps to unrestricted `yolo`, and `False` maps to `manual`.
Returns:
JSON-serializable store value.
Raises:
ValueError: If neither or both inputs are supplied, or `mode` is invalid.
"""
if (mode is None) == (auto_approve is None):
msg = "Provide exactly one of mode or auto_approve"
raise ValueError(msg)
if auto_approve is not None:
resolved = ApprovalMode.YOLO if auto_approve else ApprovalMode.MANUAL
else:
try:
resolved = ApprovalMode(mode)
except (TypeError, ValueError) as exc:
msg = f"Invalid approval mode: {mode!r}"
raise ValueError(msg) from exc
return {"mode": resolved.value}
def _item_value(item: object) -> object:
"""Extract a store item's value.
Args:
item: SDK or runtime store-item shape.
Returns:
The stored value, or `None` when the shape is unrecognized.
"""
if isinstance(item, Mapping):
return item.get("value")
return getattr(item, "value", None)
def _approval_mode_from_item(item: object) -> ApprovalMode | None:View on GitHub (pinned to a1af029e6e)
Solutions
- Use an ApprovalMode member value exactly, e.g. "yolo" or "manual"
- Validate first: `mode in {m.value for m in ApprovalMode}` before calling
- Parse config through ApprovalMode(mode) at load time with a clear fallback
- Accept case-insensitively by normalizing: mode = mode.strip().lower()
Example fix
// before approval_mode_payload(mode="YOLO") // after approval_mode_payload(mode=ApprovalMode.YOLO.value)
Defensive patterns
Strategy: validation
Validate before calling
allowed = {m.value for m in ApprovalMode}
if mode not in allowed:
raise ValueError(f"mode must be one of {sorted(allowed)}, got {mode!r}") Type guard
def is_approval_mode(value: object) -> bool:
try:
ApprovalMode(value)
return True
except (TypeError, ValueError):
return False Try / catch
try:
payload = approval_mode_payload(mode=config_mode)
except ValueError as exc:
logger.error("bad approval mode in config: %s", exc)
payload = approval_mode_payload(mode=ApprovalMode.MANUAL.value) Prevention
- Store and pass enum members, not raw strings, wherever possible
- Normalize user input with .strip().lower() before enum conversion
- Validate config values at load time with a clear error listing valid modes
When it happens
Trigger: Calling `approval_mode_payload(mode="Yolo")` (wrong case), `mode="auto"` (nonexistent), or `mode=1` where no enum member matches — typically from unvalidated config or UI input.
Common situations: Config files with hand-written mode strings; switching versions where allowed values changed; comparing against lowercase strings instead of the enum.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Provide exactly one of mode or auto_approve
- External event bypass must be a valid bypass tier: {exc}
- Invalid recent startup mode: {mode!r}
- Invalid sort_order {sort_order!r}; expected 'updated_at' or
- Invalid scope {scope!r}; expected 'cwd' or 'all'
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/2ccc3c458593c278.
Report an issue: GitHub.