Recommend safe contextual bandit action

Recommend contextual aggregate interventions with Bayesian reward learning only inside a posterior logistic harm constraint, explicitly falling back to a governed baseline when no arm is safe enough.

What it's for

Adds a safety layer to adaptive intervention search so a high expected uplift cannot outrank an unacceptable incident or guardrail risk.

What you give it

Inputs split into evidence read from your connected systems, calibration your team owns, and numerical controls that affect precision but never the result's meaning.

Field Type Role Required
arms array of objects (1 field) ≥ 2 items Evidence Yes
baseline_arm_id string non-empty Your calibration Yes
current_context array of number ≥ 1 item Evidence Yes
history array of objects (5 fields) ≥ 100 items Evidence Yes
max_detail_rows integer ≥ 1, ≤ 500 Numerical control Optional
maximum_harm_probability number ≥ 0.001, ≤ 0.5 Your calibration Optional
maximum_iterations integer ≥ 10, ≤ 1000 Numerical control Optional
minimum_safety_probability number ≥ 0.5, ≤ 0.999 Your calibration Optional
posterior_draws integer ≥ 200, ≤ 20000 Numerical control Optional
prior_precision number ≥ 0.000001, ≤ 1000 Your calibration Optional
reward_noise number ≥ 0.000001, ≤ 1000000 Your calibration Optional
seed integer Numerical control Optional

Each history record

Field Type Required
arm_id string (non-empty) Yes
context array of number (≥ 1 item) Yes
harm integer (≥ 0, ≤ 1) Yes
id string (non-empty) Yes
reward number Yes
Example input
{
  "arms": [
    {
      "id": "baseline"
    },
    {
      "id": "safe_improvement"
    },
    {
      "id": "risky_acceleration"
    }
  ],
  "baseline_arm_id": "baseline",
  "current_context": [
    0
  ],
  "history": [
    {
      "arm_id": "baseline",
      "context": [
        -0.5
      ],
      "harm": 1,
      "id": "safe-bandit-0",
      "reward": 0.9
    },
    {
      "arm_id": "safe_improvement",
      "context": [
        -0.13366336633663367
      ],
      "harm": 1,
      "id": "safe-bandit-1",
      "reward": 1.9732673267326732
    },
    {
      "arm_id": "risky_acceleration",
      "context": [
        0.23267326732673266
      ],
      "harm": 1,
      "id": "safe-bandit-2",
      "reward": 4.046534653465346
    },

Truncated for display — the full payload is 941 lines.

What you get back

This is the actual output of running the example above — computed by the same function the platform calls, not an illustration.

Example output
{
  "arms": [
    {
      "arm_id": "safe_improvement",
      "historical_actions": 34,
      "posterior_safety_probability": 0.935,
      "predicted_harm_probability": {
        "mean": 0.121863,
        "p90": 0.181361
      },
      "predicted_reward": {
        "mean": 1.946758,
        "p10": 1.755583,
        "p90": 2.152475
      },
      "probability_reward_exceeds_baseline": 1,
      "safety_eligible": true,
      "thompson_selection_probability": 1
    },
    {
      "arm_id": "baseline",
      "historical_actions": 34,
      "posterior_safety_probability": 0.925,
      "predicted_harm_probability": {
        "mean": 0.120166,
        "p90": 0.193824
      },
      "predicted_reward": {
        "mean": 0.977374,
        "p10": 0.765619,
        "p90": 1.176239
      },
      "probability_reward_exceeds_baseline": 0,
      "safety_eligible": true,
      "thompson_selection_probability": 0
    },
    {
      "arm_id": "risky_acceleration",
      "historical_actions": 34,
      "posterior_safety_probability": 0,
      "predicted_harm_probability": {
        "mean": 0.492152,
        "p90": 0.597429
      },

Truncated for display — the full payload is 81 lines.

How it works

Sequential Bayesian & bandits — Learn while deciding — update beliefs as evidence arrives and choose where the next unit of effort is worth spending.

  1. 1 Recommend contextual aggregate interventions with Bayesian reward learning only inside a posterior logistic harm constraint, explicitly falling back to a governed baseline when no arm is safe enough.
  2. 2 Evaluate the method-specific diagnostics and gates returned by the function, then abstain unless the declared decision clears them under locally governed thresholds.

Before you trust it

Every tool in the catalog ships with the conditions under which its answer is meaningful — and the conditions under which it should abstain instead of guessing.

Assumptions & guardrails

  • The likelihood or reward model, prior support, action logging, delayed outcomes, and any stationarity assumptions match the deployment process.
  • Posterior probability and adaptive selection are model-conditional; they are not substitutes for randomized propensities or guaranteed safety.

Minimum evidence

  • arms: at least 2 rows/items
  • history: at least 100 rows/items
  • current_context: at least 1 rows/items
  • baseline_arm_id: required and organization-defined

How to validate it

Validate on future periods or held-out aggregate units, compare with a simple baseline, and require stability across plausible metric definitions and decision thresholds.

Calibrating it to your org

Same for everyone

The mathematical kernel, validation rules, method version, and JSON output semantics are organization-independent; no tenant-trained coefficients or company benchmark is embedded in the function.

Specific to you

  • binary harm within a fixed post-deployment window
  • complete context vector with stable feature ordering
  • current aggregate context snapshot
  • baseline arm
  • harm definition and maximum probability
  • minimum posterior safety probability
  • reward utility scale

Calibration workflow

  1. 1 Define the management decision, target outcome, aggregate unit, privacy boundary, cadence, and prediction/intervention horizon for this organization.
  2. 2 Build a tenant-scoped historical cohort using only information available before each prediction or decision; preserve zero periods, censoring, assignment probabilities, and unresolved outcomes when the method requires them.
  3. 3 Estimate statistical parameters on training history, but obtain costs, utilities, risk tolerance, practical-effect thresholds, capacity, and policy constraints from accountable decision owners.
  4. 4 Validate on later time windows or held-out aggregate units at the deployment grain, against a simple baseline and the function-specific validation strategy.
  5. 5 Deploy only if the returned decision clears evidence, overlap, calibration, robustness, and guardrail checks; warning, unsupported, schema-gap, and fallback decisions are abstentions.
  6. 6 Monitor realized outcomes, data drift, coverage, and decision regret; recalibrate at a governed cadence or after a detected regime/definition change, never merely because a stakeholder dislikes the result.

Call it from your AI

You don't wire up 388 tools in your MCP client. The GitRevio MCP server exposes 18 tools, three of which let an agent search the catalog, read a tool's schema, and run it — so the assistant finds this one on its own.

gitrevio_capabilities_search
  { "q": "recommend contextual aggregate interventions with bayesian" }
  → finds "recommend_safe_contextual_bandit_action"

gitrevio_capability_describe
  { "capability_id": "recommend_safe_contextual_bandit_action" }
  → returns the input schema and agent guidance shown on this page

gitrevio_capability_run
  { "capability_id": "recommend_safe_contextual_bandit_action", "arguments": { ... } }
  → returns the result shown above

Works in Claude Desktop, Claude Code, Cursor, Cline, Continue.dev, Goose and Aider. See the MCP server.

Related tools

Aggregate risk register copula

Aggregate risk-register occurrence and lognormal severity marginals through a validated Gaussian copula into expected loss, VaR, CVaR, dependence amplification, and tail shares.

Statistical audit & measurement

Allocate restless bandit interventions

Allocate scarce recurring interventions across evolving Markov units with Whittle indices, explicit indexability checks, and paired policy simulation.

Sequential Bayesian & bandits

Attribute commercial dependency tail loss

Calculate expected loss, VaR and CVaR for commercial value concentrated in shared technical components, then allocate every modeled tail-loss dollar exactly once across components with normalized negative-log survival hazard rather than overlapping leave-one-out sensitivities.

Forecasting & survival

Audit commercial resilience claim integrity

Audit resilience ROI claims against a unique commercial-source to technical-component graph: recompute each action's avoided loss under joint failure scenarios, cap support at graph-derived value, detect duplicate effects, probability drift and weak evidence, and prevent overlapping component benefits from being sold twice.

Network & dependency analysis

Audit decision rank robustness smaa

Measure rank acceptability, regret, pairwise dominance, and central winning weights under uncertain criterion scores and bounded stakeholder weights.

Statistical audit & measurement

Audit extreme metric tail dependence

Detect extreme metric co-exceedances beyond independence with empirical tail coefficients, permutation inference, practical magnitude gates, and FDR control.

Statistical audit & measurement

See every tool in Risk, tails & resilience →

Ready to See Your Engineering work clearly?

Request a free demo