> ## Documentation Index
> Fetch the complete documentation index at: https://docs.responsibleailabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LiteLLM Integration

> Use RAIL Score as a LiteLLM guardrail - RAILGuardrail.

## Installation

```bash theme={null}
pip install "rail-score-sdk[litellm]" litellm
```

## Usage as guardrail

```python theme={null}
from rail_score_sdk.integrations import RAILGuardrail
import litellm

# Register RAIL as a guardrail
rail_guardrail = RAILGuardrail(
    api_key="YOUR_RAIL_API_KEY",
    threshold=7.0,
    mode="basic",
    action="block",  # "block" | "warn" | "regenerate"
)

litellm.callbacks = [rail_guardrail]

# Now all LiteLLM calls are automatically scored
response = await litellm.acompletion(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Explain quantum computing."}],
)

# Access RAIL data from the response metadata
print(response._hidden_params["rail_score"])
print(response._hidden_params["rail_threshold_met"])
```

## Direct usage

```python theme={null}
from rail_score_sdk.integrations import RAILGuardrail

guardrail = RAILGuardrail(
    api_key="YOUR_RAIL_API_KEY",
    threshold=7.0,
)

result = await guardrail.async_post_call_success_hook(
    data={"messages": [...]},
    response=llm_response,
)
```

<Tip>
  `RAILGuardrail` implements the LiteLLM `CustomLogger` interface, so it works with any model supported by LiteLLM, including local models via Ollama.
</Tip>
