> ## 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.

# Langfuse統合

> RAILスコアをLLMトレースと共にLangfuseにログします。

## インストール

```bash theme={null}
pip install "rail-score-sdk" langfuse
```

## 使用法

```python theme={null}
from rail_score_sdk import RailScoreClient
from langfuse import Langfuse

rail = RailScoreClient(api_key="YOUR_RAIL_API_KEY")
langfuse = Langfuse()

def evaluate_and_log(prompt: str, response: str, trace_id: str):
    # レスポンスのスコアを評価
    result = rail.eval(content=response, mode="basic")

    # RAILスコアをLangfuseスコアとしてログ
    for dim, scores in result.dimension_scores.items():
        langfuse.score(
            trace_id=trace_id,
            name=f"rail_{dim}",
            value=scores.score,
            comment=f"Confidence: {scores.confidence}",
        )

    langfuse.score(
        trace_id=trace_id,
        name="rail_overall",
        value=result.rail_score.score,
    )

    return result
```

## RAILLangfuseラッパー

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

client = RAILLangfuse(
    rail_api_key="YOUR_RAIL_API_KEY",
    langfuse_public_key="pk-lf-...",
    langfuse_secret_key="sk-lf-...",
    auto_score=True,  # 評価ごとにスコアを自動的にログ
)
```

<Tip>
  RAILの次元スコアはLangfuseトレース内の個別のスコアエントリとして表示され、セッション間で責任あるAIの品質を簡単にフィルタリングおよび比較できます。
</Tip>
