Validation
Validation in R-Think operates at three levels: input validation, step validation, and output validation. Each level ensures data integrity and reasoning correctness before a mission transitions forward.
Validation Levels
Validation is not a single check. It is a layered system that catches errors early and provides context-rich feedback through reason codes.
- Input Validation — Validates observations and claims before they enter the cognitive process.
- Step Validation — Validates the output of each step before passing to the next.
- Output Validation — Validates the final decided result against the mission rules before returning to the caller.
Input Validation
Input validation ensures observations and claims meet the required schema. This prevents invalid data from propagating through the reasoning chain.
import { Runtime, Protocol, Rule } from '@r-think/core';
const mission = Runtime.create({
protocol,
rules: [
Rule.required('observation'),
Rule.type('observation', 'string'),
Rule.type('claims', 'object'),
Rule.required('claims.id')
]
});
// This will fail before the protocol executes
await mission.execute({}); // RuleViolation: observation is required Step Validation
After each step completes, the runtime validates the step output against step-specific rules. This ensures data quality is maintained throughout the cognitive chain.
Output Validation
Before the runtime returns a result, it validates the final output. This is the last line of defense against invalid reasoning results.