model.scenario() is available on any ReasoningModel and returns a structured ScenarioResult containing one QueryResult per input row, each with the candidate counterfactual edits found by the search.
Basic scenario
Wrap your query rows in anop.Dataset and call model.scenario() with the desired target_class.
Understanding the result structure
model.scenario() returns a ScenarioResult. Iterating over result.queries gives you one QueryResult per input row:
ScenarioResult
ScenarioResult
The top-level container. Access all query results via
result.queries.QueryResult
QueryResult
One per input row. Contains:
q.query_index: position of this row in your input dataset.q.baseline_prediction: the model’s original prediction for this row.q.already_at_desired_class:Trueif the row is already classified astarget_class; no counterfactual is needed.q.counterfactuals: list ofCounterfactualcandidates found by the search.
Counterfactual
Counterfactual
One candidate set of edits. Contains:
cf.n_changes: number of features changed.cf.changes:dict[str, Change]mapping each changed feature name to aChangeobject with.beforeand.aftervalues.
Tuning the search
By defaulttarget_class is 1. Control the search budget with n_trials and max_steps:
Full example: flipping denied loan applications
Next steps
Explanations
Understand which features drive each prediction before running counterfactuals.
Pattern Tracker
Aggregate patterns across an entire cohort rather than row by row.