Skip to main content

Propensity API

The propensity router exposes the ML propensity pipeline -- cached predictions, model health, configuration, and the activation workflow that transitions from platform-only scoring to ML-augmented scoring.

Router namespace: propensity

Source: src/server/trpc/routers/propensity.ts

Procedures

ProcedureTypeAccessDescription
getPredictionsquerytenantCached ML propensity scores for an entity type
getModelStatusqueryadminFull model status: AUC, features, training history, data volume
getConfigqueryadminCurrent propensity configuration
updateConfigmutationadminUpdate propensity configuration
activateMLmutationadminActivate ML scoring (requires AUC >= 0.65)
startPreviewmutationadminStart a 7-day side-by-side preview
getEntityPropensityquerytenantFull propensity detail with SHAP values for one entity

getPredictions

Returns cached ML propensity scores for a given entity type. Scores are refreshed on each scoring run.

propensity.getPredictions.queryOptions(input)

Input

FieldTypeRequiredDefaultDescription
entityType"person" | "account" | "opportunity"Yes--Entity type to retrieve predictions for
limitnumber (1-1000)No100Maximum predictions to return

Response

[
{
"entityId": "acc_456",
"entityType": "account",
"propensityScore": 0.82,
"confidence": 0.91,
"predictedAt": "2026-03-05T10:30:00.000Z"
}
]

Example

const trpc = useTRPC();
const { data } = useQuery(
trpc.propensity.getPredictions.queryOptions({
entityType: "account",
limit: 50,
})
);

getModelStatus

Returns comprehensive model health information including AUC, feature importance, training history, and available data volume.

propensity.getModelStatus.queryOptions()

Access: Admin only

Input

None.

Response

{
"isActive": true,
"auc": 0.78,
"lastTrainedAt": "2026-03-04T02:00:00.000Z",
"trainingHistory": [
{ "trainedAt": "2026-03-04T02:00:00.000Z", "auc": 0.78, "samples": 1250 },
{ "trainedAt": "2026-02-25T02:00:00.000Z", "auc": 0.75, "samples": 1100 }
],
"topFeatures": [
{ "name": "engagement_score", "importance": 0.32 },
{ "name": "fit_score", "importance": 0.28 },
{ "name": "days_since_last_activity", "importance": 0.15 }
],
"dataVolume": {
"closedWon": 145,
"closedLost": 312,
"total": 457
}
}

getConfig

Returns the current propensity pipeline configuration.

propensity.getConfig.queryOptions()

Access: Admin only

Input

None.

Response

{
"minClosedWon": 50,
"retrainSchedule": "weekly",
"mlActivated": true,
"propensityWeight": 0.3
}
FieldDescription
minClosedWonMinimum closed-won deals required before ML can activate
retrainScheduleHow often the model retrains ("daily", "weekly", "monthly")
mlActivatedWhether ML scoring is active for this tenant
propensityWeightWeight of propensity score in the combined score (0-1)

updateConfig

Updates propensity pipeline configuration.

propensity.updateConfig.mutationOptions(options)

Access: Admin only

Input

FieldTypeRequiredDescription
minClosedWonnumberNoMinimum closed-won threshold
retrainSchedule"daily" | "weekly" | "monthly"NoRetrain frequency
propensityWeightnumber (0-1)NoWeight in combined score

Response

{ "success": true }

activateML

Activates ML-augmented scoring for the tenant. The model must have an AUC of at least 0.65 to activate. Use preview: true to check eligibility without activating.

propensity.activateML.mutationOptions(options)

Access: Admin only

Input

FieldTypeRequiredDefaultDescription
previewbooleanNofalseIf true, returns eligibility without activating

Response

{
"activated": true,
"auc": 0.78,
"eligible": true,
"reason": null
}
Activation Requirements

Activation fails if the model AUC is below 0.65 or there is insufficient training data. The response includes a reason string explaining the failure.


startPreview

Starts a 7-day side-by-side preview that runs ML scoring in parallel with the platform model without affecting live scores. Use this to evaluate ML quality before activating.

propensity.startPreview.mutationOptions(options)

Access: Admin only

Input

None.

Response

{
"previewStarted": true,
"endsAt": "2026-03-12T10:30:00.000Z"
}

getEntityPropensity

Returns full propensity detail for a single entity including the propensity score, confidence, and SHAP feature explanations.

propensity.getEntityPropensity.queryOptions(input)

Input

FieldTypeRequiredDescription
entityIdstringYesEntity identifier

Response

{
"entityId": "acc_456",
"propensityScore": 0.82,
"confidence": 0.91,
"shapValues": [
{ "feature": "engagement_score", "value": 0.15, "direction": "positive" },
{ "feature": "fit_score", "value": 0.12, "direction": "positive" },
{ "feature": "days_since_last_activity", "value": -0.08, "direction": "negative" }
],
"predictedAt": "2026-03-05T10:30:00.000Z"
}
SHAP Values

SHAP values explain how each feature contributed to the prediction. Positive values push the score up; negative values push it down. The sum of all SHAP values equals the difference from the base rate.