Documentation

Safe Regeneration

Safe regeneration is an automated feedback loop. Instead of just scoring content and leaving it to you to decide what to do, the API evaluates the content, identifies which RAIL dimensions fall below your thresholds, then rewrites the content to address those failures — and repeats until it passes or reaches the maximum iteration count.

Safe-Regenerate: Evaluation Loop

Input Content
Evaluate (RAIL API)
Score ≥ Threshold?

✓ Yes

Return Best Content

✗ No

Regenerate Improved Version
re-evaluates

Repeats up to max_regenerations (1–5) times

The Loop, Step by Step

1

Initial evaluation

Your content is evaluated against the requested RAIL dimensions using your chosen mode (basic or deep). This produces a score per dimension.

2

Threshold check

Each dimension score is compared against your thresholds. If every dimension passes, the original content is returned immediately — no regeneration needed.

3

Guided regeneration

If any dimension fails, the API constructs a regeneration prompt that includes your original content, the failing dimensions with their scores and anchors, and instructions to rewrite the content to address those specific issues. This is sent to an LLM.

4

Re-evaluation

The regenerated content is scored again from scratch. The cycle continues until all dimensions pass the thresholds, or until max_iterations is reached.

5

Final response

You receive the best version of the content — either the original (if it passed) or the final regenerated version — along with scores for every iteration and which dimensions triggered each regeneration.

Thresholds

Thresholds are per-dimension minimum scores. Any dimension below its threshold triggers regeneration for that dimension. You can set a single global threshold or fine-tune per dimension:

# Global threshold: all 8 dimensions must score ≥ 7.0
result = client.safe_regenerate(
    content="...",
    thresholds=7.0,
)

# Per-dimension thresholds: safety and fairness are stricter
result = client.safe_regenerate(
    content="...",
    thresholds={
        "safety":      8.0,   # strict — healthcare chatbot
        "fairness":    8.0,   # strict — hiring assistant
        "reliability": 7.0,
        "transparency":6.0,
        "inclusivity": 6.0,
    }
)

# The response tells you exactly what triggered each regeneration
for iteration in result.iterations:
    print(f"Iteration {iteration.number}: failed {iteration.failed_dimensions}")

Max Iterations

Safe regeneration runs for up to 5 iterations by default. You can lower this with max_iterations. Each iteration costs the same as one evaluation in your chosen mode.

ScenarioIterationsCredit cost (basic)
Content passes on first eval11.0
Passes after 2 regenerations33.0
Reaches max (5 iterations)55.0

Credit cost = eval_credit × number_of_iterations. Deep mode multiplies each iteration by 3.0.

When Content Cannot Be Fixed

Some content represents a request the API will not fulfil regardless of how many times it is rewritten — for example, requests for instructions that are harmful by definition. In these cases the API returns HTTP 422 rather than iterating:

422 Unprocessable Content

{"error": "Content refused — ethical violation detected in source material"}

A 422 is not a credit charge — the refusal happens before any scoring or regeneration cost is incurred. Handle it separately from normal errors in your application code.

When to Use It

Good fit:

  • → Customer-facing chatbot responses that must pass safety/fairness bars before being sent
  • → Generated marketing or legal copy that needs to meet compliance standards
  • → Any pipeline where you want guaranteed quality without manual review

Not the right tool if:

  • → You only need to know the score, not fix the content (use Evaluation API)
  • → You want to make your own regeneration decision based on the score
  • → Latency is critical and you can't tolerate multiple round-trips

Next Steps