jax-ml/jax · error · ValueError
invalid argument side={side!r}, expected 'left' or 'right'
Error message
invalid argument side={side!r}, expected 'left' or 'right' What it means
Raised by the SearchSorted HiJAX primitive when the side argument is not exactly the string 'left' or 'right'. side controls whether ties return the first (left) or last (right) insertion index, mirroring numpy.searchsorted. Any other value, including capitalized or misspelled variants, is rejected at primitive construction.
Source
Thrown at jax/_src/numpy/hijax.py:84
out_dtype: np.dtype):
batch_dims = operator.index(batch_dims)
if batch_dims < 0 or batch_dims >= sorted_arr_aval.ndim:
raise ValueError(
f"batch_dims={batch_dims} must be in range [0, {sorted_arr_aval.ndim})"
)
dimension = operator.index(dimension)
if not batch_dims <= dimension < sorted_arr_aval.ndim:
raise ValueError(
f"dimension={dimension} must be in range [{batch_dims},"
f" {sorted_arr_aval.ndim})"
)
if sorted_arr_aval.dtype != query_aval.dtype:
raise ValueError(
"dtypes of sorted_arr and query must match; got "
f"{sorted_arr_aval.dtype} and {query_aval.dtype}"
)
if side not in ["left", "right"]:
raise ValueError(
f"invalid argument side={side!r}, expected 'left' or 'right'"
)
if method not in self.valid_methods:
raise ValueError(
f"invalid argument {method=}, expected one of {list(self.valid_methods)}"
)
if sorted_arr_aval.shape[:batch_dims] != query_aval.shape[:batch_dims]:
raise ValueError(
"batch dimension sizes must match; got"
f" {sorted_arr_aval.shape[:batch_dims]} != {query_aval.shape[:batch_dims]}"
)
if not dtypes.issubdtype(out_dtype, np.integer):
raise ValueError(f"out_dtype should be an integer type; got {out_dtype}")
# Attempt this here to catch overflow errors early.
out_dtype.type(sorted_arr_aval.shape[dimension])
self.in_avals = (sorted_arr_aval, query_aval)
self.out_aval = core.typeof(api.eval_shape(
functools.partial(_searchsorted_impl,View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use exactly side='left' or side='right'
- If side comes from user input, normalize it: side.strip().lower()
- Never pass an int/bool for side in this API
Example fix
# before idx = jnp.searchsorted(a, v, side='Left') # after idx = jnp.searchsorted(a, v, side='left')
Defensive patterns
Strategy: validation
Validate before calling
assert side in ('left', 'right'), side Type guard
def valid_side(s: str) -> bool:
return isinstance(s, str) and s in ('left', 'right') Prevention
- Treat side as a closed enum; validate config values before passing
- Normalize user-supplied side with .strip().lower()
When it happens
Trigger: Passing side='Left', side='RIGHT', side=0/1, or a typo like side='rigth' to jax.numpy searchsorted.
Common situations: Porting code from an API that used booleans or integers for side; building side dynamically from user config with non-normalized casing.
Related errors
- invalid argument {method=}, expected one of {list(self.valid
- out_dtype should be an integer type; got {out_dtype}
- Unsupported method: {method}
- `compute_on`'s compute_type argument must be a string.
- Argument '{x}' of type '{typ}' is not a valid JAX type
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/96445bfc0230bf8b.
Report an issue: GitHub.