-
Notifications
You must be signed in to change notification settings - Fork 0
Policies And Approvals
->reading(callable $callback) lets you inspect, approve, or veto a request before it runs, based on the already-parsed, already-validated query rather than raw AI input:
->reading(function (Request $request, array $appliers) {
return Decision::accept();
return Decision::deny('Not allowed for this account.');
return Decision::approve('Touches billing data and needs a human to confirm first.');
return true; // shorthand for Decision::accept()
return false; // shorthand for Decision::deny()
});-
Decision::accept()ortrue: the request proceeds -
Decision::deny($reason)orfalse: the tool immediately returns{"error": $reason}and the query never runs -
Decision::approve($reason): the request only runs after a human approves it through Laravel AI's nativeApprovableandneedsApproval()flow
If you already know Laravel AI's approval flow from elsewhere, there is nothing new to learn here. Decision::approve() is just this package's way of telling that same flow when to kick in.
The callback must return a Decision or a bool. Returning null, or anything else, throws an InvalidArgumentException.
If you have no opinion on a request, return Decision::accept() or true explicitly rather than falling through.
$appliers are the fully validated, already-built Applier instances for this specific request, one per matched handler such as where, select, distinct, groupBy, orderBy, with, or withAggregate. That lets the callback decide based on what the query is actually about to do, not just what the raw request claimed.