From c9125626726f93172ea1cbe007e91b6977e60d62 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 20 Oct 2026 19:23:31 -0700 Subject: [PATCH 1/5] test(proxy): cover managed files hook registration without the repo-only enterprise package --- .../unit/proxy/hooks/test_proxy_hooks_init.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/unit/proxy/hooks/test_proxy_hooks_init.py b/tests/unit/proxy/hooks/test_proxy_hooks_init.py index a6edd3db944..009d69912e0 100644 --- a/tests/unit/proxy/hooks/test_proxy_hooks_init.py +++ b/tests/unit/proxy/hooks/test_proxy_hooks_init.py @@ -14,8 +14,12 @@ silently swallowed the ImportError in `hooks/__init__.py`, leaving ``managed_files`` unregistered and the /files endpoint returning 500. """ +import importlib +import sys + import pytest +import litellm.proxy from litellm.proxy.hooks import PROXY_HOOKS, get_proxy_hook @@ -49,3 +53,21 @@ def test_isolation_module_does_not_pull_in_proxy_utils(): importlib.import_module("litellm.llms.base_llm.managed_resources.isolation") assert "litellm.proxy.utils" not in sys.modules assert "litellm.proxy.management_endpoints.common_utils" not in sys.modules + + +def test_managed_hooks_register_from_litellm_enterprise_without_the_repo_only_enterprise_package( + monkeypatch: pytest.MonkeyPatch, +): + pytest.importorskip("litellm_enterprise") + from litellm_enterprise.proxy.hooks.managed_files import PROXY_LiteLLMManagedFiles + from litellm_enterprise.proxy.hooks.managed_vector_stores import PROXY_LiteLLMManagedVectorStores + + monkeypatch.setitem(sys.modules, "enterprise", None) + monkeypatch.setitem(sys.modules, "enterprise.enterprise_hooks", None) + monkeypatch.delitem(sys.modules, "litellm.proxy.hooks") + monkeypatch.delattr(litellm.proxy, "hooks") + + wheel_install_hooks = importlib.import_module("litellm.proxy.hooks") + + assert wheel_install_hooks.get_proxy_hook("managed_files") is PROXY_LiteLLMManagedFiles + assert wheel_install_hooks.get_proxy_hook("managed_vector_stores") is PROXY_LiteLLMManagedVectorStores From 35d30d6428181a11bc1ad62ce30e7ec029126889 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 20 Oct 2026 19:25:25 -0700 Subject: [PATCH 2/5] fix(proxy): register managed files hooks from the litellm_enterprise package A pip-installed litellm[proxy] could not import the repo-only enterprise folder, so the managed_files and managed_vector_stores hooks never registered and POST /v1/files with target_model_names answered 500. Register both straight from litellm_enterprise, which the proxy extra installs, and log a warning naming both features when that import fails --- litellm/proxy/hooks/__init__.py | 29 ++++++++++--------- .../proxy/hooks/autorouter_baseline_cache.py | 6 ++-- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/litellm/proxy/hooks/__init__.py b/litellm/proxy/hooks/__init__.py index 138050ccc9a..444bc086d35 100644 --- a/litellm/proxy/hooks/__init__.py +++ b/litellm/proxy/hooks/__init__.py @@ -1,6 +1,9 @@ import os from typing import Final, Literal +from litellm._logging import verbose_proxy_logger +from litellm.integrations.custom_logger import CustomLogger + from . import * from .autorouter_baseline_cache import AutoRouterBaselineCache from .cache_control_check import ( # noqa: F401 # backwards-compatible package export @@ -32,10 +35,10 @@ from .sensitive_data_routing import ( # noqa: F401 # backwards-compatible pack ) # List of all available hooks that can be enabled. -# Defined before the enterprise import below so that any module re-imported -# transitively through `enterprise.enterprise_hooks` can resolve `PROXY_HOOKS` +# Defined before the litellm_enterprise hook imports below so that any module re-imported +# transitively through them can resolve `PROXY_HOOKS` # and `get_proxy_hook` from this partially-initialized module without circling. -PROXY_HOOKS: Final = { +PROXY_HOOKS: Final[dict[str, type[CustomLogger]]] = { # mutable-ok: shared with cycle importers, extended below "parallel_request_limiter": PROXY_MaxParallelRequestsHandler_v3, "cache_control_check": PROXY_CacheControlCheck, "responses_id_security": ResponsesIDSecurity, @@ -63,14 +66,14 @@ def get_proxy_hook( return PROXY_HOOKS[hook_name] -### CHECK IF ENTERPRISE HOOKS ARE AVAILABLE #### - try: - from enterprise.enterprise_hooks import ENTERPRISE_PROXY_HOOKS -except ImportError: - ENTERPRISE_PROXY_HOOKS = {} - - -### update PROXY_HOOKS with ENTERPRISE_PROXY_HOOKS ### - -PROXY_HOOKS.update(ENTERPRISE_PROXY_HOOKS) + from litellm_enterprise.proxy.hooks.managed_files import PROXY_LiteLLMManagedFiles + from litellm_enterprise.proxy.hooks.managed_vector_stores import PROXY_LiteLLMManagedVectorStores +except ImportError as litellm_enterprise_import_error: + verbose_proxy_logger.warning( + "Managed files and managed vector stores are disabled because litellm_enterprise failed to import: %s", + litellm_enterprise_import_error, + ) +else: + PROXY_HOOKS["managed_files"] = PROXY_LiteLLMManagedFiles + PROXY_HOOKS["managed_vector_stores"] = PROXY_LiteLLMManagedVectorStores diff --git a/litellm/proxy/hooks/autorouter_baseline_cache.py b/litellm/proxy/hooks/autorouter_baseline_cache.py index c4232609124..dc0f58d48b5 100644 --- a/litellm/proxy/hooks/autorouter_baseline_cache.py +++ b/litellm/proxy/hooks/autorouter_baseline_cache.py @@ -137,7 +137,9 @@ class AutoRouterBaselineCache(CustomLogger): return try: raw_metadata: Final = kwargs.get(get_metadata_variable_name_from_kwargs(kwargs)) - metadata: Final = _METADATA.validate_python(raw_metadata) if isinstance(raw_metadata, Mapping) else {} + metadata: Final[Mapping[str, object]] = ( + _METADATA.validate_python(raw_metadata) if isinstance(raw_metadata, Mapping) else {} + ) if metadata.get(INTERNAL_CALL_ORIGIN_METADATA_KEY): return if logging_obj.baseline_cache_context is not None: @@ -157,7 +159,7 @@ class AutoRouterBaselineCache(CustomLogger): prices: Final = _PRICES.validate_python( _effective_model_info(router, request.route.baseline_deployment_id, request.route.baseline_model) ) - params: Final = ( + params: Final[Mapping[str, object]] = ( _METADATA.validate_python(deployment.litellm_params.model_dump(mode="json")) if deployment else {} ) projected: Final = ( From dc488f4b10820163b010c69a1afeda4381652bdc Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 20 Oct 2026 20:09:46 -0700 Subject: [PATCH 3/5] test(proxy): cover the warning when litellm_enterprise cannot load --- .../unit/proxy/hooks/test_proxy_hooks_init.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/proxy/hooks/test_proxy_hooks_init.py b/tests/unit/proxy/hooks/test_proxy_hooks_init.py index 009d69912e0..6aeafda75a3 100644 --- a/tests/unit/proxy/hooks/test_proxy_hooks_init.py +++ b/tests/unit/proxy/hooks/test_proxy_hooks_init.py @@ -15,11 +15,13 @@ silently swallowed the ImportError in `hooks/__init__.py`, leaving """ import importlib +import logging import sys import pytest import litellm.proxy +from litellm._logging import verbose_proxy_logger from litellm.proxy.hooks import PROXY_HOOKS, get_proxy_hook @@ -71,3 +73,25 @@ def test_managed_hooks_register_from_litellm_enterprise_without_the_repo_only_en assert wheel_install_hooks.get_proxy_hook("managed_files") is PROXY_LiteLLMManagedFiles assert wheel_install_hooks.get_proxy_hook("managed_vector_stores") is PROXY_LiteLLMManagedVectorStores + + +def test_proxy_hooks_still_import_and_warn_when_litellm_enterprise_cannot_load( + monkeypatch: pytest.MonkeyPatch, + caplog: pytest.LogCaptureFixture, +): + monkeypatch.setitem(sys.modules, "litellm_enterprise.proxy.hooks.managed_files", None) + monkeypatch.delitem(sys.modules, "litellm.proxy.hooks") + monkeypatch.delattr(litellm.proxy, "hooks") + verbose_proxy_logger.addHandler(caplog.handler) + try: + with caplog.at_level(logging.WARNING, logger=verbose_proxy_logger.name): + hooks_without_enterprise = importlib.import_module("litellm.proxy.hooks") + finally: + verbose_proxy_logger.removeHandler(caplog.handler) + + assert "managed_files" not in hooks_without_enterprise.PROXY_HOOKS + assert "managed_vector_stores" not in hooks_without_enterprise.PROXY_HOOKS + assert "parallel_request_limiter" in hooks_without_enterprise.PROXY_HOOKS + assert any( + "Managed files and managed vector stores are disabled" in record.getMessage() for record in caplog.records + ) From f57972b10123220c38e108abc5400cd83263353b Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 20 Oct 2026 20:32:19 -0700 Subject: [PATCH 4/5] refactor(enterprise): drop the unused enterprise hook registry and update the Dockerfile notes --- Dockerfile | 4 +-- docker/Dockerfile.database | 4 +-- docker/Dockerfile.non_root | 4 +-- enterprise/enterprise_hooks/__init__.py | 33 ------------------------- 4 files changed, 6 insertions(+), 39 deletions(-) diff --git a/Dockerfile b/Dockerfile index 890c90fe449..ba914bd44e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -161,8 +161,8 @@ COPY --from=builder /app/docker /app/docker COPY --from=builder /app/schema.prisma /app/schema.prisma COPY --from=builder /app/litellm/proxy/prisma_migration.py /app/litellm/proxy/prisma_migration.py # enterprise/ is imported by source path at runtime (proxy_cli puts the -# working directory on sys.path; litellm/proxy/hooks resolves -# enterprise.enterprise_hooks from it) +# working directory on sys.path; the moderation and blocked user list +# callbacks import enterprise.enterprise_hooks from it) COPY --from=builder /app/enterprise /app/enterprise COPY --from=builder /app/litellm-proxy-extras /app/litellm-proxy-extras # Prisma CLI + engines are baked under /opt/prisma, a fixed path every diff --git a/docker/Dockerfile.database b/docker/Dockerfile.database index 56210458532..f1fe4a0a757 100644 --- a/docker/Dockerfile.database +++ b/docker/Dockerfile.database @@ -141,8 +141,8 @@ COPY --from=builder /app/docker /app/docker COPY --from=builder /app/schema.prisma /app/schema.prisma COPY --from=builder /app/litellm/proxy/prisma_migration.py /app/litellm/proxy/prisma_migration.py # enterprise/ is imported by source path at runtime (proxy_cli puts the -# working directory on sys.path; litellm/proxy/hooks resolves -# enterprise.enterprise_hooks from it) +# working directory on sys.path; the moderation and blocked user list +# callbacks import enterprise.enterprise_hooks from it) COPY --from=builder /app/enterprise /app/enterprise COPY --from=builder /app/litellm-proxy-extras /app/litellm-proxy-extras # Prisma CLI + engines are baked under /opt/prisma, a fixed path every diff --git a/docker/Dockerfile.non_root b/docker/Dockerfile.non_root index 086c38e0d60..0115597517a 100644 --- a/docker/Dockerfile.non_root +++ b/docker/Dockerfile.non_root @@ -147,8 +147,8 @@ COPY --from=builder /app/docker /app/docker COPY --from=builder /app/schema.prisma /app/schema.prisma COPY --from=builder /app/litellm/proxy/prisma_migration.py /app/litellm/proxy/prisma_migration.py # enterprise/ is imported by source path at runtime (proxy_cli puts the -# working directory on sys.path; litellm/proxy/hooks resolves -# enterprise.enterprise_hooks from it) +# working directory on sys.path; the moderation and blocked user list +# callbacks import enterprise.enterprise_hooks from it) COPY --from=builder /app/enterprise /app/enterprise COPY --from=builder /app/litellm-proxy-extras /app/litellm-proxy-extras # Prisma CLI + engines are baked under /opt/prisma, a fixed path every runtime diff --git a/enterprise/enterprise_hooks/__init__.py b/enterprise/enterprise_hooks/__init__.py index 6de3325f113..e69de29bb2d 100644 --- a/enterprise/enterprise_hooks/__init__.py +++ b/enterprise/enterprise_hooks/__init__.py @@ -1,33 +0,0 @@ -from typing import Dict, Literal, Type, Union - -from litellm_enterprise.proxy.hooks.managed_files import PROXY_LiteLLMManagedFiles -from litellm_enterprise.proxy.hooks.managed_vector_stores import ( - PROXY_LiteLLMManagedVectorStores, -) - -from litellm.integrations.custom_logger import CustomLogger - -ENTERPRISE_PROXY_HOOKS: Dict[str, Type[CustomLogger]] = { - "managed_files": PROXY_LiteLLMManagedFiles, - "managed_vector_stores": PROXY_LiteLLMManagedVectorStores, -} - - -def get_enterprise_proxy_hook( - hook_name: Union[ - Literal[ - "managed_files", - "managed_vector_stores", - "max_parallel_requests", - ], - str, - ], -): - """ - Factory method to get a enterprise hook instance by name - """ - if hook_name not in ENTERPRISE_PROXY_HOOKS: - raise ValueError( - f"Unknown hook: {hook_name}. Available hooks: {list(ENTERPRISE_PROXY_HOOKS.keys())}" - ) - return ENTERPRISE_PROXY_HOOKS[hook_name] From 6336e9732834c89e98b2aa99f06d92d2dfa03961 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 20 Oct 2026 21:07:52 -0700 Subject: [PATCH 5/5] test(proxy): annotate the hook registry test bindings as Final --- tests/unit/proxy/hooks/test_proxy_hooks_init.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit/proxy/hooks/test_proxy_hooks_init.py b/tests/unit/proxy/hooks/test_proxy_hooks_init.py index 6aeafda75a3..82c2a24f4c1 100644 --- a/tests/unit/proxy/hooks/test_proxy_hooks_init.py +++ b/tests/unit/proxy/hooks/test_proxy_hooks_init.py @@ -17,6 +17,7 @@ silently swallowed the ImportError in `hooks/__init__.py`, leaving import importlib import logging import sys +from typing import Final import pytest @@ -69,7 +70,7 @@ def test_managed_hooks_register_from_litellm_enterprise_without_the_repo_only_en monkeypatch.delitem(sys.modules, "litellm.proxy.hooks") monkeypatch.delattr(litellm.proxy, "hooks") - wheel_install_hooks = importlib.import_module("litellm.proxy.hooks") + wheel_install_hooks: Final = importlib.import_module("litellm.proxy.hooks") assert wheel_install_hooks.get_proxy_hook("managed_files") is PROXY_LiteLLMManagedFiles assert wheel_install_hooks.get_proxy_hook("managed_vector_stores") is PROXY_LiteLLMManagedVectorStores @@ -85,7 +86,7 @@ def test_proxy_hooks_still_import_and_warn_when_litellm_enterprise_cannot_load( verbose_proxy_logger.addHandler(caplog.handler) try: with caplog.at_level(logging.WARNING, logger=verbose_proxy_logger.name): - hooks_without_enterprise = importlib.import_module("litellm.proxy.hooks") + hooks_without_enterprise: Final = importlib.import_module("litellm.proxy.hooks") finally: verbose_proxy_logger.removeHandler(caplog.handler)