reflex-dev/reflex · warning · ValueError

Invalid type for environment variable {field_name}: {field_t

Error message

Invalid type for environment variable {field_name}: {field_type}. This is probably an issue in Reflex.

What it means

interpret_env_var_value exhausted its type dispatch (str, bool, LogLevel, int, float, Path, enums, sequences, unions, literals...) and hit a field annotation it cannot handle, so it raises ValueError stating 'This is probably an issue in Reflex.' It indicates an annotation the env-parsing layer doesn't support rather than a user value problem.

Source

Thrown at packages/reflex-base/src/reflex_base/environment.py:391

            sequence_options = arg
            break
    if get_origin(field_type) in (list, Sequence):
        items = value.split(sequence_options.delimiter)
        if sequence_options.strip:
            items = [item.strip() for item in items]
        return [
            interpret_env_var_value(
                v,
                get_args(field_type)[0],
                f"{field_name}[{i}]",
            )
            for i, v in enumerate(items)
        ]
    if isinstance(field_type, type) and issubclass(field_type, enum.Enum):
        return interpret_enum_env(value, field_type, field_name)

    msg = f"Invalid type for environment variable {field_name}: {field_type}. This is probably an issue in Reflex."
    raise ValueError(msg)


T = TypeVar("T")


class EnvVar(Generic[T]):
    """Environment variable."""

    name: str
    default: Any
    type_: T

    def __init__(self, name: str, default: Any, type_: T) -> None:
        """Initialize the environment variable.

        Args:
            name: The environment variable name.
            default: The default value.

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Change the field annotation to a supported primitive (str, int, float, bool, Path, enum, Literal, Sequence, unions of these) and parse complex types yourself
  2. If the annotation looks like it should be supported, report/check the Reflex issue tracker — the message itself flags a possible framework bug
  3. As a workaround, read the raw str and validate in __post_init__

Example fix

# before
@dataclasses.dataclass
class Settings:
    limits: dict[str, int] = ...  # unsupported
# after
@dataclasses.dataclass
class Settings:
    limits_raw: str = ""  # 'a=1,b=2'
    @property
    def limits(self) -> dict[str, int]:
        return {k: int(v) for k, v in (p.split('=') for p in self.limits_raw.split(',') if p)}
Defensive patterns

Strategy: type-guard

Validate before calling

SUPPORTED = {str, bool, int, float, Path}
assert field_annotation in SUPPORTED or hasattr(field_annotation, "__args__"), f"unsupported env field type: {field_annotation}"

Type guard

def is_supported_env_type(t) -> bool:
    import enum, typing
    return (t in {str, bool, int, float, Path}
            or (isinstance(t, type) and issubclass(t, enum.Enum))
            or typing.get_origin(t) is not None)

Try / catch

null

Prevention

When it happens

Trigger: Annotating an env-parsed dataclass field with an unsupported type such as dict[str, int], a custom class, date, or a generic alias the dispatcher doesn't special-case.

Common situations: Adding richly-typed fields to config dataclasses, or upgrading Reflex where a previously tolerated annotation is no longer routed to an interpreter.

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/05d3f51bb103b323. Report an issue: GitHub.