OpenBB-finance/OpenBB · error · ValueError
Failed to cast {value} to bool.
Error message
Failed to cast {value} to bool. What it means
ValueError from Env.str2bool, which parses OpenBB's boolean environment variables (OPENBB_DEBUG_MODE, OPENBB_ALLOW_ON_COMMAND_OUTPUT, etc.). Accepted values are true/false, t/f, 1/0, yes/no, y/n (case-insensitive); anything else - 'on', 'enabled', '' (empty string from 'set VAR='), or arbitrary text - raises this error at settings load time.
Source
Thrown at openbb_platform/core/openbb_core/env.py:77
return self.str2bool(
self._environ.get("OPENBB_ALLOW_MUTABLE_EXTENSIONS", False)
)
@property
def ALLOW_ON_COMMAND_OUTPUT(self) -> bool:
"""Allow on command output: enables extensions that act on command output."""
return self.str2bool(self._environ.get("OPENBB_ALLOW_ON_COMMAND_OUTPUT", False))
@staticmethod
def str2bool(value) -> bool:
"""Match a value to its boolean correspondent."""
if isinstance(value, bool):
return value
if value.lower() in {"false", "f", "0", "no", "n"}:
return False
if value.lower() in {"true", "t", "1", "yes", "y"}:
return True
raise ValueError(f"Failed to cast {value} to bool.")
View on GitHub (pinned to 3e071fcc2c)
Solutions
- Use one of the accepted literals: export OPENBB_DEBUG_MODE=true (or false/1/0/yes/no)
- Unset the variable entirely instead of setting it empty: unset OPENBB_DEBUG_MODE
- Audit docker-compose.yml / CI env blocks for OpenBB variables with non-standard boolean values
Example fix
# before export OPENBB_DEBUG_MODE=on python -c 'import openbb' # ValueError: Failed to cast on to bool. # after export OPENBB_DEBUG_MODE=true python -c 'import openbb'
Defensive patterns
Strategy: validation
Validate before calling
TRUE = {'true', 't', '1', 'yes', 'y'}
FALSE = {'false', 'f', '0', 'no', 'n'}
def env_bool_ok(val) -> bool:
return not isinstance(val, str) or val.lower() in TRUE | FALSE Type guard
def is_openbb_bool(v) -> bool:
return not isinstance(v, str) or v.lower() in {'true','t','1','yes','y','false','f','0','no','n'} Try / catch
# Raised at import time - catch around import in launchers
try:
import openbb as obb
except ValueError as e:
if 'Failed to cast' in str(e):
import os
bad = [k for k in os.environ if k.startswith('OPENBB_') and os.environ[k].lower() not in {'true','t','1','yes','y','false','f','0','no','n'}]
raise SystemExit(f'Fix OPENBB_* boolean env vars: {bad}') from e
raise Prevention
- Use only true/false (or 1/0, yes/no) for OPENBB_* booleans
- Never set OpenBB env vars to empty strings - unset them instead
- Lint docker-compose/CI env maps for OpenBB variables before deploy
When it happens
Trigger: export OPENBB_DEBUG_MODE=on (not accepted), OPENBB_DEBUG_MODE='' after 'set -u' style clearing, or CI injecting OPENBB_DEBUG_MODE enabled. The error surfaces as soon as OpenBB reads its environment (import openbb / first command), because Env properties call str2bool on _environ.get(...).
Common situations: Using 'on/off' or 'enabled' boolean conventions from other tools; Docker ENV or docker-compose boolean-ish values; shell scripts exporting empty strings; YAML/Ansible env maps passing values like 'True ' with whitespace or '2'.
Related errors
- Provider fallback failed. [Providers] {msg}
- Missing credential '{c}'.{extra_msg} Refer to the documentat
- Target provider '{target}' has no configured root directorie
- Unsupported file format. Please use .json or .env files.
- Failed to get Jupyter URL
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/1627f8adfc1e6a1d.
Report an issue: GitHub.