pub fn validate_responses(
context: &mut Context,
responses: HashMap<Arc<str>, Response>,
) -> usizeExpand 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:
- Rule Enumeration - Iterates through all rules in the AIM structure
- Assignment Detection - Identifies rules with lowercase identifiers
- Identifier Conversion - Converts rule identifiers to uppercase for matching
- Response Matching - Finds responses with matching uppercase identifiers
- Type Validation - Validates responses against rule type definitions
- 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 assignmentresponses- AHashMapof parsed responses, keyed by uppercase identifiers
§Returns
usize- Number of successfully validated and assigned responses