jax-ml/jax · error · ValueError
new enum value must be in {enum_values}, got {new_val} of ty
Error message
new enum value must be in {enum_values}, got {new_val} of type {type(new_val)}. What it means
The parser created by enum_state rejects any new value set on the flag that is not a str (exact type check, subclasses excluded) or is not in enum_values. It fires when calling the context manager or config update with a bad value.
Source
Thrown at jax/_src/config.py:514
JIT cache key.
extra_validator: optional function to validate the value of the config
option.
Returns:
A contextmanager to control the thread-local state value.
"""
if not isinstance(default, str):
raise TypeError(f"Default value must be of type str, got {default} "
f"of type {getattr(type(default), '__name__', type(default))}")
name = name.lower()
default = os.getenv(name.upper(), default)
if default not in enum_values:
raise ValueError(f"Invalid value \"{default}\" for JAX flag {name}")
config._contextmanager_flags.add(name)
def parser(new_val):
if type(new_val) is not str or new_val not in enum_values:
raise ValueError(f"new enum value must be in {enum_values}, "
f"got {new_val} of type {type(new_val)}.")
if extra_validator is not None:
extra_validator(new_val)
return new_val
s = State[str](
name,
default,
help,
update_global_hook=update_global_hook,
update_thread_local_hook=update_thread_local_hook,
parser=parser,
include_in_jit_key=include_in_jit_key,
include_in_trace_context=include_in_trace_context,
)
config.add_option(
name, s, 'enum',
meta_args=[],View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Pass the string member: with my_flag(MyEnum.FOO.value):
- Double-check the string is one of the enum_values listed in the flag's help
Example fix
// before
with jax.my_flag(MyEnum.FOO):
...
// after
with jax.my_flag('foo'):
... Defensive patterns
Strategy: validation
Validate before calling
if not (type(new_val) is str and new_val in enum_values):
raise ValueError(f'expected one of {enum_values}, got {new_val!r}') Type guard
def is_enum_value(v, values) -> bool:
return type(v) is str and v in values Try / catch
try:
with my_flag(val):
...
except ValueError as e:
if 'new enum value' in str(e):
val = DEFAULT; my_flag(val).__enter__() Prevention
- Pass MyEnum.FOO.value rather than Enum members
- Whitelist dynamic values against enum_values before entering the context manager
When it happens
Trigger: with my_flag(MyEnum.FOO): ... (Enum member instead of its string value), or jax.config.update('my_flag', 'invalid').
Common situations: Programmatically toggling an enum-backed flag (profiler trace level, compilation cache mode) with an Enum object or a typo'd string.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Invalid value "{default}" for JAX flag {name}
- new enum value must be None or in {enum_values}, got {new_va
- Invalid value "{default_str}" for JAX flag {name}
- Default value must be of type str, got {default} of type {ge
- Default value must be of type str or None, got {default} of
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/cc9341b183b56a34.
Report an issue: GitHub.