microsoft/autogen · error · ValueError

Invalid

Error message

Invalid

What it means

When loading a component, the provider string is split on the last '.' to yield (module_path, class_name). A provider with no dot — e.g. a bare class name or malformed entry — fails rsplit and raises ValueError('Invalid'). The terse message (it should say something like 'provider must be module.Class') reflects a minimal guard before the trusted-namespace check.

Source

Thrown at python/packages/autogen-core/src/autogen_core/_component_config.py:252

        Returns:
            Self | ExpectedType: The loaded component.
        """

        # Use global and add further type checks

        if isinstance(model, dict):
            loaded_model = ComponentModel(**model)
        else:
            loaded_model = model

        # First, do a look up in well known providers
        if loaded_model.provider in WELL_KNOWN_PROVIDERS:
            loaded_model.provider = WELL_KNOWN_PROVIDERS[loaded_model.provider]

        output = loaded_model.provider.rsplit(".", maxsplit=1)
        if len(output) != 2:
            raise ValueError("Invalid")

        module_path, class_name = output

        trusted = _get_trusted_namespaces()
        # Also allow test modules (pytest convention) to load components
        module_name = module_path.rsplit(".", maxsplit=1)[-1]
        is_test_module = module_name.startswith("test_") or module_path.startswith("test_")
        if not is_test_module and not any(
            module_path.startswith(ns) or module_path == ns.rstrip(".") for ns in trusted
        ):
            raise ValueError(
                f"Provider module '{module_path}' is not in a trusted namespace. "
                f"Allowed namespaces by default: autogen_core, autogen_agentchat, autogen_ext, "
                f"autogen_studio, autogenstudio. "
                f"To allow additional namespaces, set the AUTOGEN_ALLOWED_PROVIDER_NAMESPACES "
                f"environment variable to a comma-separated list "
                f"(e.g. AUTOGEN_ALLOWED_PROVIDER_NAMESPACES=mycompany_agents,mypackage)."
            )

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Use a fully qualified provider: "my_package.module.ClassName" (the exact string dump_component produces via _type_to_provider_str).
  2. Round-trip a working instance through dump_component() and copy its provider field as the template.
  3. If using a well-known short alias, verify it exists in WELL_KNOWN_PROVIDERS before substituting your own.

Example fix

# before
model = {"provider": "MyComponent", "config": {...}}
ComponentBase.load_component(model)  # ValueError: Invalid

# after
model = {"provider": "my_package.components.MyComponent", "config": {...}}
ComponentBase.load_component(model)
Defensive patterns

Strategy: validation

Validate before calling

def is_qualified_provider(provider: str) -> bool:
    return isinstance(provider, str) and len(provider.rsplit(".", maxsplit=1)) == 2 and all(provider.rsplit(".", maxsplit=1))

assert is_qualified_provider(model["provider"]), "provider must be 'package.module.Class'"

Type guard

def is_provider_string(v: object) -> TypeGuard[str]:
    if not isinstance(v, str):
        return False
    parts = v.rsplit(".", maxsplit=1)
    return len(parts) == 2 and all(p.isidentifier() for p in parts)

Try / catch

try:
    obj = ComponentBase.load_component(model)
except ValueError as e:
    if str(e) == "Invalid":
        raise ValueError(f"provider {model['provider']!r} must be 'package.module.Class'") from e
    raise

Prevention

When it happens

Trigger: ComponentModel(provider="MyClass", ...) or load_component with a dict where provider is "MyClass" instead of "my_package.module.MyClass"; provider strings built by string concatenation that dropped the module part; hand-written JSON configs with only the class name.

Common situations: Editing serialized component JSON by hand; generated configs from other tools that emit short provider names; provider typos replacing the dot.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/6970488faaaf528f. Report an issue: GitHub.