Check Whether Treatment's Pooled Error Rate Breaches an Absolute Guardrail

Quick Overview

Implement a pandas guardrail check that pools error rates per experiment variant and flags treatment when its absolute increase over control exceeds a threshold. It tests ratio-of-sums aggregation, strict boundary handling with floating-point rates, and how to add statistical confidence to a guardrail decision.

Check Whether Treatment's Pooled Error Rate Breaches an Absolute Guardrail

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: easy

Interview Round: Other

Implement `guardrail_error_rate_check(df, max_abs_increase=0.005)` in `solution.py`. `df` has one row per bucket with columns `variant` (object: `'control'`/`'treatment'`), `requests` (int64, positive), and `errors` (int64). Return whether treatment's error rate increase over control breaches the guardrail. Requirements: - Pooled rate per variant: `sum(errors) / sum(requests)`, a ratio of sums, not the mean of per-row rates. - Increase is absolute: `rate_treatment - rate_control`, measured in rate units (0.005 is half a percentage point), not relative. - Return `True` only if the increase is strictly greater than `max_abs_increase`. An increase exactly equal to it returns `False`. - Zero or negative increase returns `False`. - Return a native Python `bool`, not a NumPy bool. Example: ```python df = pd.DataFrame({ "variant": ["control", "control", "treatment", "treatment"], "requests": [1500, 500, 1200, 800], "errors": [12, 8, 20, 14], }) # control: 20/2000 = 0.010, treatment: 34/2000 = 0.017 # absolute increase = 0.017 - 0.010 = 0.007 > 0.005 guardrail_error_rate_check(df, max_abs_increase=0.005) # -> True ``` ```hint Test the boundary Try a case where the true increase equals the threshold exactly, such as 25/1000 against 20/1000, and check what floating-point subtraction of the two rates returns. ``` ### Constraints & Assumptions - `df` has one row per bucket with the three columns above. - Both variants are present, each with at least one row with positive `requests`. ### What a Strong Answer Covers - The pooled rate per variant as a ratio of sums, and why that weighting matches the error rate users experienced. - The absolute difference of the two rates, compared with a strict inequality. - Boundary behavior: an increase exactly equal to the threshold returns `False`, even when floating-point rounding is involved. - A native Python `bool` as the return value. ### Follow-up Questions - Why use the pooled rate instead of the mean of per-row error rates? - How would you add statistical confidence to the check, beyond a raw point difference? - Requests within one bucket or from one user are not independent. How does that change the variance you would use?

Overview: Implement a pandas guardrail check that pools error rates per experiment variant and flags treatment when its absolute increase over control exceeds a threshold. It tests ratio-of-sums aggregation, strict boundary handling with floating-point rates, and how to add statistical confidence to a guardrail decision.

Nov 24, 2026
easyData ScientistOtherAnalytics & Experimentation
0
0

Implement guardrail_error_rate_check(df, max_abs_increase=0.005) in solution.py. df has one row per bucket with columns variant (object: 'control'/'treatment'), requests (int64, positive), and errors (int64). Return whether treatment's error rate increase over control breaches the guardrail.

Requirements:

  • Pooled rate per variant: sum(errors) / sum(requests) , a ratio of sums, not the mean of per-row rates.
  • Increase is absolute: rate_treatment - rate_control , measured in rate units (0.005 is half a percentage point), not relative.
  • Return True only if the increase is strictly greater than max_abs_increase . An increase exactly equal to it returns False .
  • Zero or negative increase returns False .
  • Return a native Python bool , not a NumPy bool.

Example:

df = pd.DataFrame({
    "variant": ["control", "control", "treatment", "treatment"],
    "requests": [1500, 500, 1200, 800],
    "errors": [12, 8, 20, 14],
})
# control: 20/2000 = 0.010, treatment: 34/2000 = 0.017
# absolute increase = 0.017 - 0.010 = 0.007 > 0.005
guardrail_error_rate_check(df, max_abs_increase=0.005)  # -> True

Constraints & Assumptions

  • df has one row per bucket with the three columns above.
  • Both variants are present, each with at least one row with positive requests .

What a Strong Answer Covers Guidance

  • The pooled rate per variant as a ratio of sums, and why that weighting matches the error rate users experienced.
  • The absolute difference of the two rates, compared with a strict inequality.
  • Boundary behavior: an increase exactly equal to the threshold returns False , even when floating-point rounding is involved.
  • A native Python bool as the return value.

Follow-up Questions Guidance

  • Why use the pooled rate instead of the mean of per-row error rates?
  • How would you add statistical confidence to the check, beyond a raw point difference?
  • Requests within one bucket or from one user are not independent. How does that change the variance you would use?