Viyan

Viyan AI

Guardrail model updates with loss-conditioned execution

Loss-conditioned state execution uses historical data to filter model updates, ensuring that only changes with a proven high probability of reducing error are implemented.

Most production systems treat model output as a command, executing every action the inference engine suggests. This assumes that if a model is accurate, its proposed actions are optimal. Loss-conditioned execution rejects this, framing the decision to execute as a problem distinct from prediction. The system intercepts proposed actions and evaluates them against a persistence baseline, which assumes the future state mirrors the current state. The system calculates the loss of these proposals by applying them to a buffer of recent historical data as if the decision had been made in the past. If a statistical test fails, the system ignores the model’s recommendation and maintains the current state.

Two different transition laws can provide identical information about which events are likely to occur, yet require opposite decisions to minimize absolute loss. By filtering out proposals that possess strong occurrence-ranking signals but poor loss characteristics, developers can prevent the model from triggering interventions where the potential cost of an incorrect action exceeds the benefit of doing nothing.

Strategy Accuracy Focus Loss Mechanism Execution Logic
Pure Model Execution High Unbounded Updates on every proposal
Pure Persistence Low Absolute Updates on zero proposals
Loss-Conditioned Mixed Bounded Executes only if loss gain > 0

The mechanism of bounded loss

To implement this, you construct a loss-specific proposal from the model's predictive distribution and compare it against the persistence baseline. For each calibration unit i in your held-out set of N samples, you calculate the loss difference as L = Loss(persistence) - Loss(model). The decision to execute the update is governed by a lower confidence bound on the average loss improvement, calculated as:

Bound = mean(L) - z * (std(L) / sqrt(N))

The term z * (std(L) / sqrt(N)) is the penalty, where z is the critical value for your confidence level, std is the sample standard deviation of your loss differences, and N is the number of calibration samples. You only commit to an update if the Bound is strictly greater than zero. This ensures the update is statistically likely to outperform the simple persistence baseline at a chosen confidence interval. The mechanism works by forcing the model to provide a clear, positive margin of improvement that exceeds the uncertainty inherent in the data.

Constrained inventory forecasting

In inventory systems with six common stock-out or overstock conditions, the loss-based test decouples event predictability from execution. Consider a warehouse SKU where a model predicts a 10% increase in demand. If the persistence baseline loss is 100 units and the model’s predicted loss is 95 units, the mean improvement is 5. However, if the variance of that model's performance is high—perhaps due to the model failing during specific seasonal promotions—the penalty term z * (std(L) / sqrt(N)) might equal 6. The resulting Bound of -1 forces the system to reject the update. Even though the model has a positive directional signal, the economic risk of over-ordering is too high. The system refuses the intervention to avoid the costs identified in JD.com experiments on constrained forecasting.

Limitations and drift

This approach assumes the data is independent and identically distributed. If the calibration distribution drifts, the confidence bound becomes overly conservative, and the system ignores valid updates. Developers mitigate this using a sliding window approach, restricting the buffer to the most recent T time steps. Choosing T requires balancing bias and variance. A small window captures recent dynamics but inflates the penalty term due to higher variance, effectively freezing updates. A large window reduces variance but introduces lag, as stale data from past regimes obscures the performance of the current model.

Regime shifts are often detected using CUSUM (Cumulative Sum Control Chart) tests, which track the running mean of the loss differences. When the cumulative sum of the differences deviates beyond a pre-defined threshold, the system flags a regime change and truncates the calibration history to force recalibration on current, relevant data. While this prevents stale data from polluting the bound, it remains an open research question to determine the optimal threshold for sensitivity without triggering false negatives during high-volatility periods.

Sources