{"record":{"id":"cfc3ba650e1156db","repo":"BerriAI/litellm","slug":"utils-module-lazy-import-unknown-attribute-name","errorCode":null,"errorMessage":"Utils module lazy import: unknown attribute {name!r}","messagePattern":"Utils module lazy import: unknown attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"litellm/_lazy_imports.py","lineNumber":339,"sourceCode":"    \"\"\"Handler for litellm_logging module (Logging, modify_integration)\"\"\"\n    return _generic_lazy_import(name, _LITELLM_LOGGING_IMPORT_MAP, \"Litellm logging\")\n\n\ndef _lazy_import_llm_provider_logic(name: str) -> Any:\n    \"\"\"Handler for LLM provider logic functions (get_llm_provider, etc.)\"\"\"\n    return _generic_lazy_import(name, _LLM_PROVIDER_LOGIC_IMPORT_MAP, \"LLM provider logic\")\n\n\ndef _lazy_import_utils_module(name: str) -> Any:\n    \"\"\"\n    Handler for utils module lazy imports.\n\n    This uses a custom implementation because utils module needs to use\n    _get_utils_globals() instead of get_litellm_globals() for caching.\n    \"\"\"\n    # Check if this attribute exists in our map\n    if name not in _UTILS_MODULE_IMPORT_MAP:\n        raise AttributeError(f\"Utils module lazy import: unknown attribute {name!r}\")\n\n    # Get the cache (where we store imported things) - use utils globals\n    _globals: Final = _get_utils_globals()\n\n    # If we've already imported it, just return the cached version\n    if name in _globals:\n        return _globals[name]\n\n    # Look up where to find this attribute\n    module_path, attr_name = _UTILS_MODULE_IMPORT_MAP[name]\n\n    # Import the module\n    if module_path.startswith(\".\"):\n        module = importlib.import_module(module_path, package=\"litellm\")\n    else:\n        module = importlib.import_module(module_path)\n\n    # Get the actual attribute from the module","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/_lazy_imports.py#L321-L357","documentation":"The utils-module lazy handler in litellm/_lazy_imports.py resolves only names listed in _UTILS_MODULE_IMPORT_MAP (cached into utils globals). Accessing litellm.utils-surface names not present in that map raises AttributeError('Utils module lazy import: unknown attribute ...'). It means the requested util symbol is not one of the lazily exported utils attributes — misspelled, removed in a refactor, or living in another module.","triggerScenarios":"`litellm.get_max_tokens` style accesses routed through the utils lazy path where the name is not in the map; using utils helpers renamed between versions (e.g. older function names after a cleanup); calling internal helpers that were never public.","commonSituations":"Code written against an older/newer litellm where the utils map changed; porting snippets from GitHub issues that touch litellm internals; autocomplete-driven typos.","solutions":["Confirm the name exists: check _UTILS_MODULE_IMPORT_MAP in litellm/_lazy_imports.py for your version","Import from the actual module (from litellm.utils import ...) which bypasses the map restriction for real exports","Upgrade/downgrade litellm to the version matching your code","Replace removed helpers with their documented successors"],"exampleFix":"# before\nimport litellm\nlitellm.utils.get_model_cost_map  # Utils module lazy import: unknown attribute\n\n# after\nfrom litellm.utils import get_model_cost_map  # import from the defining module\n# or use the documented replacement helper","handlingStrategy":"type-guard","validationCode":"import litellm\n\nutils_names = [\"get_litellm_params\", \"token_counter\"]\nmissing = [n for n in utils_names if not hasattr(litellm, n)]\nif missing:\n    raise RuntimeError(f\"utils lazy map lacks {missing}; import from litellm.utils directly\")","typeGuard":"from typing import Any\nimport litellm\n\ndef utils_attr(name: str) -> Any:\n    \"\"\"Resolve a utils-surface name or raise a clear AttributeError.\"\"\"\n    if not hasattr(litellm, name):\n        raise AttributeError(\n            f\"{name!r} not in _UTILS_MODULE_IMPORT_MAP; use `from litellm.utils import {name}`\"\n        )\n    return getattr(litellm, name)","tryCatchPattern":"try:\n    helper = getattr(litellm, name)\nexcept AttributeError:\n    from litellm import utils as _utils\n    helper = getattr(_utils, name, None) or _utils  # fall back to module-level lookup","preventionTips":["Prefer `from litellm.utils import X` for utils helpers — it bypasses the lazy map entirely","Lock your litellm version in requirements to keep the utils export surface stable","When copying snippets from issues, check they match your installed major version"],"tags":["attributeerror","lazy-import","utils","api-surface","python"],"backgroundTag":"module-has-no-attribute","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}