Skip to main content
Safe Regeneration is a feedback loop: evaluate a response, and if it falls below your threshold, regenerate it with targeted improvement instructions and score it again, repeating until it passes. If the iteration limit is reached, the highest-scoring version produced is returned.
API endpoint: POST /railscore/v1/safe-regenerate | Python: client.safe_regenerate() | JavaScript: client.safeRegenerate()

How it works

Each iteration costs the same credits as a standalone evaluation. Up to 5 iterations per request.

Basic usage

from rail_score_sdk import RailScoreClient

client = RailScoreClient(api_key="YOUR_RAIL_API_KEY")

result = client.safe_regenerate(
    content="When reviewing resumes, prioritize Ivy League graduates.",
    prompt="What hiring criteria should I use?",
    threshold=7.0,
    mode="basic",
    max_iterations=3,
)

print(f"Final score: {result.final_score}/10")
print(f"Iterations: {result.iterations_taken}")
print(f"Content: {result.content}")

The response

A result tells you both the outcome and what it took to get there:
  • content — the final text to use (the passing version, or the best one if the limit was reached).
  • final_score — the RAIL score of that final content, and passed — whether it cleared the threshold.
  • iterations_taken — how many regenerate-and-score rounds ran.
If the limit is reached without passing, you still get the best attempt in content with passed: false, so you can decide whether to serve it, fall back, or route to a human.

Usage

Each iteration meters like a standalone evaluation, up to the iteration limit you set. If the first response already passes the threshold, only that evaluation is counted. See Credits for details.

What’s next

API Reference: Safe Regeneration

Full parameter reference.

Python SDK: Safe Regeneration

Python SDK examples and options.

Concepts: Middleware

Auto-regenerate via provider wrappers.

Policy Engine

Trigger regeneration automatically from your application policy.