mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
refactor(guardrails): generalize _to_dict to any pydantic model
Addresses PR review: _to_dict special-cased LitellmParams and returned an empty dict for any other pydantic model. Switch to isinstance(value, BaseModel) so it coerces any pydantic model uniformly (BaseModel is already imported for the response models), which also drops the now-unused LitellmParams import. Behavior is unchanged for the current call sites.
This commit is contained in:
parent
799a559871
commit
8b31b200ca
1 changed files with 2 additions and 3 deletions
|
|
@ -20,7 +20,6 @@ from litellm.repositories.table_repositories import (
|
|||
SpendLogGuardrailIndexRepository,
|
||||
SpendLogsRepository,
|
||||
)
|
||||
from litellm.types.guardrails import LitellmParams
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
|
@ -146,8 +145,8 @@ def _get_guardrail_field(g: Any, field: str) -> Any:
|
|||
|
||||
|
||||
def _to_dict(value: Any) -> Dict[str, Any]:
|
||||
"""Coerce a LitellmParams / guardrail_info value into a plain dict."""
|
||||
if isinstance(value, LitellmParams):
|
||||
"""Coerce a pydantic model (e.g. LitellmParams) / dict value into a plain dict."""
|
||||
if isinstance(value, BaseModel):
|
||||
return value.model_dump(exclude_none=True)
|
||||
if isinstance(value, dict):
|
||||
return value
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue