cocoindex-io/cocoindex · error · ValueError

Expected at least one input argument

Error message

Expected at least one input argument

What it means

In batching mode, the wrapped function receives a batch as its first positional argument. _execute requires at least one positional argument to form that batch input; calling a batching coco.fn with zero positional arguments raises this ValueError.

Source

Thrown at python/cocoindex/_internal/function.py:1485

            if self._orig_async_fn is not None:
                return await self._orig_async_fn(*args, **kwargs)  # type: ignore
            else:
                assert self._orig_sync_fn is not None
                return await asyncio.to_thread(self._orig_sync_fn, *args, **kwargs)

        if self._has_self:
            if len(args) < 1:
                raise ValueError("Expected self argument")
            self_obj = args[0]
            actual_args = args[1:]
        else:
            self_obj = None
            actual_args = args

        # Parse args based on mode
        if self._batching:
            if len(actual_args) < 1:
                raise ValueError("Expected at least one input argument")
            input_val = actual_args[0]
            extra_args = tuple(actual_args[1:])
            extra_kwargs = dict(kwargs)
        else:
            # Runner-only mode: wrap (args, kwargs) as single input
            input_val = (actual_args, kwargs)
            extra_args = ()
            extra_kwargs = {}

        batcher_key, batcher = self._acquire_batcher(
            async_ctx, self_obj, extra_args, extra_kwargs
        )
        try:
            result = await batcher.run(input_val)
            _deadline_checkpoint()
        finally:
            self._release_batcher(batcher_key)
        # After a RetryWithSmallerBatch split, a failed sub-batch delivers its

View on GitHub (pinned to e84aa99b32)

Solutions

  1. Pass the batch (list/iterable of inputs) as the first positional argument.
  2. If the function is not meant to batch, remove batching=True from the decorator.
  3. Fix dynamic call sites to always include at least one positional input.

Example fix

// before
result = await batched_fn()
// after
result = await batched_fn([item1, item2])
Defensive patterns

Strategy: validation

Validate before calling

if batching and len(args) < 1:
    raise ValueError("batching fn needs the batch as first positional arg")

Try / catch

try:
    out = await batched_fn(*args)
except ValueError as e:
    if "at least one input argument" in str(e):
        out = await batched_fn(items)

Prevention

When it happens

Trigger: Calling a function declared with batching=True (via coco.fn batching mode) with no positional args, e.g. fn() or fn(key=value) only; empty positional list forwarded by the core processor.

Common situations: Switching a function to batching mode and forgetting that callers must pass the batch/iterable as the first positional argument; a dispatcher that builds args dynamically and produces an empty tuple.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of cocoindex-io/cocoindex@e84aa99b32 (2026-09-08). Data as JSON: /api/errors/1009994eed5fa090. Report an issue: GitHub.