reflex-dev/reflex · error · ConfigError

Invalid TOML file format at {pyproject_path}. Expected a dic

Error message

Invalid TOML file format at {pyproject_path}. Expected a dictionary.

What it means

ConfigError raised when the parsed TOML file's root is not a mapping. tomllib normally produces a dict, so this guards against degenerate/empty files or unexpected parser output; the CLI requires a table at the root to look up [tool.reflex-cloud].

Source

Thrown at packages/reflex-hosting-cli/src/reflex_cli/core/config.py:262

        Raises:
            ConfigError: If the TOML file is not found.

        """
        if not pyproject_path.exists():
            raise ConfigError(f"Config file not found at {pyproject_path}.")

        try:
            import tomllib
        except ImportError as e:
            raise ConfigError(
                "TOML support is not available. Please use Python 3.11 or later."
            ) from e

        with pyproject_path.open("rb") as file:
            pyproject_data = tomllib.load(file)
            if not isinstance(pyproject_data, dict):
                raise ConfigError(
                    f"Invalid TOML file format at {pyproject_path}. Expected a dictionary."
                )
            tools = pyproject_data.get("tool", {})
            if not isinstance(tools, dict):
                raise ConfigError(
                    f"Invalid TOML file format at {pyproject_path}. Expected 'tool' to be a dictionary."
                )
            if "reflex-cloud" not in tools:
                raise ConfigError(
                    f"Invalid TOML file format at {pyproject_path}. Expected 'tool.reflex-cloud' to be present."
                )
            data = tools["reflex-cloud"]
            if env:
                data = data.get("env", {}).get(env, {})
            data = cls._filter_dict(data)
        return cls(_cloud_config_path=pyproject_path, **data)

    @classmethod

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Open the reported file and restore valid TOML table syntax (e.g. [project] ... at minimum)
  2. If the file is not meant to be a TOML config, correct the path passed to from_toml
  3. Regenerate the file from your project template

Example fix

# before (pyproject.toml)
"just a string"

# after
[project]
name = "my-app"
Defensive patterns

Strategy: validation

Validate before calling

import tomllib
parsed = tomllib.loads(Path("pyproject.toml").read_text())
if not isinstance(parsed, dict) or not parsed:
    raise ValueError("pyproject.toml root is not a TOML table")

Type guard

def is_toml_table(data) -> bool:
    return isinstance(data, dict)

Try / catch

try:
    config = CloudConfig.from_toml(p)
except ConfigError as e:
    if "Expected a dictionary" in str(e):
        # rewrite the corrupted file from a template
        restore_default_pyproject(p)
    else:
        raise

Prevention

When it happens

Trigger: CloudConfig.from_toml on a pyproject.toml whose parsed root is not a dict (e.g. an effectively empty or malformed file that yields a non-dict).

Common situations: A truncated or corrupted pyproject.toml; accidentally pointing the config path at a non-TOML file that parses to a scalar/array.

Related errors


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