{"record":{"id":"2ccc3c458593c278","repo":"langchain-ai/deepagents","slug":"invalid-approval-mode-mode-r","errorCode":null,"errorMessage":"Invalid approval mode: {mode!r}","messagePattern":"Invalid approval mode: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/approval_mode.py","lineNumber":157,"sourceCode":"            API. `True` maps to unrestricted `yolo`, and `False` maps to `manual`.\n\n    Returns:\n        JSON-serializable store value.\n\n    Raises:\n        ValueError: If neither or both inputs are supplied, or `mode` is invalid.\n    \"\"\"\n    if (mode is None) == (auto_approve is None):\n        msg = \"Provide exactly one of mode or auto_approve\"\n        raise ValueError(msg)\n    if auto_approve is not None:\n        resolved = ApprovalMode.YOLO if auto_approve else ApprovalMode.MANUAL\n    else:\n        try:\n            resolved = ApprovalMode(mode)\n        except (TypeError, ValueError) as exc:\n            msg = f\"Invalid approval mode: {mode!r}\"\n            raise ValueError(msg) from exc\n    return {\"mode\": resolved.value}\n\n\ndef _item_value(item: object) -> object:\n    \"\"\"Extract a store item's value.\n\n    Args:\n        item: SDK or runtime store-item shape.\n\n    Returns:\n        The stored value, or `None` when the shape is unrecognized.\n    \"\"\"\n    if isinstance(item, Mapping):\n        return item.get(\"value\")\n    return getattr(item, \"value\", None)\n\n\ndef _approval_mode_from_item(item: object) -> ApprovalMode | None:","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/approval_mode.py#L139-L175","documentation":"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.","triggerScenarios":"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.","commonSituations":"Config files with hand-written mode strings; switching versions where allowed values changed; comparing against lowercase strings instead of the enum.","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()"],"exampleFix":"// before\napproval_mode_payload(mode=\"YOLO\")\n// after\napproval_mode_payload(mode=ApprovalMode.YOLO.value)","handlingStrategy":"validation","validationCode":"allowed = {m.value for m in ApprovalMode}\nif mode not in allowed:\n    raise ValueError(f\"mode must be one of {sorted(allowed)}, got {mode!r}\")","typeGuard":"def is_approval_mode(value: object) -> bool:\n    try:\n        ApprovalMode(value)\n        return True\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    payload = approval_mode_payload(mode=config_mode)\nexcept ValueError as exc:\n    logger.error(\"bad approval mode in config: %s\", exc)\n    payload = approval_mode_payload(mode=ApprovalMode.MANUAL.value)","preventionTips":["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"],"tags":["approval-mode","enum","invalid-value"],"backgroundTag":"invalid-enum-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}