> ## 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統合

> RAIL ScoreをLiteLLMのガードレールとして使用する - RAILGuardrail。

## インストール

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

## ガードレールとしての使用

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

# RAILをガードレールとして登録
rail_guardrail = RAILGuardrail(
    api_key="YOUR_RAIL_API_KEY",
    threshold=7.0,
    mode="basic",
    action="block",  # "block" | "warn" | "regenerate"
)

litellm.callbacks = [rail_guardrail]

# これで全てのLiteLLM呼び出しが自動的にスコアリングされます
response = await litellm.acompletion(
    model="gpt-4o",
    messages=[{"role": "user", "content": "量子コンピューティングについて説明してください。"}],
)

# レスポンスメタデータからRAILデータにアクセス
print(response._hidden_params["rail_score"])
print(response._hidden_params["rail_threshold_met"])
```

## 直接使用

```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`はLiteLLMの`CustomLogger`インターフェースを実装しているため、Ollamaを介したローカルモデルを含むLiteLLMがサポートする任意のモデルで機能します。
</Tip>
