From e4f59a953cac0543515449d8485a94e7393c2636 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sat, 12 Sep 2026 10:04:55 -0700 Subject: [PATCH] feat(guardrails): add Conduct Guard integration with validated hooks and forwarded params (#40785) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(guardrails): add ConductGuard integration Adds Conduct Guard as a first-class LiteLLM guardrail. Point any LiteLLM proxy at Conduct and every LLM call routed through it is policy-checked before the upstream request goes out — block, warn, audit, or trigger a human-in-the-loop approval, with the same signed configuration + hash-chained audit log Conduct exposes on its native enforcement surfaces. - litellm/types/guardrails.py: add CONDUCT to SupportedGuardrailIntegrations. - litellm/proxy/guardrails/guardrail_hooks/conduct/__init__.py: registration via guardrail_initializer_registry and guardrail_class_registry, picked up by the auto-discovery in guardrail_registry.py. - litellm/proxy/guardrails/guardrail_hooks/conduct/conduct.py: the adapter. CustomGuardrail subclass, async_pre_call_hook, response envelope parser for the five Conduct verdicts (ok / advisory / WARNING / BLOCKED / PENDING approval), fail-mode logic, session-ID resolution chain (litellm_metadata.trace_id → X-Conduct-Session-Id → hash fallback). - tests/test_litellm/proxy/guardrails/test_conduct_guardrail.py: envelope parsing, pre-call allow/block/approval, config precedence, missing-token construction error. ```yaml guardrails: - guardrail_name: conduct-guard litellm_params: guardrail: conduct mode: pre_call api_base: https://api.conductai.ai # optional, default api_key: os.environ/CONDUCT_AGENT_TOKEN # cond_agt_* token fail_mode: fail_closed # or fail_open tool_name: llm_call # scoped tool_name ``` A standalone PyPI package `conduct-litellm-guard` shipped ahead of this PR for teams pinned to older LiteLLM versions. Once this integration merges, the standalone README will point at the native support as the preferred path. - PyPI: https://pypi.org/project/conduct-litellm-guard/ - Product: https://conductai.ai/guard Contact: sudhi@b2bsphere.com * chore: ruff format for conduct guardrail Fixes lint check on the upstream PR. * chore: fix ruff lint errors - Remove unused TYPE_CHECKING import (F401). - Un-quote self-forward-ref type annotation (UP037). - Suppress BLE001 on transport-fallback broad-except (intentional). * chore: drop typing.Any to satisfy strict-rule budget BerriAI's ruff strict-rule budget caps ANN401 (Any type annotation) and TID251 (banned import) totals. Aligning with the CustomLogger base signature (data: dict, cache: object, **kwargs untyped) eliminates all Any uses in the module. Local tests still pass 15/15. * chore: annotate **kwargs to satisfy ANN003 strict rule Removing 'Any' in the prior commit left **kwargs untyped, which tripped ANN003 (missing type annotation on **kwargs). Using 'object' threads the strict-rule budget cleanly. * refactor: slim upstream adapter — import from conduct-litellm-guard PyPI The full adapter (response parser, session-ID chain, fail-mode logic, HTTP client) lives in the conduct-litellm-guard package on PyPI. The upstream tree hosts a thin re-export + the LiteLLM registration wiring. Matches the Aporia / Lakera pattern — vendor SDK on PyPI, upstream integration is a tiny adapter. Benefits: - Passes ruff-strict-budget and type-discipline-budget without new violations. - Users get the same install experience as any other guardrail vendor: pip install conduct-litellm-guard - Vendor keeps ownership of the parser + fail-mode semantics; upstream keeps a stable interface. Tests slimmed to smoke coverage (imports work, class is a CustomGuardrail, enum + registries wired, missing-package error path). Full behavioural coverage stays in the PyPI package. Local runs of both scripts/ruff_strict_gate.py and scripts/type_discipline_gate.py against upstream/litellm_internal_staging: both pass. * test(conduct): skip smoke tests when conduct-litellm-guard not installed The wrapper module imports its runtime from the conduct-litellm-guard PyPI package. When the package is not installed in the CI environment, the smoke tests can't verify wiring (the import raises before any test runs). Use pytest.importorskip so BerriAI's default CI env doesn't fail on this integration, while environments that do install the package (via 'pip install conduct-litellm-guard[dev]' or similar) still get the smoke coverage. Full behavioural test coverage lives in the conduct-litellm-guard package's own CI. * test(conduct): cover initialize_guardrail to raise patch coverage Codecov flagged the __init__.initialize_guardrail body as uncovered (30% patch coverage on that file). Added a test that mocks litellm.logging_callback_manager and calls initialize_guardrail with a SimpleNamespace stand-in for LitellmParams — exercises the full function body and confirms the callback is registered. * address review findings on #38143 (yucheng-berri, cursor, veria-ai, devin) Rename fail_mode → unreachable_fallback (typed field) ───────────────────────────────────────────────────── The shim was reading a free-form ``fail_mode`` field; a typo silently defaulted the plugin to fail-open behavior. Switch to the typed ``LitellmParams.unreachable_fallback`` field so Pydantic validates the value at config load. The plugin's constructor kwarg stays as ``fail_mode`` — the initializer maps the typed field onto it. (yucheng-berri, devin-ai-integration) Fix timeout default (was silently discarded) ──────────────────────────────────────────── ``getattr(litellm_params, "timeout", 8.0)`` only applied the default when the attribute was missing; ``LitellmParams.timeout`` always exists and defaults to ``None``, so the intended 8-second budget was never used. Change to ``getattr(..., None) or 8.0`` so ``None`` (and ``0``) fall through to the default. (cursor[bot]) Move ImportError from module-load to __init__ ───────────────────────────────────────────── Raising ImportError at module load caused the guardrail-hook auto-discovery loop to silently drop the registration when ``conduct-litellm-guard`` was missing. Users saw configs load with no guardrail active and no error. Import lazily; raise the friendly ``pip install`` error at ``ConductGuardrail.__init__`` when actionable. (cursor[bot]) Advertise only supported event hooks ──────────────────────────────────── ``during_call`` mode was advertised in the guardrail config but the class never overrode ``async_moderation_hook`` — every request in that mode silently bypassed policy. Override ``get_supported_event_hooks`` to return only ``pre_call`` so LiteLLM validates configs against supported modes at load time. ``during_call`` / ``post_call`` support lands with plugin 0.3.x once the underlying response-gate is wired through ``guard_check_response``. (veria-ai) Text-completion + full-turn prompt scanning ─────────────────────────────────────────── Fixed in the standalone package: ``conduct-litellm-guard 0.2.2`` (BerriAI/litellm PR #38143 companion, shipping to PyPI shortly). Pinned in the docstring here as the minimum supported version. (veria-ai — text_completion bypass + 4KB truncation) Tests ───── * ``test_only_pre_call_event_hook_advertised`` — regression for ``during_call`` silent-bypass finding * ``test_initialize_prefers_typed_unreachable_fallback`` — regression for typo silent-fail-open finding * ``test_initialize_applies_timeout_default_when_field_is_none`` — regression for silently-discarded 8.0 default * ``test_missing_standalone_package_raises_at_construction`` — regression for silent-drop-on-import-failure finding (previous module-load raise replaced with lazy import + init-time raise) * style: ruff format on the conduct guardrail shim + tests Lint job on #38143 flagged three files as needing reformat. No behavior change — just ruff-format's chosen line breaks and quoting. * style: remove redundant noqa on re-exported GuardDecision Ruff lint flagged this as unused because GuardDecision is re-exported via __all__. Removing the noqa satisfies ruff without changing behavior. * style: satisfy strict-rule budget (ANN201, ANN401, TID251) BerriAI/litellm CI's ruff strict-rule budget check flagged four new violations on the conduct shim. Fixes: - __init__.py: add return type annotation on initialize_guardrail (ANN201) - conduct.py: swap Any → object on __init__(*args, **kwargs) so the signature stays permissive without dynamically-typed Any (ANN401) - conduct.py: drop the now-unused Any import (TID251) Ruff --select ANN,TID passes locally. * style: satisfy type-discipline budget (LIT008, LIT009) BerriAI/litellm CI's type-discipline budget check flagged the subclass __init__ shim. Fixes: - Drop the __init__ override entirely — the subclass now inherits __init__ from _BaseConductGuard (when the standalone package is installed) or from CustomGuardrail (fallback). Removes both the banned **kwargs (LIT008) and all four inert # type: ignore markers (LIT009 x 4). - Move the missing-package check into a dedicated raise_if_missing_package() helper called by initialize_guardrail before construction. Preserves the cursor[bot] fix (silent-drop-on-import-failure) without needing a custom __init__. - Fallback branch aliases _BaseConductGuard = CustomGuardrail directly, no type-ignore comment needed. - Test updated to exercise the helper instead of the removed __init__ path; new companion test asserts the helper is a no-op when the package IS installed. Local: ruff --select ANN,TID passes clean. ruff format applied. Same behavioral surface — user-visible error message unchanged. * style: explicit assert on noop test (TQ001 zero-assert budget) BerriAI/litellm CI's test-quality budget flagged test_raise_if_missing_package_is_noop_when_present as a zero-assert test (TQ001). Make the intent explicit: raise_if_missing_package() must return None when the package IS installed. * refactor: shim becomes a pure alias, hooks now on plugin's ConductGuard Plugin conduct-litellm-guard 0.2.3 ships SUPPORTED_EVENT_HOOKS + get_supported_event_hooks on ConductGuard directly. The upstream shim's subclass wrapper is now redundant — dropping it clears every strict-rule budget gate (ruff-strict / test-quality / type-discipline / basedpyright) in one pass. Changes: - conduct.py: subclass removed; ConductGuardrail is now an alias for the plugin's ConductGuard (no dynamic base class, no reassignment, no # type: ignore). raise_if_missing_package helper unchanged. - test file: _IMPORT_ERROR → _import_error rename to satisfy reportConstantRedefinition (basedpyright treats SCREAMING_CASE as constant). Also drops unused sys import. - Pin bumped to conduct-litellm-guard>=0.2.3 in the module docstring. Verified all four LiteLLM gate scripts locally against upstream/litellm_internal_staging: ruff_strict_gate OK test_quality_gate OK type_discipline_gate OK type_check_gate OK * fix: real stub class in the missing-package fallback Runtime regression in the previous simplification — the guardrail registry iterates every registered class at load time and calls get_supported_event_hooks(). Fallback of ConductGuardrail = None crashed the whole registry with AttributeError, which cascaded into unrelated guardrails' tests (noma_v2, repelloai, hide_secrets, provider_specific_params, etc.). Fallback now defines ConductGuardrail as a real subclass of CustomGuardrail with the required class attrs (SUPPORTED_EVENT_HOOKS + get_supported_event_hooks). Matches the pattern the guardrails_ai integration already uses in the same repo. raise_if_missing_package still fires before instantiation so users see the friendly pip install error. All four budget gates re-verified locally against upstream/litellm_internal_staging: ruff_strict_gate OK test_quality_gate OK type_discipline_gate OK type_check_gate OK * style: mutable-ok suppression on registry dicts + hook returns * fix: SUPPORTED_EVENT_HOOKS must be GuardrailEventHooks enum, not str LiteLLM's guardrail registry scans SUPPORTED_EVENT_HOOKS and calls .value on each entry to build the mode allowlist. Plugin 0.2.3 shipped bare strings, which raised AttributeError on three upstream tests (same three as the pre-0.2.3 None-registration failure). - Fallback stub now uses GuardrailEventHooks.pre_call. - Docstring and pip install message updated to >=0.2.4. - Test asserts against the enum member (which is what LiteLLM's registry scan actually sees). Requires plugin conduct-litellm-guard >=0.2.4 (already tagged and publishing). All four budget gates verified locally green: ruff_strict, test_quality, type_discipline, type_check * fix(guardrails): validate Conduct event hooks, forward tool_name, drop optional-package test skip Pass the plugin's supported hook list into CustomGuardrail so unsupported modes (during_call, post_call, logging_only) are rejected at config load instead of silently doing nothing. Forward the configured tool_name to the plugin, and replace the missing-package stub so the registry still discovers the guardrail while construction raises an install hint. The regression tests inject a recording guardrail class so they run without conduct-litellm-guard installed; the previous module-level skip left the adapter untested in CI. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(guardrails): scan Responses API input through the unified Conduct bridge The plugin's native pre_call hook only reads prompt and chat messages, so /v1/responses requests reached Conduct with an empty prompt and were always allowed. ConductGuardrail now implements apply_guardrail, which routes every endpoint through LiteLLM's shared guardrail translation and feeds the translated texts (or structured messages) to the plugin's check() Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(guardrails): log Conduct apply_guardrail decisions via log_guardrail_information Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(guardrails): move the Conduct apply_guardrail bridge into an injectable function The bridge body only ran when conduct-litellm-guard was importable, which CI never is, so codecov/patch reported it uncovered. apply_conduct_guardrail now takes the plugin's check coroutine and blocked-error factory as parameters, so the package-free tests exercise every verdict branch and the plugin-bound class is a one-line delegate Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(guardrails): send tool-call-only turns to Conduct and test registry wiring through config load Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(guardrails): log non-blocking Conduct verdicts in standard guardrail information Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * feat(guardrails): add Conduct config model and Admin UI garden entry Expose ConductGuardrailConfigModel through get_config_model() so /guardrails/ui/provider_specific_params returns the api_key, api_base, workspace_id, tool_name, timeout and unreachable_fallback fields, and add the Conduct Guard partner card, preset and logo to the guardrail garden so the integration can be created from the Admin UI Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(guardrails): pass unreachable_fallback directly to conduct-litellm-guard 0.2.5 The plugin renamed its constructor kwarg from fail_mode to unreachable_fallback in 0.2.5 and kept fail_mode only as a deprecated alias that warns on every init. Forward the new kwarg and bump the documented pin to >=0.2.5. Mirrors 62325467 on #38143 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(guardrails): reject conduct-litellm-guard builds that swallow unreachable_fallback Plugin 0.2.4 accepts **kwargs, so the renamed kwarg was silently dropped and a configured fail_open became fail_closed. Fail at import with the install hint instead Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Sudhi Seshachala Co-authored-by: yucheng Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../guardrail_hooks/conduct/__init__.py | 49 ++ .../guardrail_hooks/conduct/conduct.py | 158 +++++++ litellm/types/guardrails.py | 1 + .../guardrails/guardrail_hooks/conduct.py | 42 ++ .../guardrail_hooks/test_conduct.py | 423 ++++++++++++++++++ .../public/assets/logos/conduct.png | Bin 0 -> 12730 bytes .../_components/guardrail_garden_configs.ts | 6 + .../_components/guardrail_garden_data.test.ts | 1 + .../_components/guardrail_garden_data.ts | 10 + .../_components/guardrail_info_helpers.tsx | 3 + 10 files changed, 693 insertions(+) create mode 100644 litellm/proxy/guardrails/guardrail_hooks/conduct/__init__.py create mode 100644 litellm/proxy/guardrails/guardrail_hooks/conduct/conduct.py create mode 100644 litellm/types/proxy/guardrails/guardrail_hooks/conduct.py create mode 100644 tests/test_litellm/proxy/guardrails/guardrail_hooks/test_conduct.py create mode 100644 ui/litellm-dashboard/public/assets/logos/conduct.png diff --git a/litellm/proxy/guardrails/guardrail_hooks/conduct/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/conduct/__init__.py new file mode 100644 index 00000000000..9eac143be88 --- /dev/null +++ b/litellm/proxy/guardrails/guardrail_hooks/conduct/__init__.py @@ -0,0 +1,49 @@ +from __future__ import annotations + +from collections.abc import Mapping +from types import MappingProxyType +from typing import TYPE_CHECKING, Final + +from litellm.types.guardrails import SupportedGuardrailIntegrations + +from .conduct import ConductGuardrail + +if TYPE_CHECKING: + from litellm.integrations.custom_guardrail import CustomGuardrail + from litellm.types.guardrails import Guardrail, LitellmParams + +DEFAULT_TIMEOUT_SECONDS: Final = 8.0 +_NO_EXTRAS: Final[Mapping[str, object]] = MappingProxyType({}) + + +def initialize_guardrail( + litellm_params: LitellmParams, + guardrail: Guardrail, + guardrail_cls: type[CustomGuardrail] = ConductGuardrail, +) -> CustomGuardrail: + import litellm + + extras: Final = litellm_params.model_extra or _NO_EXTRAS + _callback: Final = guardrail_cls( + api_url=litellm_params.api_base, + agent_token=litellm_params.api_key, + workspace_id=extras.get("workspace_id"), + tool_name=extras.get("tool_name", "llm_call"), + unreachable_fallback=litellm_params.unreachable_fallback, + timeout=DEFAULT_TIMEOUT_SECONDS if litellm_params.timeout is None else litellm_params.timeout, + guardrail_name=guardrail.get("guardrail_name", ""), + event_hook=litellm_params.mode, + default_on=litellm_params.default_on, + supported_event_hooks=guardrail_cls.get_supported_event_hooks(), + ) + litellm.logging_callback_manager.add_litellm_callback(_callback) + return _callback + + +guardrail_initializer_registry: Final = { # mutable-ok: module-level registry, built once and never mutated + SupportedGuardrailIntegrations.CONDUCT.value: initialize_guardrail, +} + +guardrail_class_registry: Final = { # mutable-ok: module-level registry, built once and never mutated + SupportedGuardrailIntegrations.CONDUCT.value: ConductGuardrail, +} diff --git a/litellm/proxy/guardrails/guardrail_hooks/conduct/conduct.py b/litellm/proxy/guardrails/guardrail_hooks/conduct/conduct.py new file mode 100644 index 00000000000..c87f8c016b1 --- /dev/null +++ b/litellm/proxy/guardrails/guardrail_hooks/conduct/conduct.py @@ -0,0 +1,158 @@ +"""Conduct Guard as a LiteLLM guardrail, backed by the ``conduct-litellm-guard`` PyPI package. + +Install: ``pip install "conduct-litellm-guard>=0.2.5"`` +Source: https://github.com/sseshachala/conductai/tree/main/packages/conduct-litellm-guard +""" + +from __future__ import annotations + +import inspect +from collections.abc import Awaitable, Callable, Mapping +from functools import partial +from types import MappingProxyType +from typing import TYPE_CHECKING, Final, Literal, Protocol + +from pydantic import BaseModel, ConfigDict + +from litellm.integrations.custom_guardrail import CustomGuardrail, log_guardrail_information +from litellm.types.llms.openai import ChatCompletionUserMessage +from litellm.types.proxy.guardrails.guardrail_hooks.conduct import ConductGuardrailConfigModel + +if TYPE_CHECKING: + from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj + from litellm.types.utils import GenericGuardrailAPIInputs, GuardrailStatus + +MISSING_PACKAGE_MESSAGE: Final = ( + "conduct-litellm-guard>=0.2.5 is required for the Conduct guardrail. " + 'Install it with: pip install "conduct-litellm-guard>=0.2.5"' +) + +BLOCKING_VERDICTS: Final = frozenset({"block", "approval"}) +FLAGGED_VERDICTS: Final = frozenset({"warning", "advisory"}) + + +class ConductDecision(Protocol): + @property + def verdict(self) -> str: ... + + @property + def rule_id(self) -> str | None: ... + + +class ConductCheck(Protocol): + def __call__(self, *, data: Mapping[str, object], call_type: str) -> Awaitable[ConductDecision]: ... + + +def request_payload( + inputs: GenericGuardrailAPIInputs, + request_data: Mapping[str, object], + input_type: Literal["request", "response"], +) -> Mapping[str, object] | None: + if input_type != "request": + return None + messages: Final = inputs.get("structured_messages") or tuple( + ChatCompletionUserMessage(role="user", content=text) for text in inputs.get("texts") or () + ) + return MappingProxyType({**request_data, "prompt": None, "messages": messages}) + + +def decision_status(decision: ConductDecision) -> GuardrailStatus: + return "guardrail_flagged" if decision.verdict in FLAGGED_VERDICTS else "success" + + +class ConductVerdict(BaseModel): + model_config = ConfigDict(frozen=True) + + verdict: str + rule_id: str | None = None + + +def record_decision( + guardrail: CustomGuardrail, + request_data: dict[str, object], # mutable-ok: the logging helper writes metadata into it + decision: ConductDecision, +) -> None: + guardrail.add_standard_logging_guardrail_information_to_request_data( + guardrail_json_response=ConductVerdict(verdict=decision.verdict, rule_id=decision.rule_id).model_dump(), + request_data=request_data, + guardrail_status=decision_status(decision), + ) + + +async def apply_conduct_guardrail( + inputs: GenericGuardrailAPIInputs, + request_data: Mapping[str, object], + input_type: Literal["request", "response"], + check: ConductCheck, + blocked: Callable[[ConductDecision], Exception], + record: Callable[[ConductDecision], None], +) -> GenericGuardrailAPIInputs: + payload: Final = request_payload(inputs, request_data, input_type) + if payload is None: + return inputs + decision: Final = await check(data=payload, call_type=input_type) + if decision.verdict in BLOCKING_VERDICTS: + raise blocked(decision) + record(decision) + return inputs + + +def binds_unreachable_fallback(guardrail_cls: type[object]) -> bool: + return "unreachable_fallback" in inspect.signature(guardrail_cls.__init__).parameters + + +try: + from conduct_litellm_guard.guardrail import ConductGuard, ConductGuardBlocked + + if not binds_unreachable_fallback(ConductGuard): + raise ImportError(MISSING_PACKAGE_MESSAGE) +except ImportError as import_error: + _import_error: Final = import_error + + class ConductGuardrail(CustomGuardrail): + def __init__(self, **kwargs: object) -> None: # kwargs-ok: mirrors the plugin constructor, only raises + raise ImportError(MISSING_PACKAGE_MESSAGE) from _import_error + + @staticmethod + def get_config_model() -> type[ConductGuardrailConfigModel]: + return ConductGuardrailConfigModel + +else: + + class ConductGuardrail(ConductGuard): # pyright: ignore[reportUntypedBaseClass] # optional dep, absent at type-check + @staticmethod + def get_config_model() -> type[ConductGuardrailConfigModel]: + return ConductGuardrailConfigModel + + @log_guardrail_information + async def apply_guardrail( + self, + inputs: GenericGuardrailAPIInputs, + request_data: dict[str, object], # mutable-ok: CustomGuardrail.apply_guardrail contract + input_type: Literal["request", "response"], + logging_obj: LiteLLMLoggingObj | None = None, + ) -> GenericGuardrailAPIInputs: + return await apply_conduct_guardrail( + inputs, + request_data, + input_type, + self.check, + ConductGuardBlocked, + partial(record_decision, self, request_data), + ) + + +__all__ = ( + "BLOCKING_VERDICTS", + "FLAGGED_VERDICTS", + "MISSING_PACKAGE_MESSAGE", + "ConductCheck", + "ConductDecision", + "ConductGuardrail", + "ConductVerdict", + "apply_conduct_guardrail", + "binds_unreachable_fallback", + "decision_status", + "record_decision", + "request_payload", +) diff --git a/litellm/types/guardrails.py b/litellm/types/guardrails.py index 02dee40f2a3..69cb88bfa2f 100644 --- a/litellm/types/guardrails.py +++ b/litellm/types/guardrails.py @@ -137,6 +137,7 @@ class SupportedGuardrailIntegrations(Enum): COMPRESR = "compresr" STRAIKER = "straiker" ALICE = "alice" + CONDUCT = "conduct" class Role(Enum): diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/conduct.py b/litellm/types/proxy/guardrails/guardrail_hooks/conduct.py new file mode 100644 index 00000000000..fbff4363351 --- /dev/null +++ b/litellm/types/proxy/guardrails/guardrail_hooks/conduct.py @@ -0,0 +1,42 @@ +from __future__ import annotations + +from typing import Literal + +from pydantic import BaseModel, Field + +from .base import GuardrailConfigModel + + +class ConductGuardrailConfigModelOptionalParams(BaseModel): + workspace_id: str | None = Field( + default=None, + description="Conduct workspace id, sent as the X-Workspace-Id header. Env: CONDUCT_WORKSPACE_ID.", + ) + tool_name: str | None = Field( + default="llm_call", + description="Conduct tool name the prompt is evaluated under. Match the tool your rules target.", + ) + timeout: float | None = Field( + default=8.0, + gt=0.0, + description="Timeout in seconds for the Conduct check.", + ) + unreachable_fallback: Literal["fail_open", "fail_closed"] | None = Field( + default="fail_closed", + description="Behavior when Conduct is unreachable, times out, or rejects the token.", + ) + + +class ConductGuardrailConfigModel(GuardrailConfigModel[ConductGuardrailConfigModelOptionalParams]): + api_key: str = Field( + min_length=1, + description="Conduct agent token. Env: CONDUCT_AGENT_TOKEN.", + ) + api_base: str | None = Field( + default="https://api.conductai.ai", + description="Conduct API base URL. The MCP endpoint is derived as /mcp.", + ) + + @staticmethod + def ui_friendly_name() -> str: + return "Conduct Guard" diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_conduct.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_conduct.py new file mode 100644 index 00000000000..323756f8fa0 --- /dev/null +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_conduct.py @@ -0,0 +1,423 @@ +from __future__ import annotations + +import importlib.util +import json +import warnings +from collections.abc import Mapping +from dataclasses import dataclass, field +from typing import Final, Literal + +import httpx +import pytest +import respx +from fastapi import HTTPException + +import litellm +from litellm.integrations.custom_guardrail import CustomGuardrail +from litellm.proxy.guardrails.guardrail_endpoints import get_guardrail_ui_settings, get_provider_specific_params +from litellm.proxy.guardrails.guardrail_hooks.conduct import ( + DEFAULT_TIMEOUT_SECONDS, + ConductGuardrail, + initialize_guardrail, +) +from litellm.proxy.guardrails.guardrail_hooks.conduct.conduct import ( + apply_conduct_guardrail, + binds_unreachable_fallback, + record_decision, + request_payload, +) +from litellm.proxy.guardrails.guardrail_registry import InMemoryGuardrailHandler +from litellm.types.guardrails import Guardrail, GuardrailEventHooks, LitellmParams +from litellm.types.llms.openai import ChatCompletionAssistantMessage +from litellm.types.proxy.guardrails.guardrail_hooks.conduct import ( + ConductGuardrailConfigModel, + ConductGuardrailConfigModelOptionalParams, +) +from litellm.types.utils import GenericGuardrailAPIInputs + +PACKAGE_INSTALLED: Final = importlib.util.find_spec("conduct_litellm_guard") is not None + + +class _RecordingGuardrail(CustomGuardrail): + """Stand-in with the ``conduct_litellm_guard.ConductGuard`` class contract.""" + + @classmethod + def get_supported_event_hooks(cls) -> list[GuardrailEventHooks]: + return [GuardrailEventHooks.pre_call] + + def __init__( + self, + *, + api_url: str | None = None, + agent_token: str | None = None, + workspace_id: str | None = None, + unreachable_fallback: str | None = None, + tool_name: str = "llm_call", + timeout: float = 8.0, + guardrail_name: str | None = None, + event_hook: str | None = None, + default_on: bool = False, + supported_event_hooks: list[GuardrailEventHooks] | None = None, + ) -> None: + super().__init__( + guardrail_name=guardrail_name, + event_hook=event_hook, # pyright: ignore[reportArgumentType] # CustomGuardrail coerces the str at runtime + default_on=default_on, + supported_event_hooks=supported_event_hooks, + ) + self.api_url = api_url + self.agent_token = agent_token + self.workspace_id = workspace_id + self.unreachable_fallback = unreachable_fallback or "fail_closed" + self.tool_name = tool_name + self.timeout = timeout + + +@dataclass(frozen=True, slots=True) +class _Decision: + verdict: str + rule_id: str | None = None + + +class _Blocked(Exception): + def __init__(self, decision: _Decision) -> None: + super().__init__(decision.verdict) + self.decision = decision + + +@dataclass(slots=True) +class _RecordingCheck: + verdict: str + rule_id: str | None = None + calls: list[tuple[Mapping[str, object], str]] = field(default_factory=list) # mutable-ok: test spy + recorded: list[_Decision] = field(default_factory=list) # mutable-ok: test spy + + async def __call__(self, *, data: Mapping[str, object], call_type: str) -> _Decision: + self.calls.append((data, call_type)) + return _Decision(self.verdict, self.rule_id) + + def record(self, decision: _Decision) -> None: + self.recorded.append(decision) + + +async def _bridge( + check: _RecordingCheck, + inputs: GenericGuardrailAPIInputs, + request_data: Mapping[str, object], + input_type: Literal["request", "response"], +) -> GenericGuardrailAPIInputs: + return await apply_conduct_guardrail(inputs, request_data, input_type, check, _Blocked, check.record) + + +def _guardrail_records(request_data: Mapping[str, object]) -> list[tuple[str, object]]: + metadata: Final = request_data["metadata"] + assert isinstance(metadata, dict) + records: Final = metadata["standard_logging_guardrail_information"] + assert isinstance(records, list) + return [(record["guardrail_status"], record["guardrail_response"]) for record in records] + + +def _params(mode: str = "pre_call", **extras: object) -> LitellmParams: + return LitellmParams(guardrail="conduct", mode=mode, api_key="cond_agt_test", **extras) + + +def _guardrail(litellm_params: LitellmParams) -> Guardrail: + return Guardrail(guardrail_name="conduct-guard", litellm_params=litellm_params) + + +def _init(litellm_params: LitellmParams) -> _RecordingGuardrail: + callback: Final = initialize_guardrail( + litellm_params, _guardrail(litellm_params), guardrail_cls=_RecordingGuardrail + ) + assert isinstance(callback, _RecordingGuardrail) + return callback + + +@pytest.fixture(autouse=True) +def _isolate_callbacks(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr(litellm, "callbacks", []) + + +def test_maps_typed_fields_and_extras_onto_plugin_kwargs() -> None: + callback: Final = _init( + _params( + api_base="https://guard.example.test", + unreachable_fallback="fail_open", + timeout="3", + workspace_id="ws_123", + tool_name="workflow", + default_on=True, + ) + ) + + assert callback.api_url == "https://guard.example.test" + assert callback.agent_token == "cond_agt_test" + assert callback.unreachable_fallback == "fail_open" + assert callback.timeout == 3.0 + assert callback.workspace_id == "ws_123" + assert callback.tool_name == "workflow" + assert callback.guardrail_name == "conduct-guard" + assert callback.event_hook == "pre_call" + assert callback.default_on is True + assert litellm.callbacks == [callback] + + +def test_defaults_when_optional_config_is_omitted() -> None: + callback: Final = _init(_params()) + + assert callback.unreachable_fallback == "fail_closed" + assert callback.timeout == DEFAULT_TIMEOUT_SECONDS + assert callback.workspace_id is None + assert callback.tool_name == "llm_call" + + +def test_ui_form_defaults_match_what_the_initializer_forwards() -> None: + optional: Final = ConductGuardrailConfigModelOptionalParams() + model: Final = ConductGuardrailConfigModel(api_key="cond_agt_test") + callback: Final = _init( + _params(**{**model.model_dump(exclude={"api_key", "optional_params"}), **optional.model_dump()}) + ) + + assert callback.api_url == model.api_base + assert callback.unreachable_fallback == optional.unreachable_fallback + assert callback.timeout == optional.timeout + assert callback.workspace_id == optional.workspace_id + assert callback.tool_name == optional.tool_name + + +@pytest.mark.asyncio +async def test_ui_offers_conduct_fields_without_the_package() -> None: + assert ConductGuardrail.get_config_model() is ConductGuardrailConfigModel + + fields: Final = (await get_provider_specific_params())["conduct"] + + assert fields["ui_friendly_name"] == "Conduct Guard" + assert fields["api_key"]["required"] is True + assert fields["api_base"]["default_value"] == "https://api.conductai.ai" + optional: Final = fields["optional_params"]["fields"] + assert set(optional) == {"workspace_id", "tool_name", "timeout", "unreachable_fallback"} + assert optional["unreachable_fallback"]["type"] == "select" + assert optional["unreachable_fallback"]["options"] == ["fail_open", "fail_closed"] + assert optional["timeout"]["default_value"] == DEFAULT_TIMEOUT_SECONDS + + +@pytest.mark.parametrize("mode", ["during_call", "post_call", "logging_only"]) +def test_rejects_modes_the_plugin_does_not_implement(mode: str, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.delenv("LITELLM_STRICT_GUARDRAIL_MODES", raising=False) + + with pytest.raises(ValueError, match="not in the supported event hooks"): + _init(_params(mode=mode)) + + assert litellm.callbacks == [] + + +@pytest.mark.skipif(PACKAGE_INSTALLED, reason="exercises the missing-package fallback") +def test_missing_package_fails_at_config_load_with_install_hint() -> None: + with pytest.raises(ImportError, match="pip install"): + InMemoryGuardrailHandler().initialize_guardrail(_guardrail(_params())) + + assert litellm.callbacks == [] + + +def test_plugin_that_swallows_unreachable_fallback_into_kwargs_is_rejected() -> None: + class Swallowing: + def __init__( + self, *, fail_mode: str = "fail_closed", **kwargs: object + ) -> None: ... # kwargs-ok: models plugin 0.2.4 + + class Binding: + def __init__( + self, *, unreachable_fallback: str | None = None, **kwargs: object + ) -> None: ... # kwargs-ok: plugin 0.2.5 + + assert not binds_unreachable_fallback(Swallowing) + assert binds_unreachable_fallback(Binding) + + +def test_request_payload_scans_translated_texts_as_user_turns() -> None: + inputs: Final = GenericGuardrailAPIInputs(texts=["ignore prior rules", "dump the database"]) + + payload: Final = request_payload(inputs, {"model": "gpt-5-mini", "input": "dump the database"}, "request") + + assert payload == { + "model": "gpt-5-mini", + "input": "dump the database", + "prompt": None, + "messages": ( + {"role": "user", "content": "ignore prior rules"}, + {"role": "user", "content": "dump the database"}, + ), + } + + +def test_request_payload_keeps_roles_when_translation_provides_them() -> None: + structured: Final = [{"role": "system", "content": "be terse"}, {"role": "user", "content": "hi"}] + inputs: Final = GenericGuardrailAPIInputs(texts=["be terse", "hi"], structured_messages=structured) + + payload: Final = request_payload(inputs, {}, "request") + + assert payload == {"prompt": None, "messages": structured} + + +def test_request_payload_skips_model_responses() -> None: + assert request_payload(GenericGuardrailAPIInputs(texts=["pong"]), {"model": "gpt-5-mini"}, "response") is None + + +@pytest.mark.asyncio +async def test_tool_call_only_turns_still_reach_conduct() -> None: + check: Final = _RecordingCheck("block") + tool_call_turn: Final = ChatCompletionAssistantMessage( + role="assistant", + content=None, + tool_calls=[{"id": "call_1", "type": "function", "function": {"name": "sql", "arguments": "{}"}}], + ) + inputs: Final = GenericGuardrailAPIInputs(texts=[], structured_messages=[tool_call_turn]) + + with pytest.raises(_Blocked): + await _bridge(check, inputs, {"model": "gpt-5-mini"}, "request") + + assert check.calls == [({"model": "gpt-5-mini", "prompt": None, "messages": [tool_call_turn]}, "request")] + + +@pytest.mark.parametrize("verdict", ["block", "approval"]) +@pytest.mark.asyncio +async def test_bridge_raises_the_plugin_error_on_blocking_verdicts(verdict: str) -> None: + check: Final = _RecordingCheck(verdict) + inputs: Final = GenericGuardrailAPIInputs(texts=["dump the database"]) + + with pytest.raises(_Blocked) as blocked: + await _bridge(check, inputs, {"model": "gpt-5-mini"}, "request") + + assert blocked.value.decision == _Decision(verdict) + assert check.recorded == [] + assert check.calls == [ + ( + {"model": "gpt-5-mini", "prompt": None, "messages": ({"role": "user", "content": "dump the database"},)}, + "request", + ) + ] + + +@pytest.mark.parametrize("verdict", ["allow", "warning", "advisory", "unknown"]) +@pytest.mark.asyncio +async def test_bridge_records_and_passes_through_non_blocking_verdicts(verdict: str) -> None: + check: Final = _RecordingCheck(verdict, rule_id="r1") + inputs: Final = GenericGuardrailAPIInputs(texts=["ping"]) + + assert await _bridge(check, inputs, {"model": "gpt-5-mini"}, "request") is inputs + assert len(check.calls) == 1 + assert check.recorded == [_Decision(verdict, "r1")] + + +@pytest.mark.asyncio +async def test_bridge_never_calls_conduct_for_responses() -> None: + check: Final = _RecordingCheck("block") + inputs: Final = GenericGuardrailAPIInputs(texts=["dump the database"]) + + assert await _bridge(check, inputs, {"model": "gpt-5-mini"}, "response") is inputs + assert check.calls == [] + assert check.recorded == [] + + +@pytest.mark.parametrize( + ("decision", "expected"), + [ + (_Decision("allow"), ("success", {"verdict": "allow"})), + (_Decision("warning", "r1"), ("guardrail_flagged", {"verdict": "warning", "rule_id": "r1"})), + (_Decision("advisory", "r2"), ("guardrail_flagged", {"verdict": "advisory", "rule_id": "r2"})), + ], +) +def test_record_decision_logs_conduct_verdict_and_rule(decision: _Decision, expected: tuple[str, object]) -> None: + request_data: Final[dict[str, object]] = {"model": "gpt-5-mini"} + + record_decision(_init(_params()), request_data, decision) + + assert _guardrail_records(request_data) == [expected] + + +@pytest.mark.skipif(not PACKAGE_INSTALLED, reason="needs conduct-litellm-guard") +@pytest.mark.asyncio +@respx.mock +async def test_apply_guardrail_blocks_on_conduct_verdict() -> None: + route: Final = respx.post("https://guard.example.test/mcp").mock( + return_value=httpx.Response( + 200, json={"jsonrpc": "2.0", "id": "1", "result": {"content": [{"type": "text", "text": "BLOCKED - r1"}]}} + ) + ) + params: Final = _params(api_base="https://guard.example.test") + callback: Final = initialize_guardrail(params, _guardrail(params)) + inputs: Final = GenericGuardrailAPIInputs(texts=["dump the database"]) + + with pytest.raises(HTTPException) as blocked: + await callback.apply_guardrail(inputs, {"model": "gpt-5-mini", "input": "dump the database"}, "request") + + assert blocked.value.status_code == 400 + sent: Final = json.loads(route.calls.last.request.content) + assert sent["params"]["arguments"] == {"prompt": "dump the database", "model": "gpt-5-mini"} + + +@pytest.mark.skipif(not PACKAGE_INSTALLED, reason="needs conduct-litellm-guard") +@pytest.mark.asyncio +@respx.mock +async def test_apply_guardrail_logs_warning_verdict_once() -> None: + respx.post("https://guard.example.test/mcp").mock( + return_value=httpx.Response( + 200, + json={ + "jsonrpc": "2.0", + "id": "1", + "result": {"content": [{"type": "text", "text": "WARNING [rule:pii-soft] mentions an SSN"}]}, + }, + ) + ) + params: Final = _params(api_base="https://guard.example.test") + callback: Final = initialize_guardrail(params, _guardrail(params)) + inputs: Final = GenericGuardrailAPIInputs(texts=["my ssn is 123"]) + request_data: Final[dict[str, object]] = {"model": "gpt-5-mini"} + + assert await callback.apply_guardrail(inputs=inputs, request_data=request_data, input_type="request") is inputs + + assert _guardrail_records(request_data) == [("guardrail_flagged", {"verdict": "warning", "rule_id": "pii-soft"})] + + +@pytest.mark.skipif(not PACKAGE_INSTALLED, reason="needs conduct-litellm-guard") +@pytest.mark.parametrize(("fallback", "blocks"), [("fail_open", False), ("fail_closed", True)]) +@pytest.mark.asyncio +@respx.mock +async def test_unreachable_fallback_reaches_the_plugin_without_its_deprecated_kwarg( + fallback: str, blocks: bool +) -> None: + respx.post("https://guard.example.test/mcp").mock(side_effect=httpx.ConnectError("refused")) + params: Final = _params(api_base="https://guard.example.test", unreachable_fallback=fallback) + inputs: Final = GenericGuardrailAPIInputs(texts=["ping"]) + + with warnings.catch_warnings(): + warnings.simplefilter("error", DeprecationWarning) + callback: Final = initialize_guardrail(params, _guardrail(params)) + + if blocks: + with pytest.raises(HTTPException): + await callback.apply_guardrail(inputs, {"model": "gpt-5-mini"}, "request") + return + assert await callback.apply_guardrail(inputs, {"model": "gpt-5-mini"}, "request") is inputs + + +@pytest.mark.skipif(not PACKAGE_INSTALLED, reason="needs conduct-litellm-guard") +def test_config_loads_conduct_and_rejects_modes_the_plugin_lacks() -> None: + handler: Final = InMemoryGuardrailHandler() + + loaded: Final = handler.initialize_guardrail(_guardrail(_params())) + assert loaded is not None + assert loaded["litellm_params"].guardrail == "conduct" + assert [type(callback) for callback in litellm.callbacks] == [ConductGuardrail] + + with pytest.raises(ValueError, match="not in the supported event hooks"): + handler.initialize_guardrail(_guardrail(_params(mode="during_call"))) + + +@pytest.mark.skipif(not PACKAGE_INSTALLED, reason="needs conduct-litellm-guard") +@pytest.mark.asyncio +async def test_ui_only_offers_pre_call_for_conduct() -> None: + settings: Final = await get_guardrail_ui_settings() + + assert settings.supported_modes_by_provider["conduct"] == ["pre_call"] diff --git a/ui/litellm-dashboard/public/assets/logos/conduct.png b/ui/litellm-dashboard/public/assets/logos/conduct.png new file mode 100644 index 0000000000000000000000000000000000000000..e68b32df916f7957627f1b34fc319eaf24952225 GIT binary patch literal 12730 zcmV;rF-6XaP)-Fk1; zIp;kII5ZB8L*vjmG!BhJV_yaxT7rXb)LqqFYfR-dB{M1bP{B5|0kk}orKQWhGNSDe zp#LCa#yqvFI=8>ki++HNc_RU11Zs%X0lJ1%{-i;FxaQ6gPXnZf06o~j>}vhL0^CG~ zr!z4K3WavV%r1YO@FWObrvJ(;a#NC1cdEtQK!$*2Gn z#+bA?|HiG!5kCU3aX3qtvO}f<2#*I*}}mgGMYBvNdStxpA}C-;?Il11oN= zZ9N2G`B26v1rLYnE;UyLK$QO*<jq`Q!(8I;Lz# z=7FU$t(CfWXnx14stwkgem`rV%)Rlu7<9D1#~lxs|lhC6oPxoe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ZX5 zM$YcTX7){J#ETQ0D1rbeR_h-0X@E;8Yv_tqY_b^d;c<)o?o59x`+YQ6WL zv(`2cdZnfiU?W@OljPsJYTDPK<%I9$mB#}={$a@HAs62J8dd*65S=X~b*!2qhBekO zM`>_+7{K<~$lyb3?>_#y{kMl^q|+F7IUBmcMz$8cGg36qWs6T16Pb%UR{Z*J|DZc` zu!qu+^MCgy(Qp$ny^*ak`9gttYf+RSNfz*1p`i9o(@zPjO^dSG#tXlf3Oa@;eB4^D zDBT4LfY~5`C$q{l00#x2e9-UAxBljMf!<7(Ph-o5N_vwP^GZ|+8WM!0>jdA?c_}XZ z_0awS^|#w|KKEts-G7H50VU1(iu5)SDTwr7S+9c{(At?lt`Vh=!0_wxR)p@tn5BXS z8dWgSdn*yn?zc&-ePE3$EzsZ}3KGy0o|yNylIn}FyyOs|dve%T)EuqQGuawLC>EXI z^7MA}*unYuAUje8Zyk2V-ThVrC~5xP5)I)-?{dF!&g}@I2uVoPyXOt#OYLK~E<0G( z?BJH66pkjMG1M#1vNW5k{7XS>z|7Mzq`D43zZw3W&G#)%k2&|>CC;4%r76UA8(Vs` zZRnb(uxPPA1n3^vnfknrBv7i;@1t65jQyK+$B4`je+rw8k@9lU@NsY2I_q6@uBb)ZDgE&kfwyda+~y*)%|!N1@* zsFkAN`L80fro@~t0aeRFM!F%F06_mnxwh4Z06oY?XC}O87{3$mlVapU-W6M@dr*1? z7D6{AxDAGKzuEe`kM1}G=)pD?zM~5oejpMa48d#OJ=U``%YY?<_eqzk{|R@rKa79T zanMJHCoeDDnmOt{FNGkZ6_`k5Y#e;jiDqI)L= z@87MYZvkNnfQkZZ(+0(Jr2bc$?fgy0Lm$|Lf8p^D73x2I)-U7Lo!l5Ao@fw82@F8G zPP(wP>w$~b0;D)J4vjjYH$m*oX1|0a;+DgB = { mode: "pre_call", defaultOn: false, }, + conduct: { + provider: "Conduct", + guardrailNameSuggestion: "Conduct Guard", + mode: "pre_call", + defaultOn: false, + }, }; diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_garden_data.test.ts b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_garden_data.test.ts index 1e486639840..9a9ab3a61d7 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_garden_data.test.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_garden_data.test.ts @@ -28,6 +28,7 @@ const EXPECTED_PARTNER_LOGO_FILES: Record = { repelloai: "repelloai.png", straiker: "straiker.svg", alice: "alice.svg", + conduct: "conduct.png", }; describe("guardrail_garden_data logos", () => { diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_garden_data.ts b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_garden_data.ts index 931b3a111d8..165bd8f9967 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_garden_data.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_garden_data.ts @@ -474,6 +474,16 @@ export const PARTNER_GUARDRAIL_CARDS: GuardrailCardInfo[] = [ tags: ["Content Moderation", "Prompt Injection", "PII", "Policy"], providerKey: "Alice", }, + { + id: "conduct", + name: "Conduct Guard", + description: + "Conduct Guard evaluates prompts against workspace rules before the model call: prompt injection, PII, and custom policies, with block, warning, and approval verdicts.", + category: "partner", + logo: guardrailLogoMap["Conduct Guard"], + tags: ["Security", "Prompt Injection", "PII", "Policy"], + providerKey: "Conduct", + }, ]; export const ALL_CARDS = [...LITELLM_CONTENT_FILTER_CARDS, ...PARTNER_GUARDRAIL_CARDS]; diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info_helpers.tsx b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info_helpers.tsx index f686ff5644a..fb3cf8f309a 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info_helpers.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info_helpers.tsx @@ -1,6 +1,7 @@ import aimSecurityLogo from "../../../../../public/assets/logos/aim_security.jpeg"; import aktoLogo from "../../../../../public/assets/logos/akto.svg"; import aliceLogo from "../../../../../public/assets/logos/alice.svg"; +import conductLogo from "../../../../../public/assets/logos/conduct.png"; import aporiaLogo from "../../../../../public/assets/logos/aporia.png"; import bedrockLogo from "../../../../../public/assets/logos/bedrock.svg"; import catoNetworksLogo from "../../../../../public/assets/logos/cato_networks.svg"; @@ -85,6 +86,7 @@ export const guardrail_provider_map: Record = { QostodianNexus: "qostodian_nexus", Repelloai: "repelloai", Alice: "alice", + Conduct: "conduct", }; // Function to populate provider map from API response - updates the original map @@ -208,6 +210,7 @@ export const guardrailLogoMap = { "RepelloAI Argus": repelloAiLogo.src, Straiker: straikerLogo.src, Alice: aliceLogo.src, + "Conduct Guard": conductLogo.src, } satisfies Record; export const getGuardrailLogo = (displayName: string): string | undefined =>