R-Think

Validation

Validation in R-Think operates at three levels: input validation, step validation, and output validation. Each level ensures data integrity and reasoning correctness.

Validation Levels

Validation is not a single check. It is a layered system that catches errors early and provides context-rich feedback.

  1. Input Validation - Validates data before it enters the protocol.
  2. Step Validation - Validates the output of each step before passing to the next.
  3. Output Validation - Validates the final result before returning to the caller.

Input Validation

Input validation ensures the data entering a protocol meets the required schema. This prevents invalid data from propagating through the reasoning chain.

input-validation.ts typescript
const runtime = Runtime.create({
  protocol,
  rules: [
    Rule.required('requestId'),
    Rule.type('requestId', 'string'),
    Rule.type('payload', 'object'),
    Rule.required('payload.data')
  ]
});

// This will fail before the protocol executes
await runtime.execute({}); // RuleViolation: requestId 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 reasoning 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.

Validation is Mandatory

Validation cannot be disabled in production mode. Skipping validation is only available in development mode with explicit configuration.