{"record":{"id":"204d728bcb224e0c","repo":"jax-ml/jax","slug":"default-value-must-be-of-type-bool-got-default","errorCode":null,"errorMessage":"Default value must be of type bool, got {default} of type {getattr(type(default), '__name__', type(default))}","messagePattern":"Default value must be of type bool, got (.+?) of type (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":408,"sourceCode":"        name='jax_enable_foo',\n        default=False,\n        help='Enable foo.')\n\n    # Now the JAX_ENABLE_FOO shell environment variable and --jax_enable_foo\n    # command-line flag can be used to control the process-level value of\n    # the configuration option, in addition to using e.g.\n    # ``config.update(\"jax_enable_foo\", True)`` directly. We can also use a\n    # context manager:\n\n    with enable_foo(True):\n      ...\n\n  The value of the thread-local state or flag can be accessed via\n  ``config.jax_enable_foo``. Reading it via ``config.FLAGS.jax_enable_foo`` is\n  an error.\n  \"\"\"\n  if not isinstance(default, bool):\n    raise TypeError(f\"Default value must be of type bool, got {default} \"\n                    f\"of type {getattr(type(default), '__name__', type(default))}\")\n  default = bool_env(name.upper(), default)\n  name = name.lower()\n  if upgrade:\n    help += ' ' + UPGRADE_BOOL_HELP\n    extra_description += UPGRADE_BOOL_EXTRA_DESC\n  config._contextmanager_flags.add(name)\n\n  def parser(val):\n    if validator:\n      validator(val)\n    return bool(val)\n\n  s = State[bool](\n      name, default, help, update_global_hook=update_global_hook,\n      update_thread_local_hook=update_thread_local_hook,\n      extra_description=extra_description, default_context_manager_value=True,\n      parser=parser, include_in_jit_key=include_in_jit_key,","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L390-L426","documentation":"bool_state, the helper that defines boolean JAX config options, validates that its default is a Python bool before reading the environment variable override. Because the option's semantic domain is strictly boolean, passing an int, string, or None default is rejected at definition time with a message showing the offending value and its type.","triggerScenarios":"Calling jax.config.define_bool_state / bool_state('jax_my_flag', 1, ...), default='true', or default=None. Also happens when a default is computed from env/config code that may return non-bool.","commonSituations":"Writing custom flags in plugins or forks; porting code where the default came from an env read (os.getenv returns a string); using 0/1 as 'boolean' defaults out of habit.","solutions":["Pass a literal bool: default=False or default=True","If the default is computed, coerce: bool(int(os.getenv('MY_FLAG', '0')))","For string-parsed env defaults, let bool_env handle it by just supplying the bool default"],"exampleFix":"# before\njax.config.define_bool_state('jax_my_flag', int(os.getenv('MY_FLAG', '0')), 'help')\n# after\njax.config.define_bool_state('jax_my_flag', os.getenv('MY_FLAG', '0') == '1', 'help')","handlingStrategy":"type-guard","validationCode":"default = os.getenv('MY_FLAG', '0') == '1'  # ensure bool\nassert isinstance(default, bool), f'default must be bool, got {type(default).__name__}'\njax.config.define_bool_state('jax_my_flag', default, 'help')","typeGuard":"def is_bool(v: object) -> TypeGuard[bool]:\n    return isinstance(v, bool)","tryCatchPattern":null,"preventionTips":["Never use 0/1 or 'true'/'false' strings as bool_state defaults","Coerce env-derived defaults to bool before passing","Add a unit test that defines your custom flags to catch bad defaults at test time"],"tags":["jax","config","typeerror","bool-default"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}