The precheck function provides fast, local validation before committing to expensive Lit Action execution. It’s your Policy’s first line of defense against invalid requests.
The precheck function is executed locally by the Vincent Ability executor to provide a best-effort check that the policy shouldn’t fail when the policy’s evaluate function is called.
Function Parameters
The precheck function receives two parameters:
Object containing the ability and user parameters Parameters matching your abilityParamsSchema
definition
Parameters matching your userParamsSchema
definition
Context object provided by the SDK with helpers and metadata The IPFS CID of the Vincent Ability that is being executed
The ID of the Vincent App the Vincent Ability is being executed for
The version of the Vincent App the Vincent Ability is being executed for
Information about the execution delegation The Ethereum address of the Vincent Ability executor
User’s Vincent Wallet information The token ID of the Vincent App User’s Vincent Wallet
The Ethereum address of the App User’s Vincent Wallet
The public key of the App User’s Vincent Wallet
Helper method for returning an allow result from your policy’s precheck function
Helper method for returning a deny result from your policy’s precheck function
Response Schemas
Allow Response
precheckAllowResultSchema
A Zod schema that defines the structure of successful precheck results. Include details about why the precheck passed, such as current spending limits and remaining quotas.
Deny Response
A Zod schema that defines the structure of failed precheck results. Include details about why the precheck failed, such as exceeded limits or disallowed tokens.
Example Implementation
import { createVincentPolicy } from '@lit-protocol/vincent-ability-sdk' ;
import { z } from 'zod' ;
const vincentPolicy = createVincentPolicy ({
// ... other policy definitions
precheck : async ({ abilityParams , userParams }, policyContext ) => {
const { amount , tokenAddress } = abilityParams ;
const { dailySpendingLimit , allowedTokens } = userParams ;
const isTokenAllowed = allowedTokens . includes ( tokenAddress );
const { isSpendingLimitExceeded , currentDailySpending } = await checkSpendingLimit (
tokenAddress ,
amount ,
dailySpendingLimit ,
);
if ( ! isTokenAllowed ) {
return policyContext . deny ({
reason: 'Token not allowed' ,
maxDailySpendingLimit: dailySpendingLimit ,
currentDailySpending ,
allowedTokens: allowedTokens ,
});
}
if ( isSpendingLimitExceeded ) {
return policyContext . deny ({
reason: 'Spending limit exceeded' ,
maxDailySpendingLimit: dailySpendingLimit ,
currentDailySpending ,
allowedTokens: allowedTokens ,
});
}
return policyContext . allow ({
maxDailySpendingLimit: dailySpendingLimit ,
currentDailySpending ,
allowedTokens: allowedTokens ,
});
},
});
Best Practices
Validate Early - Check user parameters first before expensive operations
Return Helpful Context - Include current state information in responses
Handle Errors Gracefully - Provide clear error messages for debugging
Keep It Fast - Avoid expensive blockchain calls in precheck
Next Steps