Principle:24kchengYe MemoMind Operation Validation
| Knowledge Sources | |
|---|---|
| Domains | Validation, SaaS |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Pre-operation validation pattern that intercepts expensive operations (retain, recall, reflect, consolidate) to enforce quotas, credits, or business rules before execution.
Description
The Operation Validation pattern defines validation hooks that run before each memory operation. An `OperationValidatorExtension` receives the full operation context (bank_id, request_context, parameters) and either accepts or rejects the operation. This enables usage metering and billing — validating credits/quotas before executing expensive LLM operations. Critical for SaaS deployments where per-tenant resource limits must be enforced.
The pattern solves the problem of coupling business rules (billing, quotas) to core engine logic: validation is a pluggable extension, so the core engine remains agnostic to billing systems.
Usage
Use this principle when building a multi-tenant SaaS system that needs per-operation resource controls. Implement `OperationValidatorExtension` and configure it via `HINDSIGHT_API_OPERATION_VALIDATOR_EXTENSION`.
Theoretical Basis
Validation follows the Guard Clause pattern — early rejection before the operation begins:
# Abstract validator defines per-operation hooks
class OperationValidatorExtension(Extension, ABC):
@abstractmethod
async def validate_retain(self, context: RetainContext) -> ValidationResult: ...
@abstractmethod
async def validate_recall(self, context: RecallContext) -> ValidationResult: ...
# Concrete implementation enforces business rules
class CreditValidator(OperationValidatorExtension):
async def validate_retain(self, context):
if not has_credits(context.request_context):
return ValidationResult.reject("Insufficient credits")
return ValidationResult.accept()