langchain-ai/deepagents · error · ModelConfigError

Class '{class_name}' not found in module '{module_path}' for

Error message

Class '{class_name}' not found in module '{module_path}' for provider '{provider}'

What it means

Raised when the configured `class_path` module imports fine but does not expose the named attribute. `_create_model_from_class` does `getattr(module, class_name, None)` and rejects None: a symbol that does not exist means the configured provider is unusable.

Source

Thrown at libs/code/deepagents_code/config.py:5394

            "must be in module.path:ClassName format"
        )
        raise ModelConfigError(msg)

    module_path, class_name = class_path.rsplit(":", 1)

    try:
        module = importlib.import_module(module_path)
    except ImportError as e:
        msg = f"Could not import module '{module_path}' for provider '{provider}': {e}"
        raise ModelConfigError(msg) from e

    cls = getattr(module, class_name, None)
    if cls is None:
        msg = (
            f"Class '{class_name}' not found in module '{module_path}' "
            f"for provider '{provider}'"
        )
        raise ModelConfigError(msg)

    if not (isinstance(cls, type) and issubclass(cls, _BaseChatModel)):
        msg = (
            f"'{class_path}' is not a BaseChatModel subclass (got {type(cls).__name__})"
        )
        raise ModelConfigError(msg)

    try:
        return cls(model=model_name, **kwargs)
    except Exception as e:
        msg = f"Failed to instantiate '{class_path}' for '{provider}:{model_name}': {e}"
        raise ModelConfigError(msg) from e


def _create_model_via_init(
    model_name: str,
    provider: str,
    kwargs: dict[str, Any],

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Check exports: `python -c "import my_pkg.models as m; print(dir(m))"`
  2. Correct the class name after the colon in config.toml to the current symbol
  3. Pin the custom package version if a newer release renamed the class

Example fix

// before (config.toml)
class_path = "my_pkg.models:MyChatModel"  # renamed upstream

// after
class_path = "my_pkg.models:MyChatModelV2"
Defensive patterns

Strategy: validation

Validate before calling

import importlib
def class_exists(class_path: str) -> bool:
    module_path, class_name = class_path.rsplit(":", 1)
    module = importlib.import_module(module_path)
    return hasattr(module, class_name)

Type guard

def is_exported_class(module: object, class_name: str) -> bool:
    import types
    attr = getattr(module, class_name, None)
    return isinstance(attr, type)

Try / catch

from deepagents_code.model_config import ModelConfigError
try:
    model = create_model(spec, class_path=class_path)
except ModelConfigError as e:
    if "not found in module" in str(e):
        import importlib
        m = importlib.import_module(class_path.rsplit(":", 1)[0])
        raise SystemExit(f"Available: {[n for n in dir(m) if not n.startswith('_')]}" )
    raise

Prevention

When it happens

Trigger: `class_path` resolves to an importable module but `ClassName` after the colon is not an attribute of it — the class was renamed, moved modules, the name is misspelled, or case does not match (config.py:5388-5394).

Common situations: Upgrading a custom model package where the class was renamed; copying `class_path` from older docs; pointing at a module that re-exports under a different name; case mistakes (`Chatmodel` vs `ChatModel`).

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/baf41967f6c177f1. Report an issue: GitHub.