Skip to main content

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

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

Check required parameters and basic types before doing any processing.
Error messages should tell users exactly what’s wrong and how to fix it.
Include suggestion in error results to help users fix issues.
Enforce min/max lengths, ranges, and patterns to prevent edge cases.