From 36844ef301568736f14d9bef20dd18cf284468fb Mon Sep 17 00:00:00 2001 From: yucheng Date: Thu, 17 Sep 2026 22:26:00 +0000 Subject: [PATCH] fix(proxy): clamp prompt injection heuristics worker count to at least one Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/constants.py | 2 +- .../test_litellm/proxy/hooks/test_prompt_injection_detection.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/litellm/constants.py b/litellm/constants.py index 9153e00f131..6ef3f2ba752 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -605,7 +605,7 @@ LOGGING_EXECUTOR_MAX_THREADS: Final = get_env_int("LOGGING_EXECUTOR_MAX_THREADS" LOGGING_EXECUTOR_MAX_PENDING_TASKS: Final = get_env_int("LOGGING_EXECUTOR_MAX_PENDING_TASKS", 10_000) LOGGING_EXECUTOR_DROPPED_TASK_LOG_INTERVAL_SECONDS: Final = 30.0 AWS_SIGNING_MAX_THREADS: Final = 16 -PROMPT_INJECTION_HEURISTICS_MAX_THREADS: Final = get_env_int("PROMPT_INJECTION_HEURISTICS_MAX_THREADS", 1) +PROMPT_INJECTION_HEURISTICS_MAX_THREADS: Final = max(1, get_env_int("PROMPT_INJECTION_HEURISTICS_MAX_THREADS", 1)) DD_TRACER_STREAMING_CHUNK_YIELD_RESOURCE: Final = os.getenv( "DD_TRACER_STREAMING_CHUNK_YIELD_RESOURCE", "streaming.chunk.yield" ) diff --git a/tests/test_litellm/proxy/hooks/test_prompt_injection_detection.py b/tests/test_litellm/proxy/hooks/test_prompt_injection_detection.py index d629cf3032e..a04ed9345ee 100644 --- a/tests/test_litellm/proxy/hooks/test_prompt_injection_detection.py +++ b/tests/test_litellm/proxy/hooks/test_prompt_injection_detection.py @@ -130,7 +130,7 @@ async def test_heuristics_check_does_not_occupy_default_executor(): @pytest.mark.parametrize( ("configured", "expected"), - [("3", 3), ("not-an-int", 1)], + [("3", 3), ("not-an-int", 1), ("0", 1), ("-2", 1)], ) def test_heuristics_thread_count_config_is_honoured(monkeypatch: pytest.MonkeyPatch, configured: str, expected: int): monkeypatch.setenv("PROMPT_INJECTION_HEURISTICS_MAX_THREADS", configured)