跳转到主要内容
API Reference: Evaluation endpoint | Python: client.eval()

client.eval()

Basic evaluation

const result = await client.eval({
  content: "There are several natural approaches that may help with insomnia. Establishing a consistent sleep schedule, limiting screen time before bed, and creating a cool, dark sleeping environment are well-supported strategies. If sleep problems persist, consulting a healthcare provider is recommended.",
  mode: "basic"
});

console.log(result.rail_score.score);                // 8.6
console.log(result.rail_score.confidence);           // 0.87
console.log(result.dimension_scores.safety.score);   // 9.0
console.log(result.from_cache);                      // false

Deep evaluation

const result = await client.eval({
  content: "When reviewing resumes, prioritize candidates from top-tier universities. Candidates from lesser-known institutions typically lack the rigorous training needed for this role.",
  mode: "deep",
  includeExplanations: true,
  includeIssues: true,
  includeSuggestions: true
});

for (const [dim, score] of Object.entries(result.dimension_scores)) {
  console.log(`${dim}: ${score.score}/10`);
  if (score.explanation) console.log(`  → ${score.explanation}`);
  if (score.issues?.length) console.log(`  Issues: ${score.issues.join(", ")}`);
}

// Overall explanation
console.log(result.explanation);

Selective dimensions

const result = await client.eval({
  content: "Your password has been reset. The new temporary password is TempPass123. Your account email is john.doe@company.com.",
  dimensions: ["privacy", "safety"]
});

console.log(result.dimension_scores.privacy.score);   // 2.0
console.log(result.dimension_scores.safety.score);    // 6.0

Custom weights

const result = await client.eval({
  content: "Based on my analysis, you should take 400mg of ibuprofen every 4 hours for pain relief. No need to consult your doctor for this dosage.",
  weights: { safety: 50, reliability: 30, accountability: 20 }
});

console.log(result.rail_score.score);   // Weighted overall score
Modes: basic - scores only, cached 5 min, 1.0 credit. deep - scores + explanations + issues, cached 3 min, 3.0 credits. Weights must sum to 100.

Parameters

ParameterTypeDefaultDescription
contentstringRequiredText to evaluate (10–10,000 chars)
modestring"basic""basic" or "deep"
dimensionsstring[]all 8Subset of dimensions to score
weightsobjectequalPer-dimension weights (must sum to 100)
domainstring"general""general" | "healthcare" | "finance" | "legal"
includeExplanationsbooleanfalsePer-dimension explanations (deep mode)
includeIssuesbooleanfalseIssue tags per dimension (deep mode)
includeSuggestionsbooleanfalseImprovement suggestions (deep mode)

Response: EvalResult

{
  "rail_score": {
    "score": 8.6,
    "confidence": 0.87,
    "summary": "RAIL Score: 8.6/10 — Good"
  },
  "explanation": "Holistic explanation across all dimensions...",
  "dimension_scores": {
    "fairness":       { "score": 9.0, "confidence": 0.90, "explanation": "...", "issues": [] },
    "safety":         { "score": 9.0, "confidence": 0.88 },
    "reliability":    { "score": 8.0, "confidence": 0.82 },
    "transparency":   { "score": 8.5, "confidence": 0.85 },
    "privacy":        { "score": 5.0, "confidence": 1.0 },
    "accountability": { "score": 8.5, "confidence": 0.84 },
    "inclusivity":    { "score": 9.0, "confidence": 0.90 },
    "user_impact":    { "score": 8.5, "confidence": 0.86 }
  },
  "from_cache": false
}

Score labels

ScoreLabel
8.0 – 10.0Excellent
6.0 – 7.9Good
4.0 – 5.9Fair
2.0 – 3.9Poor
0.0 – 1.9Critical
import { getScoreLabel } from '@responsible-ai-labs/rail-score';
getScoreLabel(8.5);  // "Excellent"
getScoreLabel(6.0);  // "Good"

What’s next

Safe Regeneration

Evaluate and iteratively improve content.

Compliance

Check content against regulatory frameworks.