reflex-dev/reflex · error · ValueError
OTP field `length` is required when passing children explici
Error message
OTP field `length` is required when passing children explicitly.
What it means
The OTP field wrapper auto-generates length input slots only when you pass no children; with explicit children it cannot infer the count, so you must pass length explicitly (as a static int) so it can wire up paste/caret behavior.
Source
Thrown at packages/reflex-components-internal/src/reflex_components_internal/components/base/otp_field.py:179
Args:
*children: Optional children to include in place of the default inputs.
**props: Additional properties to apply to the OTP field root.
Returns:
The OTP field component.
Raises:
ValueError: If `length` is missing when children are supplied, or
if `length` is not a positive integer when children are
auto-generated.
TypeError: If `length` is not an integer when children are
auto-generated (a Var can only be used with explicit children).
"""
if children:
if "length" not in props:
msg = "OTP field `length` is required when passing children explicitly."
raise ValueError(msg)
else:
length = props.setdefault("length", 6)
if not isinstance(length, int) or isinstance(length, bool):
msg = (
"OTP field high-level wrapper requires a static integer `length`."
" Pass children explicitly for dynamic lengths."
)
raise TypeError(msg)
if length <= 0:
msg = "OTP field `length` must be a positive integer."
raise ValueError(msg)
children = tuple(OTPFieldInput.create() for _ in range(length))
return OTPFieldRoot.create(*children, **props)
class OTPField(ComponentNamespace):
"""Namespace for OTP field components."""View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Pass an explicit integer: rx.otp_field(*slots, length=4)
- Or pass no children and use length=N (default 6) to auto-generate slots
- Remember length must be a static int when children are auto-generated; only explicit-children mode needs the prop here
Example fix
# before rx.otp_field(rx.otp_field.slot(), rx.otp_field.slot()) # after rx.otp_field(rx.otp_field.slot(), rx.otp_field.slot(), length=2)
Defensive patterns
Strategy: validation
Validate before calling
if children and 'length' not in kwargs:
kwargs['length'] = len(children)
rx.otp_field(*children, **kwargs) Prevention
- Pass length=N whenever you pass explicit slot children
- Use auto-generated slots (no children) for the common case
When it happens
Trigger: rx.otp_field(rx.otp_field.slot(), rx.otp_field.slot()) without length=4 — children given but length omitted.
Common situations: Customizing slot rendering (custom separators, styling) by passing children manually and forgetting length; trying to use a Var length (not allowed without static behavior).
Related errors
- OTP field high-level wrapper requires a static integer `leng
- OTP field `length` must be a positive integer.
- ChildrenTypeError(component=cls.__name__, child=child)
- Do not override _add_style directly. Use add_style instead.
- The component `{comp_name}` cannot have `{child_name}` as a
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/9533b9a5c9f90f09.
Report an issue: GitHub.