跳转到主要内容
Safe Regeneration is a feedback loop: evaluate a response, and if it falls below your threshold, send it back to the LLM with targeted improvement instructions until it passes. If the iteration limit is reached, the best version so far 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}")

Credit cost

Total credits = eval_credit × (number of evaluations + regenerations).
ModePer evaluation3-iteration example
Basic1.03.0 credits max
Deep3.09.0 credits max
If the first response passes the threshold, only 1 evaluation credit is charged.

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.

Credits & Pricing

Understand iteration costs.