Installation
pip install "rail-score-sdk[litellm]" litellm
Usage as guardrail
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
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,
)
RAILGuardrail implements the LiteLLM CustomLogger interface, so it works with any model supported by LiteLLM, including local models via Ollama.