fix(ui): allow internal users/team admins to select guardrails when creating keys#22816
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR allows internal users and team admins (roles in
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/_types.py | Adds /guardrails/list and /v2/guardrails/list to internal_user_routes, granting internal users read-only access to the guardrails list — appropriate for their key management capabilities. |
| ui/litellm-dashboard/src/components/networking.tsx | Refactors getGuardrailsList to try the v2 endpoint first and fall back to v1 if it fails. Clean error handling with proper fallback chain. |
| ui/litellm-dashboard/src/components/organisms/create_key_button.tsx | Introduces canEditGuardrails for guardrails/disable-global-guardrails controls. However, the Prompts and Policies selectors remain gated on premiumUser only, creating an inconsistency. |
| ui/litellm-dashboard/src/components/templates/key_edit_view.tsx | Same canEditGuardrails pattern applied to guardrails selector and switch. Prompts selector (line 508) and PolicySelector (line 485) are still only gated on premiumUser, which is inconsistent with the guardrails changes. |
| ui/litellm-dashboard/src/components/templates/key_info_view.tsx | Adds canEditGuardrails to guard both the handleKeyUpdate deletion logic and passes premiumUser down to KeyEditView (which re-computes the same flag). Logic is correct. |
| ui/litellm-dashboard/src/components/templates/KeyInfoView.handleKeyUpdate.test.tsx | Good test coverage: tests role-based guardrails access for non-premium viewers (stripped), non-premium admins (preserved), and premium users (preserved). Adds a necessary mock for useResetKeySpend. |
| ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx | Test description updated to match new behavior. Minimal change, correct. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User opens Key Create/Edit] --> B{Check canEditGuardrails}
B -->|premiumUser = true| C[Guardrails enabled]
B -->|role in rolesWithWriteAccess| C
B -->|Neither| D[Guardrails disabled]
C --> E[UI: Guardrails selector enabled]
C --> F[UI: Disable global guardrails switch enabled]
D --> G[UI: Guardrails selector disabled]
D --> H[UI: Disable global guardrails switch disabled]
E --> I[handleKeyUpdate]
F --> I
G --> I
H --> I
I --> J{canEditGuardrails?}
J -->|Yes| K[Preserve guardrails & prompts in payload]
J -->|No| L[Delete guardrails & prompts from payload]
K --> M[API Call: keyUpdateCall]
L --> M
M --> N{v2/guardrails/list}
N -->|Success| O[Return guardrails]
N -->|Fail| P{v1/guardrails/list fallback}
P -->|Success| O
P -->|Fail| Q[Throw error]
Last reviewed commit: 8da9491
Additional Comments (2)
The guardrails selector and the "disable global guardrails" switch both use The same inconsistency exists for the PolicySelector at line 485 (
Same inconsistency as in |
fix(ui): allow internal users/team admins to select guardrails when creating keys
Pre-Submission checklist
tests/test_litellm/directorymake test-unitCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🐛 Bug Fix
Changes
litellm/proxy/_types.py- add/guardrails/listand/v2/guardrails/listtointernal_user_routesso internal users can fetch guardrailsnetworking.tsx- fetch guardrails with v2→v1 fallbackcreate_key_button.tsx- show guardrails selector for internal users / team admins (not just premium users)key_edit_view.tsx- same role-based access for key editingkey_info_view.tsx- passcanEditGuardrailsflag down