apache/beam · error
Invalid output type in method %v, return value at index %v.
Error message
Invalid output type in method %v, return value at index %v. Got: %v, Want: %v (from method %v). Ensure that all restrictions in an SDF are the same type, and that %v returns a slice.
What it means
SplitRestriction must return a slice whose element type is exactly the restriction type from CreateInitialRestriction. This error fires when the first return value is not a slice of that restriction type (wrong element type, not a slice, or a pointer type).
Source
Thrown at sdks/go/pkg/beam/core/graph/fn.go:1024
if err := validateSdfElementT(fn, createInitialRestrictionName, method, num, startIdx); err != nil {
return err
}
case splitRestrictionName:
if err := validateSdfElementT(fn, splitRestrictionName, method, num, startIdx); err != nil {
return err
}
idx := num + startIdx
if method.Param[idx].T != restrictionT {
err := errors.Errorf("mismatched restriction type in method %v, param %v. got: %v, want: %v",
splitRestrictionName, idx, method.Param[idx].T, restrictionT)
return errors.SetTopLevelMsgf(err, "Mismatched restriction type in method %v, "+
"parameter at index %v. Got: %v, Want: %v (from method %v). "+
"Ensure that all restrictions in an SDF are the same type.",
splitRestrictionName, idx, method.Param[idx].T, restrictionT, createInitialRestrictionName)
}
if method.Ret[0].T.Kind() != reflect.Slice ||
method.Ret[0].T.Elem() != restrictionT {
err := errors.Errorf("invalid output type in method %v, return %v. got: %v, want: %v",
splitRestrictionName, 0, method.Ret[0].T, reflect.SliceOf(restrictionT))
return errors.SetTopLevelMsgf(err, "Invalid output type in method %v, "+
"return value at index %v. Got: %v, Want: %v (from method %v). "+
"Ensure that all restrictions in an SDF are the same type, and that %v returns a slice.",
splitRestrictionName, 0, method.Ret[0].T, reflect.SliceOf(restrictionT), createInitialRestrictionName, splitRestrictionName)
}
case restrictionSizeName:
if err := validateSdfElementT(fn, restrictionSizeName, method, num, startIdx); err != nil {
return err
}
idx := num + startIdx
if method.Param[idx].T != restrictionT {
err := errors.Errorf("mismatched restriction type in method %v, param %v. got: %v, want: %v",
restrictionSizeName, idx, method.Param[idx].T, restrictionT)
return errors.SetTopLevelMsgf(err, "Mismatched restriction type in method %v, "+
"parameter at index %v. Got: %v, Want: %v (from method %v). "+
"Ensure that all restrictions in an SDF are the same type.",
restrictionSizeName, idx, method.Param[idx].T, restrictionT, createInitialRestrictionName)View on GitHub (pinned to 12126d8942)
Solutions
- Return a slice of the exact restriction type: []RestrictionType from CreateInitialRestriction.
- Remove pointer indirection if the restriction is a value type ([]T not []*T).
- Ensure the slice element type matches the restriction type identically (exact reflect equality).
- If returning an error, keep the slice first and error last.
Example fix
// before
func (fn *myFn) SplitRestriction(r myRestriction) ([]*myRestriction, error) { ... }
// after
func (fn *myFn) SplitRestriction(r myRestriction) ([]myRestriction, error) { ... } Defensive patterns
Strategy: validation
Validate before calling
// Assert SplitRestriction returns []RestrictionType:
func checkSplitReturn(t reflect.Type) error {
cir, _ := t.MethodByName("CreateInitialRestriction")
sr, _ := t.MethodByName("SplitRestriction")
want := reflect.SliceOf(cir.Type.Out(0))
got := sr.Type.Out(0)
if got != want {
return fmt.Errorf("SplitRestriction return %v, want %v", got, want)
}
return nil
} Prevention
- Always return a value slice ([]T), not pointers ([]*T)
- Update SplitRestriction's slice element type whenever the restriction type changes
- Add compile-time reflection checks in package tests
When it happens
Trigger: SplitRestriction returning []OtherRestriction, a single restriction value, []*T instead of []T, or a non-slice collection.
Common situations: Returning a pointer-to-restriction slice because the restriction type was changed to pointer form in some methods; returning one restriction without wrapping it in a slice; changing the restriction type in CreateInitialRestriction without updating the slice element type.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Mismatched restriction type in method %v, parameter at index
- Mismatched output type in method %v, return value at index %
- invalid number of main input params in method %v. got: %v, w
- unexpected number of params in method %v. got: %v, want: %v
- unexpected number of returns in method %v. got: %v, want: %v
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/7872e1600c1fcb09.
Report an issue: GitHub.