{"record":{"id":"11da187a7f05d814","repo":"langchain-ai/deepagents","slug":"could-not-import-module-module-path-for-provid","errorCode":null,"errorMessage":"Could not import module '{module_path}' for provider '{provider}': {e}","messagePattern":"Could not import module '(.+?)' for provider '(.+?)': (.+?)","errorType":"exception","errorClass":"ModelConfigError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/config.py","lineNumber":5386,"sourceCode":"        BaseChatModel as _BaseChatModel,  # Runtime import; module level is typing only\n    )\n\n    from deepagents_code.model_config import ModelConfigError\n\n    if \":\" not in class_path:\n        msg = (\n            f\"Invalid class_path '{class_path}' for provider '{provider}': \"\n            \"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:","sourceCodeStart":5368,"sourceCodeEnd":5404,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/config.py#L5368-L5404","documentation":"Raised when the module portion of a configured `class_path` cannot be imported; the ImportError is wrapped as `ModelConfigError` with the original exception chained via `from e`, preserving the root cause. A module that itself raises ImportError during import also lands here.","triggerScenarios":"`_create_from_class` calls `importlib.import_module(module_path)` which raises ImportError — the package is not installed in the active environment, the module name is misspelled, or a transitive import inside the module fails (config.py:5382-5386).","commonSituations":"Custom model package installed in a different virtualenv than dcode's; typo in the module path (`my_pkd.models`); a dependency of the module missing after an upgrade; editable install stale after a rename.","solutions":["Read the chained ImportError in the message — it names the real cause","Install the module's package into the same environment dcode runs in (`pip install my_pkg` or `uv pip install -e ./my_pkg`)","Fix the module path in config.toml or the missing transitive dependency"],"exampleFix":"// before (config.toml)\nclass_path = \"my_pkd.models:MyChatModel\"  # typo\n\n// after\nclass_path = \"my_pkg.models:MyChatModel\"\n$ pip install -e ./my_pkg","handlingStrategy":"try-catch","validationCode":"import importlib.util\ndef module_importable(module_path: str) -> bool:\n    try:\n        return importlib.util.find_spec(module_path) is not None\n    except (ImportError, ValueError):\n        return False","typeGuard":null,"tryCatchPattern":"from deepagents_code.model_config import ModelConfigError\ntry:\n    model = create_model(spec, class_path=class_path)\nexcept ModelConfigError as e:\n    if \"Could not import module\" in str(e):\n        print(f\"Install the package defining {class_path.split(':')[0]}\")\n        raise SystemExit(1)\n    raise","preventionTips":["Install custom model packages into the same venv dcode uses","Test `importlib.import_module(module_path)` in CI before deploying config","Avoid renaming modules without checking config.toml references"],"tags":["import","python","config","dependency"],"backgroundTag":"module-not-found","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}