{"record":{"id":"baf41967f6c177f1","repo":"langchain-ai/deepagents","slug":"class-class-name-not-found-in-module-module","errorCode":null,"errorMessage":"Class '{class_name}' not found in module '{module_path}' for provider '{provider}'","messagePattern":"Class '(.+?)' not found in module '(.+?)' for provider '(.+?)'","errorType":"exception","errorClass":"ModelConfigError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/config.py","lineNumber":5394,"sourceCode":"            \"must be in module.path:ClassName format\"\n        )\n        raise ModelConfigError(msg)\n\n    module_path, class_name = class_path.rsplit(\":\", 1)\n\n    try:\n        module = importlib.import_module(module_path)\n    except ImportError as e:\n        msg = f\"Could not import module '{module_path}' for provider '{provider}': {e}\"\n        raise ModelConfigError(msg) from e\n\n    cls = getattr(module, class_name, None)\n    if cls is None:\n        msg = (\n            f\"Class '{class_name}' not found in module '{module_path}' \"\n            f\"for provider '{provider}'\"\n        )\n        raise ModelConfigError(msg)\n\n    if not (isinstance(cls, type) and issubclass(cls, _BaseChatModel)):\n        msg = (\n            f\"'{class_path}' is not a BaseChatModel subclass (got {type(cls).__name__})\"\n        )\n        raise ModelConfigError(msg)\n\n    try:\n        return cls(model=model_name, **kwargs)\n    except Exception as e:\n        msg = f\"Failed to instantiate '{class_path}' for '{provider}:{model_name}': {e}\"\n        raise ModelConfigError(msg) from e\n\n\ndef _create_model_via_init(\n    model_name: str,\n    provider: str,\n    kwargs: dict[str, Any],","sourceCodeStart":5376,"sourceCodeEnd":5412,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/config.py#L5376-L5412","documentation":"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.","triggerScenarios":"`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).","commonSituations":"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`).","solutions":["Check exports: `python -c \"import my_pkg.models as m; print(dir(m))\"`","Correct the class name after the colon in config.toml to the current symbol","Pin the custom package version if a newer release renamed the class"],"exampleFix":"// before (config.toml)\nclass_path = \"my_pkg.models:MyChatModel\"  # renamed upstream\n\n// after\nclass_path = \"my_pkg.models:MyChatModelV2\"","handlingStrategy":"validation","validationCode":"import importlib\ndef class_exists(class_path: str) -> bool:\n    module_path, class_name = class_path.rsplit(\":\", 1)\n    module = importlib.import_module(module_path)\n    return hasattr(module, class_name)","typeGuard":"def is_exported_class(module: object, class_name: str) -> bool:\n    import types\n    attr = getattr(module, class_name, None)\n    return isinstance(attr, type)","tryCatchPattern":"from deepagents_code.model_config import ModelConfigError\ntry:\n    model = create_model(spec, class_path=class_path)\nexcept ModelConfigError as e:\n    if \"not found in module\" in str(e):\n        import importlib\n        m = importlib.import_module(class_path.rsplit(\":\", 1)[0])\n        raise SystemExit(f\"Available: {[n for n in dir(m) if not n.startswith('_')]}\" )\n    raise","preventionTips":["Verify symbol names after every upgrade of the custom model package","Pin the package version in lock files to avoid surprise renames","Use dir(module) to confirm the exact exported class name"],"tags":["config","import","attribute"],"backgroundTag":"attribute-not-found","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}