InferenceAI

Enter at least two characters to search.

Start free

Canary Rollout Guardrail

mediumProduction AI20 min25 XP

Implement should_rollback_canary(samples, max_error_rate, max_p95_ms). Each sample is [latency_ms, failed], where failed is boolean. Return True if the observed error rate is strictly greater than max_error_rate or nearest-rank p95 latency is strictly greater than max_p95_ms. Return False for an empty sample. For p95, sort latencies and use the 1-based rank ceil(0.95 * n). This is a simplified rollout rule; real systems also require minimum sample sizes and statistical checks.

Examples

EXAMPLE WALKTHROUGHerror guardrail

A guided view of the published example, not a trace of your code.

INPUT[[[100,false],[200,false],[300,true]],0.2,400]
TASKshould_rollback_canary()
EXPECTED OUTPUTtrue

Start with the input values shown in this example.

Example 1 of 2

Input: samples = [[100,false],[200,false],[300,true]], max_error_rate = 0.2, max_p95_ms = 400

Output: true

Explanation: error guardrail

Input: samples = [[100,false],[500,false]], max_error_rate = 0.1, max_p95_ms = 400

Output: true

Explanation: latency guardrail

Hint 1

A value equal to a threshold passes.

Hint 2

Nearest-rank p95 uses a 1-based rank.

Topics

PythonCanary ReleaseObservability