jax-ml/jax · error · TypeError
Invalid value received for the layout argument. Expected…
Error message
Invalid value received for the layout argument. Expected values are `None`, `Layout.AUTO` or an instance of `Layout`. Got {layout} of type {type(layout)} What it means
Raised by the constructor of jax._src.layout (Layout device-assignment/validation object) when the `layout` argument is not None, not Layout.AUTO, and not a Layout instance. JAX validates layout eagerly so that invalid layout specs fail at API entry rather than during compilation. The message reports the offending value and its type.
Solutions
- Pass jax.sharding.Layout.AUTO (or None) or a real jax.sharding.Layout instance
- Check you are not passing a PartitionSpec/Sharding into the layout slot (swap arguments)
- Upgrade/downgrade JAX to a version whose Layout API matches your code
- If subclassing Layout, ensure you inherit from jax.sharding.Layout, not a duck-typed imitation
Example fix
# before layout = 'auto' jax.jit(f, layout=layout) # after from jax.sharding import Layout layout = Layout.AUTO # or None, or Layout(...)
Defensive patterns
Strategy: type-guard
Validate before calling
from jax.sharding import Layout ok = layout is None or layout is Layout.AUTO or isinstance(layout, Layout)
Type guard
def is_valid_layout(x) -> bool:
from jax.sharding import Layout
return x is None or x is Layout.AUTO or isinstance(x, Layout) Try / catch
try:
op(layout=layout)
except TypeError as e:
if 'layout argument' in str(e):
layout = None; op(layout=layout)
else: raise Prevention
- Always construct layouts via jax.sharding.Layout APIs
- Never pass strings for layout; use Layout.AUTO
- Validate config-derived layout values before handing them to JAX
When it happens
Trigger: Calling an API that takes a layout kwarg (e.g. jax.jit sharding/layout or making a Layout object) with a string like 'auto', a PartitionSpec, a Sharding, or any custom object instead of Layout.AUTO / None / a Layout instance.
Common situations: Porting code that passed layout-like strings; confusing sharding and layout arguments; building a custom Layout subclass hierarchy where the isinstance check no longer matches; older JAX versions where the argument did not exist or accepted anything.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Expected mode of type `LayoutMode`. Got type
- layouts passed to `with_layout_constraint` must be of type…
- All args passed to `explicit_layout` must have the same…
- All objects to concatenate must be arrays, got
- Argument ' ' of type is not a valid JAX type.
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/3b63af943de47885.
Report an issue: GitHub.
Appendix: source
Thrown at jax/_src/layout.py:147
class Format:
__slots__ = ['layout', 'sharding']
def __init__(self, layout: LayoutOptions = None,
sharding: ShardingOptions = None):
# If layout is concrete and sharding is not, error.
if isinstance(layout, Layout) and sharding is None:
raise ValueError(
'Sharding has to be concrete when layout is of type'
f' {type(layout)}. Please pass a'
' `jax.sharding.NamedSharding` or'
' `jax.sharding.SingleDeviceSharding` to the sharding argument. Got'
f' sharding {sharding}'
)
if not isinstance(
layout, (Layout, type(None), AutoLayoutSingleton)):
raise TypeError(
'Invalid value received for the layout argument.'
' Expected values are `None`, `Layout.AUTO` or an'
f' instance of `Layout`. Got {layout} of'
f' type {type(layout)}'
)
if not isinstance(sharding, (Sharding, type(None))):
raise TypeError(
'Invalid value received for the sharding argument. Expected values'
' are `None` or an instance of `jax.Sharding`. Got'
f' {sharding} of type {type(sharding)}')
self.layout = layout
self.sharding = sharding
def __repr__(self):
return f'Format(layout={self.layout}, sharding={self.sharding})'
def __hash__(self):View on GitHub (pinned to 1e1c6a8fc0)