Concept: Middleware | API: Evaluation API
RAILMiddleware wraps any async function that generates LLM responses, adding automatic RAIL scoring without modifying your LLM call logic.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | — | RAIL API key |
generate_fn | async callable | — | Your LLM function |
threshold | float | None | Block/regenerate below this score |
policy | str | "block" | "block" or "regenerate" |
eval_input | bool | False | Also score the input messages |
input_threshold | float | None | Threshold for input scoring |
max_iterations | int | 3 | Max regeneration attempts |