The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(ui): keep Back to Guardrails reachable when a ?guardrail= link is stale
ryan-crabbe-berriee5d66d03082
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsxindex fcffc2122e7..836921104ff 100644--- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx+++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx@@ -338,3 +338,27 @@ describe("Guardrail Info", () => {expect(screen.getByText("Guardrail Settings")).toBeInTheDocument();});});++describe("Guardrail Info when the guardrail cannot be loaded", () => {+ afterEach(() => {+ vi.clearAllMocks();+ });++ it("should keep Back to Guardrails reachable so a stale ?guardrail= link is not a dead end", async () => {+ vi.mocked(networking.getGuardrailInfo).mockRejectedValue(new Error("Guardrail stale-id not found"));+ vi.mocked(networking.getGuardrailUISettings).mockResolvedValue({+ supported_entities: [],+ supported_actions: [],+ pii_entity_categories: [],+ supported_modes: [],+ });+ vi.mocked(networking.getGuardrailProviderSpecificParams).mockResolvedValue({});+ const onClose = vi.fn();++ render(<GuardrailInfoView guardrailId="stale-id" onClose={onClose} accessToken="123" isAdmin={true} />);++ expect(await screen.findByText("Guardrail not found")).toBeInTheDocument();+ fireEvent.click(screen.getByRole("button", { name: /back to guardrails/i }));+ expect(onClose).toHaveBeenCalledTimes(1);+ });+});diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.tsx b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.tsxindex aaa656d15bb..c9162d99934 100644--- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.tsx+++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.tsx@@ -481,16 +481,18 @@ const GuardrailInfoView: React.FC<GuardrailInfoProps> = ({ guardrailId, onClose,return <div className="p-4">Loading...</div>;}+ const backButton = (+ <Button variant="ghost" onClick={onClose} className="mb-4">+ <ArrowLeft className="w-4 h-4" />+ Back to Guardrails+ </Button>+ );+if (!guardrailData) {- return <div className="p-4">Guardrail not found</div>;+ return <div className="p-4">{backButton}Guardrail not found</div>;}- // Format date helper function- const formatDate = (dateString?: string) => {- if (!dateString) return "-";- const date = new Date(dateString);- return date.toLocaleString();- };+ const formatDate = (dateString?: string) => (dateString ? new Date(dateString).toLocaleString() : "-");// Format the provider display name and logoconst { logo, displayName } = getGuardrailLogoAndName(guardrailData.litellm_params?.guardrail || "");@@ -510,10 +512,7 @@ const GuardrailInfoView: React.FC<GuardrailInfoProps> = ({ guardrailId, onClose,return (<div className="p-4"><div>- <Button variant="ghost" onClick={onClose} className="mb-4">- <ArrowLeft className="w-4 h-4" />- Back to Guardrails- </Button>+ {backButton}<h1 className="text-2xl font-semibold">{guardrailData.guardrail_name || "Unnamed Guardrail"}</h1><div className="flex items-center cursor-pointer"><p className="text-muted-foreground font-mono">{guardrailData.guardrail_id}</p>