Tool Input Validator

Easy
Agents

Validate and normalize tool parameters against a schema:

  1. Check all required params are present
  2. Validate types match (str, int, float, bool)
  3. Apply default values for missing optional params
  4. Return normalized params with defaults applied

Type Conversion:

  • Try to convert values to correct type
  • '123' → 123 for int type
  • 'true' → True for bool type

Error Format: {'param': 'name', 'error': 'description'}

Examples

Example 1:
Input: validate_tool_input({'name': 'test'}, {'name': {'type': 'str', 'required': True}})
Output: {'valid': True, 'errors': [], 'normalized_params': {'name': 'test'}}
Explanation: Required param present, correct type
Example 2:
Input: validate_tool_input({}, {'count': {'type': 'int', 'required': False, 'default': 5}})
Output: {'valid': True, 'errors': [], 'normalized_params': {'count': 5}}
Explanation: Missing optional param, default applied

Starter Code

def validate_tool_input(params, schema):
    """
    Validate tool parameters against a JSON-like schema.
    
    Schema format:
    {
        'param_name': {'type': 'str|int|float|bool', 'required': True/False, 'default': val},
        ...
    }
    
    Returns:
        dict with 'valid' (bool), 'errors' (list), 'normalized_params' (dict)
    """
    # Your implementation here
    pass
Lines: 1Characters: 0
Ready
The AI Interview - Master AI/ML Interviews