Custom Policies
Verdict lets you write your own custom policies. Under the hood, verdict uses the Rego language for decisions.
Decision
As mentioned before, the central idea here is a decision. To create a decision, you can call the build_decision
function in the sencillo package. This handles building the response and setting the status for you.
Overriding Decisions
Default decisions can be overridden by simply importing the relevant auto
package. Here we are saying if legalName
is “Jim’s Trucking” we will allow the request even if the auto package denies it. We can simply call sencillo.build_decision
which handles building the decision object and setting the status based on the data.
Here are two examples of how to do this:
Example 1
In this example we store the decision in an object called sencillo_decision
and then we return our own decision object. The last section sets our allowed value to be true if the legal name matches “Jim’s Trucking” or if it doesn’t, the value returned by the sencillo_decision
.
package custom
import data.sencillo
import data.sencillo.underwriting.auto.fmcsa.business
denials := business.denials
referrals := business.referrals
errors := business.errors
sencillo_decision := sencillo.build_decision(denials, referrals, errors)
decision := {
"allowed": allowed,
"referrals": sencillo_decision.referrals,
"denials": sencillo_decision.denials,
"errors": sencillo_decision.errors,
"status": sencillo_decision.status,
}
allowed if {
input.dotData.carrier.legalName == "Jim's Trucking"
} else := sencillo_decision.allowed
Example 2
In this example we have more control over the denials and referrals. If the legal name is not “Jim’s Trucking” we use the values returned by the business package. If it is Jim’s trucking we set denials
and referrals
to be empty. These overridden sets are then passed to the build_decision
function which returns allowed
.
package custom
import data.sencillo
import data.sencillo.underwriting.auto.fmcsa.business
# If the name is equal to Jim's trucking we need to set denials to an empty set
denials := business.denials if {
input.dotData.carrier.legalName != "Jim's Trucking"
} else := []
# Another option to set referrals to empty if the value matches
default referrals := set()
referrals := business.referrals if {
input.dotData.carrier.legalName != "Jim's Trucking"
}
errors := business.errors
decision := sencillo.build_decision(denials, referrals, errors)
If this sample payload is passed usig the custom policy above, a referral decision is returned:
Request
{
"effectiveDate": "2024-01-01",
"dotData": {
"carrier": {
"censusTypeId": {
"censusType": "C",
"censusTypeDesc": "CARRIER"
},
"carrierOperation": {
"carrierOperationDesc": "Interstate"
},
"dotNumber": 1234,
"statusCode": "A",
"legalName": "SOME TRUCKING LLC",
"mcs150Outdated": "N",
"allowedToOperate": "Y",
"phyState": "PA",
"driverOosRate": 6,
"driverOosRateNationalAverage": "5.51",
"hazmatOosRate": 0,
"hazmatOosRateNationalAverage": "4.5",
"vehicleOosRate": 0,
"vehicleOosRateNationalAverage": "20.72"
},
"cargo": [
{
"cargoClassDesc": "Swimming Pools"
}
],
"operations": [
{
"operationClassDesc": "Authorized For Hire"
}
]
}
}
Response
{
"allowed": false,
"denials": [],
"errors": [],
"referrals": [
"driver OOS rate of 6 is higher than national average of 5.51"
],
"status": "Referred"
}
However, based on the custom policy, if we pass the same payload but chang the business name to Jim's Trucking
, an approval ("allowed": true
) is returned:
Request
{
"effectiveDate": "2024-01-01",
"dotData": {
"carrier": {
"censusTypeId": {
"censusType": "C",
"censusTypeDesc": "CARRIER"
},
"carrierOperation": {
"carrierOperationDesc": "Interstate"
},
"dotNumber": 1234,
"statusCode": "A",
"legalName": "Jim's Trucking",
"mcs150Outdated": "N",
"allowedToOperate": "Y",
"phyState": "PA",
"driverOosRate": 6,
"driverOosRateNationalAverage": "5.51",
"hazmatOosRate": 0,
"hazmatOosRateNationalAverage": "4.5",
"vehicleOosRate": 0,
"vehicleOosRateNationalAverage": "20.72"
},
"cargo": [
{
"cargoClassDesc": "Swimming Pools"
}
],
"operations": [
{
"operationClassDesc": "Authorized For Hire"
}
]
}
}
Response
As mentioned earlier, this response only contains the referral data if you do NOT override the arrays being passed to build_decision
demonstrated in the second example.
{
"allowed": true,
"denials": [],
"errors": [],
"referrals": [
"driver OOS rate of 6 is higher than national average of 5.51"
],
"status": "Referred"
}