reflex-dev/reflex · error · EnvironmentVarValueError

Invalid float value: {value!r} for {field_name}

Error message

Invalid float value: {value!r} for {field_name}

What it means

interpret_float_env converts an env var string with float(value); failure raises EnvironmentVarValueError naming the field. Same pattern as the int interpreter but for float-typed config fields.

Source

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

def interpret_float_env(value: str, field_name: str) -> float:
    """Interpret a float environment variable value.

    Args:
        value: The environment variable value.
        field_name: The field name.

    Returns:
        The interpreted value.

    Raises:
        EnvironmentVarValueError: If the value is invalid.
    """
    try:
        return float(value)
    except ValueError as ve:
        msg = f"Invalid float value: {value!r} for {field_name}"
        raise EnvironmentVarValueError(msg) from ve


def interpret_existing_path_env(value: str, field_name: str) -> ExistingPath:
    """Interpret a path environment variable value as an existing path.

    Args:
        value: The environment variable value.
        field_name: The field name.

    Returns:
        The interpreted value.

    Raises:
        EnvironmentVarValueError: If the path does not exist.
    """
    path = Path(value)
    if not path.exists():
        msg = f"Path does not exist: {path!r} for {field_name}"

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Use a dot-decimal numeric string, e.g. RATE=0.5
  2. Ensure the variable is actually set (empty string is invalid)
  3. For optional floats, use a union like float | None with a sentinel so unset maps properly

Example fix

# before
RATE=0,5
# after
RATE=0.5
Defensive patterns

Strategy: validation

Validate before calling

try:
    float(raw)
except ValueError:
    raise SystemExit(f"RATE must be a float, got {raw!r}")

Type guard

def is_valid_float_env(v: str) -> bool:
    try:
        float(v)
        return True
    except ValueError:
        return False

Try / catch

except EnvironmentVarValueError:
    value = 1.0  # fallback

Prevention

When it happens

Trigger: A float-typed field receives a non-numeric string: RATE=fast, COMPRESSION=0,5 (comma decimal separator), or an empty string.

Common situations: Locale differences (comma vs dot decimals), empty values from unset CI variables interpolating as '', or textual values in numeric fields.

Related errors


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