Skip to content

ahmeddoghri/riskbandit

Repository files navigation

riskbandit

The reward-greedy policy does exactly what you told it to do and exactly what you were afraid it would do. riskbandit builds the guardrail that stops it.

CI python deps license

Optimize a contextual bandit for reward alone and it will happily find the action that blows through your risk budget, because nobody told it a budget existed. riskbandit trains separate reward and cost models on synthetic logged data, calibrates the cost residuals with conformal prediction on a held-out split, and at decision time only considers actions whose upper cost bound actually fits inside the budget before picking the best reward among the survivors. Safety becomes a selection rule baked into the policy instead of a paragraph in the README that nobody enforces.

Run it

git clone https://github.com/ahmeddoghri/riskbandit
cd riskbandit
pip install -e ".[dev]"
python -m riskbandit.benchmark

Verified benchmark

Generated locally with python -m riskbandit.benchmark:

policy         avg_reward  violation_rate
safe_action        0.442           0.000
reward_greedy      0.774           0.733
conformal          0.572           0.007
violation_drop      0.727

Reward-greedy racks up 0.774 average reward and blows the budget on 73.3% of decisions, which is what "optimize for reward, don't ask questions" looks like in practice. The conformal policy gives up some reward, landing at 0.572, but drops the violation rate to 0.7%, a 0.727 point collapse. That trade is the whole product.

Research trail

Tests

pytest -q
ruff check .

MIT © Ahmed Doghri

About

The greedy bandit does exactly what you asked and exactly what you feared. Conformal cost bounds drop budget violations from 73% to 0.7% while keeping most of the reward.

Topics

Resources

License

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages