pub trait ToolFunction: Send + Sync {
// Required method
fn execute<'life0, 'async_trait>(
&'life0 self,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<ToolResult, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn validate_input(
&self,
_input: &Value,
) -> Result<(), Box<dyn Error + Send + Sync>> { ... }
fn timeout_seconds(&self) -> u64 { ... }
}
Expand description
Trait for implementing tool functions.
This trait allows you to define custom tools that Claude can call. Each tool receives structured input and returns a structured result.
Required Methods§
Provided Methods§
Sourcefn validate_input(
&self,
_input: &Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
fn validate_input( &self, _input: &Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
Validate input before execution (optional).
Override this method to provide custom validation logic beyond the JSON schema validation.
Sourcefn timeout_seconds(&self) -> u64
fn timeout_seconds(&self) -> u64
Get the tool’s timeout in seconds (optional).
Override to set a custom timeout for this tool. Default is 30 seconds.