{"record":{"id":"afe4821c83dc4725","repo":"jax-ml/jax","slug":"invalid-truth-value-val-r-for-environment-varna","errorCode":null,"errorMessage":"invalid truth value {val!r} for environment {varname!r}","messagePattern":"invalid truth value (.+?) for environment (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":60,"sourceCode":"def bool_env(varname: str, default: bool) -> bool:\n  \"\"\"Read an environment variable and interpret it as a boolean.\n\n  True values are (case insensitive): 'y', 'yes', 't', 'true', 'on', and '1';\n  false values are 'n', 'no', 'f', 'false', 'off', and '0'.\n\n  Args:\n    varname: the name of the variable\n    default: the default boolean value\n  Raises: ValueError if the environment variable is anything else.\n  \"\"\"\n  val = os.getenv(varname, str(default))\n  val = val.lower()\n  if val in ('y', 'yes', 't', 'true', 'on', '1'):\n    return True\n  elif val in ('n', 'no', 'f', 'false', 'off', '0'):\n    return False\n  else:\n    raise ValueError(f\"invalid truth value {val!r} for environment {varname!r}\")\n\ndef int_env(varname: str, default: int) -> int:\n  \"\"\"Read an environment variable and interpret it as an integer.\"\"\"\n  return int(os.getenv(varname, str(default)))\n\n\nclass ValueHolder[ValueType](Protocol):\n  \"\"\"A holder for a configuration value.\n\n  There are two kinds of value holders: ``Flag``, which is assigned exactly\n  once and never modified after; and ``State``, which can be changed locally\n  within a thread via a context manager.\n  \"\"\"\n\n  value: ValueType\n\n  def _set(self, value: ValueType) -> None: ...\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L42-L78","documentation":"JAX boolean config flags (e.g. JAX_ENABLE_X64, JAX_DEBUG_NANS) accept only a fixed set of truthy/falsy string spellings: y/yes/t/true/on/1 and n/no/f/false/off/0 (case-insensitive). bool_env parses the environment variable at import/config-definition time and raises ValueError for anything else, since there is no unambiguous interpretation.","triggerScenarios":"Setting an env var like JAX_ENABLE_X64=YES PLEASE, JAX_DEBUG_NANS=enable, JAX_64BIT=2, or with a trailing space/quote, then importing jax or defining a new bool config option.","commonSituations":"Typos in CI environment matrices ('ture', 'flase'), values copied from docs with quotes (JAX_ENABLE_X64=\"true\" in a Dockerfile where quotes are literal), or scripts writing 0/1 plus whitespace.","solutions":["Correct the value to one of: y/yes/t/true/on/1 or n/no/f/false/off/0 (case-insensitive)","Strip quotes and whitespace when exporting in Dockerfiles/shell: ENV JAX_ENABLE_X64=true (no quotes)","Audit with: env | grep JAX_ to find malformed values before importing jax"],"exampleFix":"# before\nENV JAX_ENABLE_X64=\"true\"   # Dockerfile: literal quotes become part of the value\n# after\nENV JAX_ENABLE_X64=true","handlingStrategy":"validation","validationCode":"import os, re\n\nTRUTHY = {'y','yes','t','true','on','1'}\nFALSY = {'n','no','f','false','off','0'}\n\ndef check_jax_bool_envs():\n    for k, v in os.environ.items():\n        if k.startswith('JAX_') and re.fullmatch(r'.*(TRUE|FALSE|ENABLE|DEBUG|DISABLE|ON|OFF).*', k):\n            s = v.strip().lower()\n            if s not in TRUTHY | FALSY:\n                raise ValueError(f'{k}={v!r} is not a valid JAX bool')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only true/false spellings in Dockerfiles and CI, without quotes","Add a startup sanity check for JAX_* env values","Watch for trailing whitespace when setting env vars in scripts"],"tags":["jax","environment-variable","config","bool-parsing"],"backgroundTag":"invalid-env-var-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}