{"record":{"id":"3b63af943de47885","repo":"jax-ml/jax","slug":"invalid-value-received-for-the-layout-argument-ex","errorCode":null,"errorMessage":"Invalid value received for the layout argument. Expected values are `None`, `Layout.AUTO` or an instance of `Layout`. Got {layout} of type {type(layout)}","messagePattern":"Invalid value received for the layout argument\\. Expected values are `None`, `Layout\\.AUTO` or an instance of `Layout`\\. Got (.+?) of type (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/layout.py","lineNumber":147,"sourceCode":"\n\nclass Format:\n  __slots__ = ['layout', 'sharding']\n\n  def __init__(self, layout: LayoutOptions = None,\n               sharding: ShardingOptions = None):\n    # If layout is concrete and sharding is not, error.\n    if isinstance(layout, Layout) and sharding is None:\n      raise ValueError(\n          'Sharding has to be concrete when layout is of type'\n          f' {type(layout)}. Please pass a'\n          ' `jax.sharding.NamedSharding` or'\n          ' `jax.sharding.SingleDeviceSharding` to the sharding argument. Got'\n          f' sharding {sharding}'\n      )\n    if not isinstance(\n        layout, (Layout, type(None), AutoLayoutSingleton)):\n      raise TypeError(\n          'Invalid value received for the layout argument.'\n          ' Expected values are `None`, `Layout.AUTO` or an'\n          f' instance of `Layout`. Got {layout} of'\n          f' type {type(layout)}'\n      )\n    if not isinstance(sharding, (Sharding, type(None))):\n      raise TypeError(\n          'Invalid value received for the sharding argument. Expected values'\n          ' are `None` or an instance of `jax.Sharding`. Got'\n          f' {sharding} of type {type(sharding)}')\n\n    self.layout = layout\n    self.sharding = sharding\n\n  def __repr__(self):\n    return f'Format(layout={self.layout}, sharding={self.sharding})'\n\n  def __hash__(self):","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/layout.py#L129-L165","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nlayout = 'auto'\njax.jit(f, layout=layout)\n\n# after\nfrom jax.sharding import Layout\nlayout = Layout.AUTO  # or None, or Layout(...)","handlingStrategy":"type-guard","validationCode":"from jax.sharding import Layout\nok = layout is None or layout is Layout.AUTO or isinstance(layout, Layout)","typeGuard":"def is_valid_layout(x) -> bool:\n    from jax.sharding import Layout\n    return x is None or x is Layout.AUTO or isinstance(x, Layout)","tryCatchPattern":"try:\n    op(layout=layout)\nexcept TypeError as e:\n    if 'layout argument' in str(e):\n        layout = None; op(layout=layout)\n    else: raise","preventionTips":["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"],"tags":["jax","layout","type-validation","isinstance-check"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}