Skip to content

fix: Register DynamoAI guardrail initializer and enum entry#23754

Closed
Harshit28j wants to merge 4 commits intoBerriAI:mainfrom
Harshit28j:litellm_fix_guardrails_dynamo
Closed

fix: Register DynamoAI guardrail initializer and enum entry#23754
Harshit28j wants to merge 4 commits intoBerriAI:mainfrom
Harshit28j:litellm_fix_guardrails_dynamo

Conversation

@Harshit28j
Copy link
Copy Markdown
Contributor

Summary

Fixes #22773 — DynamoAI guardrail now properly registers with the initialization system, resolving the "Unsupported guardrail: dynamoai" error.

Changes

  1. Added DYNAMOAI = "dynamoai" to SupportedGuardrailIntegrations enum
  2. Implemented initialize_guardrail() function in dynamoai/__init__.py
  3. Added guardrail_initializer_registry and guardrail_class_registry for proper registration
  4. Added comprehensive tests covering enum entry, initializer registry, class registry, instance creation, and global discovery

The DynamoAI guardrail was added in PR #15920 but was never wired into the registration system. The dynamic discovery mechanism at module load time looks for guardrail_initializer_registry in each guardrail hook's __init__.py — DynamoAI was missing this, causing lookups to fail. All 5 new tests verify the fix works end-to-end.

🐛 Bug Fix

Harshit28j and others added 4 commits March 16, 2026 20:19
Fix the "Unsupported guardrail: dynamoai" error by:
1. Adding DYNAMOAI to SupportedGuardrailIntegrations enum
2. Implementing initialize_guardrail() and registries in dynamoai/__init__.py

The DynamoAI guardrail was added in PR BerriAI#15920 but never properly registered
in the initialization system. The __init__.py was missing the
guardrail_initializer_registry and guardrail_class_registry dictionaries
that the dynamic discovery mechanism looks for at module load time.

Fixes BerriAI#22773

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Verifies enum entry, initializer registry, class registry,
instance creation, and global registry discovery.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Mar 16, 2026 3:36pm

Request Review

@Harshit28j
Copy link
Copy Markdown
Contributor Author

Duplicate of #23752, closing.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 16, 2026

Greptile Summary

This PR wires DynamoAI into the guardrail registration system, fixing the "Unsupported guardrail: dynamoai" error reported in #22773. The dynamic discovery mechanism in guardrail_registry.py scans guardrail_hooks/ subdirectories at module load time for a guardrail_initializer_registry dict; DynamoAI was the only integration that had a full implementation but was missing this dict and the corresponding SupportedGuardrailIntegrations enum entry.

  • DYNAMOAI = "dynamoai" added to SupportedGuardrailIntegrations in alphabetical order — correct.
  • initialize_guardrail, guardrail_initializer_registry, and guardrail_class_registry added to dynamoai/__init__.py, exactly mirroring the established pattern used by aporia_ai, grayswan, and others.
  • Five new unit tests cover enum presence, registry entries, instance creation (mocked), and global discoverability — all mock-only, no real network calls.
  • Missing: DynamoAIGuardrailConfigModel is not added to the LitellmParams inheritance chain. This means the DynamoAI-specific model_id and policy_ids constructor parameters cannot be set via the standard YAML config path, and initialize_guardrail does not forward them even via environment variables. Users who rely on these fields will silently get empty/default values.
  • Unused import os in the test file.

Confidence Score: 3/5

  • Safe to merge for the core bug fix, but DynamoAI-specific config fields (model_id, policy_ids) remain silently unconfigurable via YAML.
  • The registration wiring is correct and follows the established pattern precisely. The enum entry, initializer, and both registries are in order. Tests are properly mocked and cover the key scenarios. The score is reduced because DynamoAIGuardrailConfigModel is not integrated into LitellmParams, leaving model_id and policy_ids inaccessible via the standard config path — this limits the completeness of the fix for users who need those DynamoAI features.
  • litellm/proxy/guardrails/guardrail_hooks/dynamoai/init.py — model_id and policy_ids not forwarded; litellm/types/guardrails.py — DynamoAIGuardrailConfigModel not added to LitellmParams bases

Important Files Changed

Filename Overview
litellm/proxy/guardrails/guardrail_hooks/dynamoai/init.py Adds initialize_guardrail, guardrail_initializer_registry, and guardrail_class_registry following the established pattern. The core registration wiring is correct; however, DynamoAI-specific config fields (model_id, policy_ids) are not forwarded because DynamoAIGuardrailConfigModel is absent from LitellmParams.
litellm/types/guardrails.py Adds DYNAMOAI = "dynamoai" to SupportedGuardrailIntegrations enum in alphabetical order — correct and minimal change.
tests/test_litellm/proxy/guardrails/guardrail_hooks/test_dynamoai.py Five new unit tests covering enum entry, initializer/class registry presence, instance creation (properly mocked), and global registry discoverability. No real network calls are made. Minor: unused import os on line 7.

Sequence Diagram

sequenceDiagram
    participant Config as YAML Config
    participant Registry as guardrail_registry.py
    participant Hooks as guardrail_hooks/dynamoai/__init__.py
    participant Init as initialize_guardrail()
    participant Guard as DynamoAIGuardrails
    participant CBM as logging_callback_manager

    Note over Registry: Module load — dynamic discovery
    Registry->>Hooks: importlib.import_module("...dynamoai")
    Hooks-->>Registry: guardrail_initializer_registry {"dynamoai": initialize_guardrail}
    Hooks-->>Registry: guardrail_class_registry {"dynamoai": DynamoAIGuardrails}
    Registry->>Registry: guardrail_initializer_registry.update(discovered)

    Note over Config,CBM: Runtime — guardrail initialization
    Config->>Registry: InMemoryGuardrailHandler.initialize_guardrail(guardrail)
    Registry->>Registry: initializer = guardrail_initializer_registry["dynamoai"]
    Registry->>Init: initializer(litellm_params, guardrail)
    Init->>Guard: DynamoAIGuardrails(api_base, api_key, guardrail_name, event_hook, default_on)
    Guard-->>Init: _dynamoai_callback
    Init->>CBM: add_litellm_callback(_dynamoai_callback)
    Init-->>Registry: _dynamoai_callback
Loading

Last reviewed commit: ed213ba


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

Comment on lines +14 to +20
_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,
)
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", []).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]DynamoAI Guardrail missing initializer registration - "Unsupported guardrail: dynamoai" error

1 participant