{"record":{"id":"63ad56328440dd05","repo":"jax-ml/jax","slug":"the-input-arguments-to-the-custom-jvp-decorated-fu-63ad56","errorCode":null,"errorMessage":"The input arguments to the custom_jvp-decorated function {self.f.__name__} could not be resolved to positional-only arguments. Binding failed with the error:\n{e}","messagePattern":"The input arguments to the custom_jvp-decorated function (.+?) could not be resolved to positional-only arguments\\. Binding failed with the error:\n(.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/hijax.py","lineNumber":1203,"sourceCode":"      primal_out = self(*primals)\n      zeros = tree_map(ad_util.p2tz, primal_out)\n      all_tangents_out = [j(t, primal_out, *primals) if j else zeros\n                          for t, j in zip(tangents, jvps)]\n      sum_tangents = lambda _, x, *xs: reduce(ad.add_tangents, xs, x)\n      tangent_out = tree_map(sum_tangents, primal_out, *all_tangents_out)\n      return primal_out, tangent_out\n    self.defjvp(jvp)\n\n  def __call__(self, *args, **kwargs):\n    if not self.jvp_fun:\n      msg = (f\"No JVP defined for custom_jvp function {self.f.__name__} \"\n             \"using defjvp.\")\n      raise AttributeError(msg)\n\n    try:\n      args = resolve_kwargs(self.f, args, kwargs)\n    except TypeError as e:\n      raise TypeError(\n          \"The input arguments to the custom_jvp-decorated function \"\n          f\"{self.f.__name__} could not be resolved to positional-only \"\n          f\"arguments. Binding failed with the error:\\n{e}\") from e\n    if any(isinstance(args[i], core.Tracer) for i in self.static_argnums):\n      raise UnexpectedTracerError(\"custom_jvp inputs marked with nondiff_argnums \"\n                                  \"must be static, not Tracers\")\n    if all(is_hashable(args[i]) for i in self.static_argnums):\n      traced = api.jit(self.f, static_argnums=(*self.static_argnums,)).trace(*args)\n    else:\n      # jit requires hashable static_argnums values, but classic custom_jvp\n      # accepted unhashable nondiff_argnums values, so close over them instead\n      which_static = [i in self.static_argnums for i in range(len(args))]\n      dyn_args, static_args = partition_list(which_static, args)\n      f = dyn_args_fun(self.f, self.static_argnums,\n                       tuple(map(WrapHashably, static_args)), len(args))\n      traced = api.jit(f).trace(*dyn_args)\n    if any(isinstance(x, core.Tracer) for x in traced._consts):\n      t = next(x for x in traced._consts if isinstance(x, core.Tracer))","sourceCodeStart":1185,"sourceCodeEnd":1221,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/hijax.py#L1185-L1221","documentation":"The custom_jvp wrapper resolves keyword arguments to positional-only arguments using the decorated function's signature (resolve_kwargs). If binding fails — wrong kwarg name, unexpected kwargs, or missing required ones — the original TypeError is re-raised with this message explaining the positional-only constraint.","triggerScenarios":"Calling a @custom_jvp function with keyword arguments that don't bind to its signature, e.g. f(x=1, nonexistent=2), or calling with kwargs when the wrapped function uses *args or positional-only params.","commonSituations":"Refactoring function parameter names while callers still use old kwarg names; wrapper functions that forward **kwargs blindly; methods decorated with custom_jvp where 'self' shifts positions and breaks static_argnums indices.","solutions":["Call the function with positional arguments only","Fix kwarg names to match the decorated function's signature exactly","When wrapping, normalize kwargs to positional with inspect.signature(...).bind before calling"],"exampleFix":"// before\n@jax.custom_jvp\ndef f(x, scale):\n  return x * scale\nf(x=1.0, scales=2.0)  # typo'd kwarg\n// after\nf(1.0, 2.0)\n# or f(x=1.0, scale=2.0)","handlingStrategy":"validation","validationCode":"import inspect\nsig = inspect.signature(f)\nbound = sig.bind(*args, **kwargs)  # raises early with a clear error if binding fails\nf(*bound.args)","typeGuard":null,"tryCatchPattern":"try:\n    f(**kwargs)\nexcept TypeError as e:\n    if 'could not be resolved to positional-only' in str(e):\n        # retry with positional args in signature order\n        f(*positional_in_order)","preventionTips":["Call custom_jvp functions with positional arguments","Validate kwargs with inspect.signature.bind before forwarding"],"tags":["jax","custom-jvp","kwargs","signature-binding"],"backgroundTag":"python-function-signature-binding-error","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}