diff options
author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
---|---|---|
committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/litellm/proxy/guardrails/guardrail_endpoints.py | |
parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
download | gn-ai-4a52a71956a8d46fcb7294ac71734504bb09bcc2.tar.gz |
Diffstat (limited to '.venv/lib/python3.12/site-packages/litellm/proxy/guardrails/guardrail_endpoints.py')
-rw-r--r-- | .venv/lib/python3.12/site-packages/litellm/proxy/guardrails/guardrail_endpoints.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/litellm/proxy/guardrails/guardrail_endpoints.py b/.venv/lib/python3.12/site-packages/litellm/proxy/guardrails/guardrail_endpoints.py new file mode 100644 index 00000000..7407d6fb --- /dev/null +++ b/.venv/lib/python3.12/site-packages/litellm/proxy/guardrails/guardrail_endpoints.py @@ -0,0 +1,85 @@ +""" +CRUD ENDPOINTS FOR GUARDRAILS +""" + +from typing import Dict, List, Optional, cast + +from fastapi import APIRouter, Depends + +from litellm.proxy.auth.user_api_key_auth import user_api_key_auth +from litellm.types.guardrails import GuardrailInfoResponse, ListGuardrailsResponse + +#### GUARDRAILS ENDPOINTS #### + +router = APIRouter() + + +def _get_guardrails_list_response( + guardrails_config: List[Dict], +) -> ListGuardrailsResponse: + """ + Helper function to get the guardrails list response + """ + guardrail_configs: List[GuardrailInfoResponse] = [] + for guardrail in guardrails_config: + guardrail_configs.append( + GuardrailInfoResponse( + guardrail_name=guardrail.get("guardrail_name"), + litellm_params=guardrail.get("litellm_params"), + guardrail_info=guardrail.get("guardrail_info"), + ) + ) + return ListGuardrailsResponse(guardrails=guardrail_configs) + + +@router.get( + "/guardrails/list", + tags=["Guardrails"], + dependencies=[Depends(user_api_key_auth)], + response_model=ListGuardrailsResponse, +) +async def list_guardrails(): + """ + List the guardrails that are available on the proxy server + + 👉 [Guardrail docs](https://docs.litellm.ai/docs/proxy/guardrails/quick_start) + + Example Request: + ```bash + curl -X GET "http://localhost:4000/guardrails/list" -H "Authorization: Bearer <your_api_key>" + ``` + + Example Response: + ```json + { + "guardrails": [ + { + "guardrail_name": "bedrock-pre-guard", + "guardrail_info": { + "params": [ + { + "name": "toxicity_score", + "type": "float", + "description": "Score between 0-1 indicating content toxicity level" + }, + { + "name": "pii_detection", + "type": "boolean" + } + ] + } + } + ] + } + ``` + """ + from litellm.proxy.proxy_server import proxy_config + + config = proxy_config.config + + _guardrails_config = cast(Optional[list[dict]], config.get("guardrails")) + + if _guardrails_config is None: + return _get_guardrails_list_response([]) + + return _get_guardrails_list_response(_guardrails_config) |