Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion litellm/litellm_core_utils/litellm_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
SERVED_OUTPUT_TEXTS_KEY,
overlay_served_output_texts,
)
from litellm.litellm_core_utils.thread_pool_executor import executor
from litellm.llms.base_llm.ocr.transformation import OCRResponse
from litellm.llms.base_llm.search.transformation import SearchResponse
from litellm.responses.utils import ResponseAPILoggingUtils
Expand Down Expand Up @@ -173,7 +174,7 @@
Usage,
)
from litellm.types.videos.main import VideoObject
from litellm.utils import _get_base_model_from_metadata, executor, print_verbose
from litellm.utils import _get_base_model_from_metadata, print_verbose

from ..integrations.argilla import ArgillaLogger
from ..integrations.arize.arize_phoenix import ArizePhoenixLogger
Expand Down
2 changes: 1 addition & 1 deletion litellm/litellm_core_utils/streaming_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ def _dispatch_provider_chunk(
self,
chunk: Any,
model_response: ModelResponseStream,
completion_obj: dict[str, Any],
completion_obj: dict[str, object],
) -> _ProviderChunkResult:
response_obj: dict[str, Any] = {}
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,7 @@ def _create_elicitation_callback():


def _record_mcp_guardrail_evaluations(
synthetic_llm_data: dict[str, Any], # mutable-ok: `_sync_guardrail_info_to_logging_obj` takes a concrete dict
synthetic_llm_data: dict[str, object], # mutable-ok: `_sync_guardrail_info_to_logging_obj` takes a concrete dict
litellm_logging_obj: "LiteLLMLoggingObj | None",
) -> None:
"""Bridge guardrail decision records off an MCP synthetic request onto the request's logger.
Expand Down
16 changes: 8 additions & 8 deletions litellm/proxy/auth/user_api_key_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import secrets
from collections.abc import Mapping
from datetime import datetime, timezone
from typing import Any, Final, NamedTuple, Protocol, Union, cast
from typing import Final, NamedTuple, Protocol, Union, cast

import fastapi
import orjson
Expand Down Expand Up @@ -207,7 +207,7 @@ def _get_model_from_request_context(
request_data: dict,
route: str,
request: Request | None,
llm_router: Any | None = None,
llm_router: litellm.Router | None = None,
team_id: str | None = None,
) -> str | list[str] | None:
return get_model_from_request(
Expand Down Expand Up @@ -512,8 +512,8 @@ def _get_bearer_token_or_received_api_key(api_key: str) -> str:


def _routing_selector_matches_claim(
selector_value: Any | None,
claim_value: Any | None,
selector_value: str | list[str] | None,
claim_value: object,
*,
split_space_delimited: bool = False,
) -> bool:
Expand Down Expand Up @@ -653,7 +653,7 @@ async def user_api_key_auth_websocket_for_model(websocket: WebSocket, model: str
# ``websocket.url``, which Starlette reconstructs from the (poisonable)
# Host header. Carry the ASGI scope's path / root_path so the lookup
# never reaches the fallback.
synthetic_scope: Final[dict[str, Any]] = {
synthetic_scope: Final[dict[str, object]] = {
"type": "http",
"headers": scope_headers,
"path": ws_scope.get("path", ""),
Expand Down Expand Up @@ -3099,7 +3099,7 @@ async def _reserve_budget_after_common_checks(
user_api_key_auth_obj: UserAPIKeyAuth,
request_data: dict,
route: str,
llm_router: Any | None,
llm_router: litellm.Router | None,
team_object: LiteLLM_TeamTableCachedObj | None,
user_object: LiteLLM_UserTable | None,
prisma_client: PrismaClient | None,
Expand Down Expand Up @@ -3142,7 +3142,7 @@ def _should_skip_budget_checks(
request_data: dict,
route: str,
request: Request | None,
llm_router: Any | None,
llm_router: litellm.Router | None,
team_id: str | None = None,
) -> bool:
model: Final = _get_model_from_request_context(
Expand Down Expand Up @@ -3598,7 +3598,7 @@ async def _enforce_key_and_fallback_model_access(
route: str,
request: Request | None,
llm_model_list: list | None,
llm_router: Any | None,
llm_router: litellm.Router | None,
) -> None:
"""
Key-level model allowlist and client fallbacks (same as standard auth).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ async def _post_apply_guardrail_content_with_retry(
or attempt >= _BEDROCK_APPLY_GUARDRAIL_MAX_THROTTLE_RETRIES
):
raise
await asyncio.sleep(_BEDROCK_APPLY_GUARDRAIL_BASE_BACKOFF_SECONDS * (2**attempt))
await asyncio.sleep(_BEDROCK_APPLY_GUARDRAIL_BASE_BACKOFF_SECONDS * (2.0**attempt))
raise HTTPException(status_code=500, detail="Bedrock guardrail throttle retries exhausted")

async def _post_apply_guardrail_content(
Expand Down
16 changes: 13 additions & 3 deletions litellm/proxy/guardrails/guardrail_hooks/xecguard/xecguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from typing import TYPE_CHECKING, Any, Final, Literal, Optional

from fastapi.exceptions import HTTPException
from typing_extensions import ReadOnly, TypedDict, Unpack

from litellm._logging import verbose_proxy_logger
from litellm.integrations.custom_guardrail import (
Expand Down Expand Up @@ -77,6 +78,12 @@ def _sanitize_scan_result_for_logging(scan_result: dict) -> dict:
]


class _CustomGuardrailOptions(TypedDict, total=False, extra_items=object):
"""Base-class constructor options this guardrail forwards untouched to CustomGuardrail."""

supported_event_hooks: ReadOnly[list[GuardrailEventHooks] | None]


class XecGuardMissingCredentials(Exception):
pass

Expand All @@ -90,7 +97,7 @@ def __init__(
policy_names: list[str] | None = None,
block_on_error: bool | None = None,
grounding_strictness: str | None = None,
**kwargs: Any,
**kwargs: Unpack[_CustomGuardrailOptions],
) -> None:
self.api_key = api_key or os.environ.get("XECGUARD_API_KEY")
if not self.api_key:
Expand Down Expand Up @@ -122,9 +129,12 @@ def __init__(
llm_provider=httpxSpecialProvider.GuardrailCallback,
)

kwargs.setdefault("supported_event_hooks", list(self.get_supported_event_hooks()))
options: Final[_CustomGuardrailOptions] = {
"supported_event_hooks": list(self.get_supported_event_hooks()),
**kwargs,
}

super().__init__(**kwargs)
super().__init__(**options)

@staticmethod
def get_config_model() -> type["GuardrailConfigModel"] | None:
Expand Down
2 changes: 1 addition & 1 deletion litellm/proxy/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3598,7 +3598,7 @@ async def _get_source_cache_base_spend(
) -> float:
source_cache_keys: Final = [source_cache_key] if isinstance(source_cache_key, str) else source_cache_key
for cache_key in source_cache_keys:
source = await user_api_key_cache.async_get_cache(key=cache_key)
source: object = await user_api_key_cache.async_get_cache(key=cache_key)
if source is None:
continue
if isinstance(source, dict):
Expand Down
2 changes: 1 addition & 1 deletion litellm/responses/mcp/litellm_proxy_mcp_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _should_use_litellm_mcp_gateway(tools: Iterable[ToolParam] | None) -> bool:
def _parse_mcp_tools(tools: Iterable[Mapping[str, object]] | None) -> SplitTools:
items: Final = tuple(tools or ())
gateway_tools: Final[list[ToolParam]] = [tool for tool in items if _names_gateway_explicitly(tool)]
other_tools: Final[list[Any]] = [tool for tool in items if not _names_gateway_explicitly(tool)]
other_tools: Final[list[ToolParam]] = [tool for tool in items if not _names_gateway_explicitly(tool)]
return gateway_tools, other_tools

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ async def _classify_with_llm(
self,
prompt: str,
system_prompt: str | None = None,
request_kwargs: dict[str, Any] | None = None,
request_kwargs: Mapping[str, object] | None = None,
messages: Sequence[Mapping[str, object]] | None = None,
) -> tuple[ComplexityTier | str, float | None]:
"""
Expand Down
Loading