Parameter Validation
All parameters are validated before SQL execution to ensure type safety, constraint compliance, and security. This validation process prevents errors and protects against SQL injection attacks.Parameter validation happens automatically—you just need to define constraints in your tool configuration. The server handles all validation logic.
Validation Process
Parameters go through a four-step validation process before being bound to SQL statements:1. Type Validation
What it checks: Values must match the declared type (string, integer, float, boolean, or array)
Examples:
2. Constraint Validation
What it checks: Values must satisfy all defined constraints (min/max, length, pattern, enum) String Constraints:- minLength / maxLength
- pattern
- enum
- Integer min/max
- Float min/max
3. SQL Security
What it does: Parameters are bound securely using prepared statements to prevent SQL injection How it works:- Parameter Binding
- Array Expansion
Your YAML configuration:What happens internally:
- SQL is prepared with placeholders:
SELECT * FROM SAMPLE.EMPLOYEE WHERE EMPNO = ? AND WORKDEPT = ? - Parameters are bound safely:
employee_id→ first?,department→ second? - Values never concatenated into SQL string
- SQL injection attempts fail automatically
4. Required Check
What it checks: Required parameters must be provided (unless they have default values) Examples:Common Validation Errors
Type Mismatch Errors
| Error Message | Cause | Solution |
|---|---|---|
Expected integer, got string | Passed "100" instead of 100 | Remove quotes from numbers |
Expected string, got integer | Passed 100 instead of "100" | Add quotes around strings |
Expected boolean, got string | Passed "true" instead of true | Use boolean literals |
Expected array, got string | Passed "A,B,C" instead of ["A","B","C"] | Use JSON array format |
Range/Length Errors
| Error Message | Cause | Solution |
|---|---|---|
Value X is less than minimum Y | Number below min constraint | Increase value to meet minimum |
Value X exceeds maximum Y | Number above max constraint | Decrease value to meet maximum |
String length X is less than minimum Y | String too short | Add more characters |
String length X exceeds maximum Y | String too long | Shorten the string |
Pattern/Enum Errors
| Error Message | Cause | Solution |
|---|---|---|
Value does not match pattern: ... | String doesn’t match regex | Follow the required format |
Value 'X' must be one of: ... | Value not in enum list | Use one of the allowed values |
Required Parameter Errors
| Error Message | Cause | Solution |
|---|---|---|
Required parameter 'X' not provided | Missing required parameter | Include the parameter in request |
Parameter 'X' is required | NULL value for required param | Provide a non-NULL value |
Security Benefits
SQL Injection Prevention
Parameter binding provides automatic SQL injection protection:How SQL Injection Attacks Fail
How SQL Injection Attacks Fail
Malicious Input Attempt:What happens:
- Value treated as literal string:
'000010' OR '1'='1' - Compared against
EMPNOcolumn as-is - No match found (no employee with that literal ID)
- Query returns empty result set
- Attack fails - SQL is never modified
- Parameters are bound, not concatenated
- Special characters like
'are escaped automatically - SQL structure cannot be altered through parameters
Type Safety
Type validation prevents data corruption and unexpected errors:Type Safety Benefits
Type Safety Benefits
- Prevents crashes: No runtime type errors from invalid data
- Ensures consistency: Database columns receive correct data types
- Catches bugs early: Invalid data rejected before query execution
- Improves debugging: Clear error messages identify problems immediately
Constraint Enforcement
Constraints protect against invalid business logic:Constraint Benefits
Constraint Benefits
- Range limits: Prevent nonsensical values (negative ages, 200% CPU usage)
- Format validation: Ensure IBM i naming conventions are followed
- Enum restrictions: Limit choices to valid options
- Length limits: Prevent buffer overflows and excessive data
Debugging Validation Errors
Reading Error Messages
Validation errors follow a consistent format:- Parameter name: Which parameter failed validation
- Error description: Why validation failed
- Context: Expected vs. actual values
Common Debugging Steps
1
Check the parameter type
Ensure you’re passing the correct JSON type (number vs. string, array vs. string)
2
Review constraints
Check min/max, length, pattern, and enum constraints in the tool definition
3
Verify required parameters
Confirm all required parameters are present in the request
4
Test with simple values
Try minimal valid values to isolate the issue
5
Check special characters
For pattern validation, ensure special characters are allowed
Testing Parameter Validation
Good practice: Test parameter validation before deploying tools:Best Practices
Use Appropriate Constraints
- Don’t over-constrain: Allow reasonable ranges
- Don’t under-constrain: Prevent invalid business logic
- Use enum for fixed value sets
- Use pattern for format validation
Provide Clear Descriptions
- Explain validation rules in descriptions
- Include examples of valid values
- Document special values (*LIBL, etc.)
- Mention units for numeric parameters
Test Edge Cases
- Test minimum and maximum values
- Test boundary conditions
- Test with NULL values
- Test with empty strings/arrays
Handle Optional Parameters
- Use defaults for common values
- Check for NULL in SQL when needed
- Document optional parameter behavior
- Consider making parameters required if critical