Validation
CTP provides built-in validation for tool definitions, inputs, and outputs.Definition Validation
Validate tool definitions against the CTP schema:Validation Result
Common Validation Errors
| Code | Message | Fix |
|---|---|---|
MISSING_REQUIRED | Required field missing | Add the required field |
INVALID_ID | ID must be lowercase hyphen-separated | Use format my-tool-name |
INVALID_CATEGORY | Unknown category | Use one of 8 valid categories |
DUPLICATE_PARAMETER | Parameter name already used | Use unique parameter names |
Input Validation
Validate parameters before execution:Automatic Runtime Validation
The runtime can validate automatically:Parameter Constraints
String Validation
Number Validation
File Validation
Manual Validation in Tools
Implement validation in your tool function:Result Validation
Validate tool output:Result Requirements
Validation Helper Functions
Schema Validation
Use JSON Schema for advanced validation:Best Practices
Validate Early
Validate Early
Check required parameters and basic types before doing any processing.
Provide Clear Messages
Provide Clear Messages
Error messages should tell users exactly what’s wrong and how to fix it.
Use Suggestions
Use Suggestions
Include
suggestion in error results to help users fix issues.Validate Constraints
Validate Constraints
Enforce min/max lengths, ranges, and patterns to prevent edge cases.