apache/beam · error
method has too few main inputs
Error message
%v method has too few main inputs
What it means
validateMainInputs also enforces a minimum main-input count (numMainIn, default MainSingle). When ProcessElement declares fewer main inputs than required (e.g. zero or one where two are expected for KV inputs), this error is raised with a detailed top-level message.
Solutions
- Declare the required number of main input parameters (e.g. k, v for KVs)
- Ensure numMainIn passed to NewDoFn/AsDoFn options matches the method signature
- Check that the incoming PCollection type matches what the method expects
Example fix
// before func (f *MyFn) ProcessElement(ctx context.Context, k string, emit func(int)) error // expects KV // after func (f *MyFn) ProcessElement(ctx context.Context, k string, v int, emit func(int)) error
Defensive patterns
Strategy: validation
Validate before calling
// ensure ProcessElement's main-input count matches the incoming PCollection shape (KV => 2 params)
Prevention
- Match ProcessElement parameters to the PCollection coders (KV adds a key parameter)
- Set numMainIn option only when intentionally handling multi-input DoFns
When it happens
Trigger: Using a DoFn with numMainIn > 1 (e.g. MainKVs) but declaring ProcessElement with a single element parameter; or dropping one of two parameters for a keyed PCollection.
Common situations: Applying a KV-expecting DoFn to key/value side-input patterns; changing PCollection element type from KV to single value without updating ProcessElement.
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
- method has no main inputs
- Duplicate state key used by and . Ensure that state keys…
- emit parameter in method
- emit parameters expected in method
- error writing state
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/01292ace951518af.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/graph/fn.go:668
// validateMainInputs checks that a method has the given number of main inputs
// and that main inputs are before any side inputs.
func validateMainInputs(fn *Fn, method *funcx.Fn, methodName string, numMainIn mainInputs) error {
if numMainIn == MainUnknown {
numMainIn = MainSingle // If unknown, validate for minimum number of inputs.
}
// Make sure there are enough inputs (at least numMainIn)
pos, num, ok := method.Inputs()
if !ok {
err := errors.Errorf("%v method has no main inputs", methodName)
err = errors.SetTopLevelMsgf(err,
"Method %v in DoFn %v is missing all inputs. A main input is required.",
methodName, fn.Name())
return err
}
if num < int(numMainIn) {
err := errors.Errorf("%v method has too few main inputs", methodName)
err = errors.SetTopLevelMsgf(err,
"Method %v in DoFn %v does not have enough main inputs. "+
"%v main inputs were expected, but only %v inputs were found.",
methodName, fn.Name(), numMainIn, num)
return err
}
// Check that the first input is not an Iter or ReIter (those aren't valid
// as the first main input).
first := method.Param[pos].Kind
if first != funcx.FnValue {
err := errors.New("first main input parameter must be a value type")
err = errors.SetTopLevelMsgf(err,
"Method %v of DoFns should always have the first input be a value type, "+
"but it has an Iter or ReIter first in DoFn %v.",
processElementName, fn.Name())
return errors.WithContextf(err, "method %v", processElementName)
}View on GitHub (pinned to 12126d8942)