validate_responses

Function validate_responses 

Source
pub fn validate_responses(
    context: &mut Context,
    responses: HashMap<Arc<str>, Response>,
) -> usize
Expand description

Validates inference responses and assigns them to matching assignment rules in an AIM structure.

This function processes a collection of parsed inference responses and assigns them to corresponding assignment rules in the AIM structure. Assignment rules are identified by all-lowercase identifiers (e.g., summary, temperature). For a lowercase rule foo, its uppercase form FOO is used to match against parsed response keys.

§Process

The validation follows a systematic workflow:

  1. Rule Enumeration - Iterates through all rules in the AIM structure
  2. Assignment Detection - Identifies rules with lowercase identifiers
  3. Identifier Conversion - Converts rule identifiers to uppercase for matching
  4. Response Matching - Finds responses with matching uppercase identifiers
  5. Type Validation - Validates responses against rule type definitions
  6. Value Assignment - Assigns validated values through the execution context

§Fault Tolerance

The validation process is intentionally fault-tolerant to handle the probabilistic nature of AI model responses:

  • Non-matching Responses: Silently ignores responses without matching assignment rules
  • Type Validation Failures: Silently ignores responses that fail type conversion
  • Partial Success: Returns success if at least one response is validated

This design ensures that workflows continue even when some inference responses are malformed or unexpected.

§Parameters

  • context - A mutable reference to the execution context for value assignment
  • responses - A HashMap of parsed responses, keyed by uppercase identifiers

§Returns

  • usize - Number of successfully validated and assigned responses