{"record":{"id":"7dcd1e38174039b2","repo":"jax-ml/jax","slug":"dtype-must-be-specified","errorCode":null,"errorMessage":"dtype must be specified.","messagePattern":"dtype must be specified\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/dtypes.py","lineNumber":1112,"sourceCode":"    dtype or (dtype, weak_type) depending on the value of the ``return_weak_type`` argument.\n  \"\"\"\n  if len(args) == 0:\n    raise ValueError(\"at least one array or dtype is required\")\n  dtype: DType | ExtendedDType\n  dtype, weak_type = lattice_result_type(*(default_float_dtype() if arg is None else arg for arg in args))\n  if weak_type:\n    dtype = default_types['f' if dtype in _custom_float_dtypes else dtype.kind]()\n  return (dtype, weak_type) if return_weak_type_flag else dtype\n\ndef check_and_canonicalize_user_dtype(\n    dtype, fun_name=None, *, allow_non_jax_dtypes: bool = False\n) -> DType:\n  \"\"\"Checks validity of a user-provided dtype, and returns its canonical form.\n\n  For Python scalar types this function returns the corresponding default dtype.\n  \"\"\"\n  if dtype is None:\n    raise ValueError(\"dtype must be specified.\")\n  if isinstance(dtype, Array):\n    raise ValueError(\"Passing an array as a dtype argument is no longer \"\n                     \"supported; instead of dtype=arr use dtype=arr.dtype.\")\n  if issubdtype(dtype, extended):\n    return dtype\n  # Avoid using `dtype in [...]` because of numpy dtype equality overloading.\n  if isinstance(dtype, type) and (f := _DEFAULT_TYPEMAP.get(dtype)) is not None:\n    return f()\n  np_dtype = np.dtype(dtype)\n  if np_dtype not in _jax_dtype_set:\n    if allow_non_jax_dtypes:\n      return np_dtype\n    msg = (\n        f'JAX only supports number, bool, and string dtypes, got dtype {dtype}'\n    )\n    msg += f\" in {fun_name}\" if fun_name else \"\"\n    raise TypeError(msg)\n  return _maybe_canonicalize_explicit_dtype(np_dtype, fun_name or \"\")","sourceCodeStart":1094,"sourceCodeEnd":1130,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dtypes.py#L1094-L1130","documentation":"check_and_canonicalize_user_dtype validates user-provided dtype= arguments for many lax/jnp operations; passing None (dtype not specified) where a concrete dtype is required raises this ValueError.","triggerScenarios":"Calling ops like lax.conv_general_dilated(..., dtype=None), searchsorted, or scaled-matmul wrappers with dtype left unset/None because it was optional in an older API or your config defaulted to None.","commonSituations":"Upgrading JAX after a dtype argument became required; config-driven pipelines where the dtype field is optional and defaults to None; wrapper APIs forwarding None.","solutions":["Pass an explicit dtype: dtype=jnp.float32 (or match your data)","Set a default in your config layer: dtype = cfg.dtype or jnp.float32","Check the function signature/docstring — if dtype is required, make it a required parameter in your wrapper"],"exampleFix":"# before\nlax.conv_general_dilated(..., dtype=None)\n\n# after\nlax.conv_general_dilated(..., dtype=jnp.float32)","handlingStrategy":"validation","validationCode":"dtype = dtype if dtype is not None else jnp.float32","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default optional dtype configs to a concrete dtype","Make dtype a required parameter in wrappers around ops that need it"],"tags":["jax","dtype","argument-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}