Build a staged rollout gate with Holm-corrected guardrail metrics
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: medium
Interview Round: Other
Write `ramp_decision`, the gate that decides what happens to a feature at each stage of a staged ramp (`'1pct'`, `'5pct'`, `'50pct'`).
```python
def ramp_decision(stage, guardrail_pvals, guardrail_deltas, primary_p, primary_delta, alpha=0.05) -> dict:
```
`guardrail_pvals` and `guardrail_deltas` map the same guardrail names to a p-value and an observed delta, where a negative delta means the metric got worse. Return a dict with exactly three keys. `'action'` is one of `'rollback'`, `'advance'`, `'ship'` or `'hold'`. `'breached'` is the sorted list of breached guardrail names, or `[]` if there are none. `'primary_significant'` is `primary_p <= alpha`.
Apply these rules:
1. Holm-correct the guardrail p-values with `multipletests(list_of_pvals, alpha=alpha, method='holm')`, iterating names in `sorted(guardrail_pvals)`. An empty guardrail set means no breaches.
2. A guardrail is breached if and only if its Holm-adjusted p-value is `<= alpha` and its delta is `< 0`. The raw p-value does not gate.
3. Any breach returns `'rollback'`. This check comes before the primary metric.
4. Otherwise, if `primary_p <= alpha` and `primary_delta > 0`, return `'advance'` at stage `'1pct'` or `'5pct'` and `'ship'` at stage `'50pct'`.
5. Otherwise return `'hold'`. That includes a significant primary with a non-positive delta.
```python
ramp_decision(
stage='5pct',
guardrail_pvals={'latency': 0.01, 'errors': 0.30},
guardrail_deltas={'latency': -0.02, 'errors': 0.00},
primary_p=0.02, primary_delta=0.05,
)
# -> {'action': 'rollback', 'breached': ['latency'], 'primary_significant': True}
```
```hint Check the example
Work the two guardrail p-values in the example through Holm's step-down procedure by hand and see which adjusted value ends up at or below `alpha`.
```
```hint Empty guardrails
Decide what the function returns when there are no guardrails, without relying on how the library treats an empty list.
```
### Constraints & Assumptions
- `stage` is always one of `'1pct'`, `'5pct'` or `'50pct'`.
- The two guardrail dicts have the same keys.
- `multipletests` comes from `statsmodels.stats.multitest`.
### What a Strong Answer Covers
- Holm-adjusted p-values matched back to the right names, and a breach rule that needs both an adjusted p-value at or below `alpha` and a negative delta.
- Strict priority of the actions, with `'primary_significant'` reported on its own whatever the action is.
- The empty guardrail set and the exact output shape.
- A hand check of the example, including a case where a raw p-value passes but the adjusted one does not.
### Follow-up Questions
- Why use Holm here instead of Bonferroni or Benjamini-Hochberg?
- How would you handle guardrails where only harm in one direction matters?
- How does the false-positive risk change as you add more guardrails and ramp stages?
- At 1% traffic the primary metric is rarely significant. How would you change the advance rule for the early stages?
Overview: Implement the decision function for a staged feature ramp that Holm-corrects guardrail p-values, flags harmful breaches and chooses rollback, advance, ship or hold. It tests multiple-testing correction, rule priority and how repeated checks across ramp stages affect error rates.