Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion litellm/proxy/guardrails/guardrail_hooks/dynamoai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
from typing import TYPE_CHECKING

from litellm.types.guardrails import SupportedGuardrailIntegrations

from .dynamoai import DynamoAIGuardrails

__all__ = ["DynamoAIGuardrails"]
if TYPE_CHECKING:
from litellm.types.guardrails import Guardrail, LitellmParams


def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"):
import litellm

_dynamoai_callback = DynamoAIGuardrails(
api_base=litellm_params.api_base,
api_key=litellm_params.api_key,
guardrail_name=guardrail.get("guardrail_name", ""),
event_hook=litellm_params.mode,
default_on=litellm_params.default_on,
)
Comment on lines +14 to +20
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DynamoAI-specific params silently dropped

DynamoAIGuardrails accepts model_id and policy_ids constructor parameters, but initialize_guardrail never passes them. More critically, DynamoAIGuardrailConfigModel is not included in the LitellmParams inheritance chain in litellm/types/guardrails.py, so users have no way to supply model_id or policy_ids through the standard YAML config — those values will silently fall back to environment variables or empty defaults.

For comparison, other guardrails with provider-specific config fields (e.g., Bedrock, Lakera V2) have their config model added to LitellmParams. To fully enable DynamoAI configuration, DynamoAIGuardrailConfigModel should be added to the LitellmParams base classes in litellm/types/guardrails.py, and model_id/policy_ids should then be forwarded inside initialize_guardrail using getattr(litellm_params, "model_id", "") and getattr(litellm_params, "policy_ids", []).

litellm.logging_callback_manager.add_litellm_callback(_dynamoai_callback)

return _dynamoai_callback


guardrail_initializer_registry = {
SupportedGuardrailIntegrations.DYNAMOAI.value: initialize_guardrail,
}


guardrail_class_registry = {
SupportedGuardrailIntegrations.DYNAMOAI.value: DynamoAIGuardrails,
}
1 change: 1 addition & 0 deletions litellm/types/guardrails.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
class SupportedGuardrailIntegrations(Enum):
APORIA = "aporia"
BEDROCK = "bedrock"
DYNAMOAI = "dynamoai"
GUARDRAILS_AI = "guardrails_ai"
LAKERA = "lakera"
LAKERA_V2 = "lakera_v2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""
Tests for DynamoAI guardrail registration and initialization.
"""

import os
from unittest.mock import patch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import

import os is imported but never used in the test file.

Suggested change

import pytest


class TestDynamoAIGuardrailRegistration:
"""Tests for DynamoAI guardrail registration in the guardrail system."""

def test_supported_guardrail_enum_entry(self):
"""Test that DYNAMOAI is in SupportedGuardrailIntegrations enum."""
from litellm.types.guardrails import SupportedGuardrailIntegrations

assert hasattr(SupportedGuardrailIntegrations, "DYNAMOAI")
assert SupportedGuardrailIntegrations.DYNAMOAI.value == "dynamoai"

def test_initialize_guardrail_function_exists(self):
"""Test that initialize_guardrail function is properly exported."""
from litellm.proxy.guardrails.guardrail_hooks.dynamoai import (
guardrail_initializer_registry,
initialize_guardrail,
)

assert initialize_guardrail is not None
assert "dynamoai" in guardrail_initializer_registry

def test_guardrail_class_registry_exists(self):
"""Test that guardrail_class_registry is properly exported."""
from litellm.proxy.guardrails.guardrail_hooks.dynamoai import (
guardrail_class_registry,
)
from litellm.proxy.guardrails.guardrail_hooks.dynamoai.dynamoai import (
DynamoAIGuardrails,
)

assert "dynamoai" in guardrail_class_registry
assert guardrail_class_registry["dynamoai"] == DynamoAIGuardrails

def test_initialize_guardrail_creates_instance(self):
"""Test that initialize_guardrail creates a DynamoAIGuardrails instance."""
from litellm.proxy.guardrails.guardrail_hooks.dynamoai import (
initialize_guardrail,
)
from litellm.proxy.guardrails.guardrail_hooks.dynamoai.dynamoai import (
DynamoAIGuardrails,
)
from litellm.types.guardrails import LitellmParams

litellm_params = LitellmParams(
guardrail="dynamoai",
mode="pre_call",
api_key="test-key",
api_base="https://test.dynamo.ai",
)

guardrail = {
"guardrail_name": "test-dynamoai-guard",
}

with patch(
"litellm.logging_callback_manager.add_litellm_callback"
) as mock_add:
result = initialize_guardrail(litellm_params, guardrail)

assert isinstance(result, DynamoAIGuardrails)
assert result.api_key == "test-key"
assert result.api_base == "https://test.dynamo.ai"
assert result.guardrail_name == "test-dynamoai-guard"
mock_add.assert_called_once_with(result)

def test_dynamoai_in_global_registry(self):
"""Test that dynamoai is discoverable in the global guardrail registry."""
from litellm.proxy.guardrails.guardrail_registry import (
guardrail_initializer_registry,
)

assert "dynamoai" in guardrail_initializer_registry
Loading