From 240afd4724da82f23afcc3a79e9297f6dd1d3e78 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Wed, 24 Jun 2026 16:21:57 +0530 Subject: [PATCH] fix(lint): fix remaining PLR0913 (too-many-args) violations - Extract highest_risk_percentage from response_payload in _log_guardrail_result instead of passing as a param - Introduce DataSourceConfig dataclass to bundle name/enabled/priority for URLDataSource, VectorStoreDataSource, FactCheckDataSource Co-Authored-By: Claude Sonnet 4.6 --- .../bias_hallucination_estimator.py | 11 ++++-- .../data_sources.py | 34 ++++++++++++------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/bias_hallucination_estimator/bias_hallucination_estimator.py b/litellm/proxy/guardrails/guardrail_hooks/bias_hallucination_estimator/bias_hallucination_estimator.py index 15467d3476b..1cfd50f47c8 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/bias_hallucination_estimator/bias_hallucination_estimator.py +++ b/litellm/proxy/guardrails/guardrail_hooks/bias_hallucination_estimator/bias_hallucination_estimator.py @@ -192,7 +192,6 @@ class BiasHallucinationEstimatorGuardrail(CustomGuardrail): response_payload=response_payload, status=status, start_time=start_time, - highest_risk_percentage=highest_risk.risk.overall_risk_percentage, ) if decision == "blocked": @@ -276,8 +275,16 @@ class BiasHallucinationEstimatorGuardrail(CustomGuardrail): response_payload: dict[str, object], status: GuardrailStatus, start_time: datetime, - highest_risk_percentage: int, ) -> None: + risk_scores = response_payload.get("risk_scores") or [] + highest_risk_percentage: int = max( + ( + int(r["overall_risk_percentage"]) # type: ignore[index] + for r in risk_scores + if isinstance(r, dict) and "overall_risk_percentage" in r + ), + default=0, + ) detection_methods = self._detection_methods(response_payload) tracing_detail = GuardrailTracingDetail( guardrail_id=self.guardrail_id or self.guardrail_name, diff --git a/litellm/proxy/guardrails/guardrail_hooks/bias_hallucination_estimator/data_sources.py b/litellm/proxy/guardrails/guardrail_hooks/bias_hallucination_estimator/data_sources.py index eaf00ea793e..5249b7fddd3 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/bias_hallucination_estimator/data_sources.py +++ b/litellm/proxy/guardrails/guardrail_hooks/bias_hallucination_estimator/data_sources.py @@ -10,6 +10,15 @@ from pathlib import Path from typing import Any, cast +@dataclass +class DataSourceConfig: + """Common configuration shared by all DataSource subclasses.""" + + name: str = "" + enabled: bool = True + priority: int = 0 + + @dataclass class FetchConfig: """HTTP fetch settings for URL-backed data sources.""" @@ -162,12 +171,11 @@ class URLDataSource(DataSource): def __init__( self, urls: list[str], - name: str = "url_source", - enabled: bool = True, - priority: int = 0, + source_config: DataSourceConfig | None = None, fetch_config: FetchConfig | None = None, ) -> None: - super().__init__(name=name, enabled=enabled, priority=priority) + _sc = source_config or DataSourceConfig(name="url_source") + super().__init__(name=_sc.name, enabled=_sc.enabled, priority=_sc.priority) self.urls = urls _fetch = fetch_config or FetchConfig() self.cache_ttl = _fetch.cache_ttl @@ -241,14 +249,15 @@ class VectorStoreDataSource(DataSource): def __init__( self, provider: str, - name: str = "", - enabled: bool = True, - priority: int = 0, + source_config: DataSourceConfig | None = None, client_config: VectorStoreClientConfig | None = None, **config: str, ) -> None: + _sc = source_config or DataSourceConfig() super().__init__( - name=name or f"vectorstore_{provider}", enabled=enabled, priority=priority + name=_sc.name or f"vectorstore_{provider}", + enabled=_sc.enabled, + priority=_sc.priority, ) self.provider = provider self.config = config @@ -403,14 +412,15 @@ class FactCheckDataSource(DataSource): def __init__( self, provider: str = "snopes", - name: str = "", - enabled: bool = True, - priority: int = 0, + source_config: DataSourceConfig | None = None, api_key: str | None = None, **config: str, ) -> None: + _sc = source_config or DataSourceConfig() super().__init__( - name=name or f"factcheck_{provider}", enabled=enabled, priority=priority + name=_sc.name or f"factcheck_{provider}", + enabled=_sc.enabled, + priority=_sc.priority, ) self.provider = provider self.api_key = api_key