Concepts
Tool
Create validated, structured functions that can be used safely by LLM agents.
Overview
The Tool
class allows you to wrap Python functions—synchronous or asynchronous—with input validation, rich metadata, and compatibility with LLM agent frameworks such as LangChain.
It enables:
- Pydantic-based input validation
- Safe execution of async and sync functions
- Metadata generation for prompt or UI integration
- Seamless conversion to LangChain
StructuredTool
Basic Usage
Simple Sync Function
With Async Function
Input Validation with Pydantic
You can provide a schema to ensure input data is validated before execution.
Attributes
Name | Type | Description |
---|---|---|
name | str | Unique identifier for the tool |
description | str | Used in UIs and LLM prompt construction |
func | Callable | The actual function (sync or async) to execute |
input_schema | Optional[BaseModel] | Pydantic schema for validating and describing tool inputs |
raise_on_error | bool (default=True) | If False , will suppress exceptions and log errors |
Metadata via describe()
LangChain Integration
Error Handling
If validation fails, a ToolInputValidationError
will be raised with detailed information:
Real-World Example
Best Practices
- Keep tool functions pure and stateless
- Always define an input schema for clarity and safety
- Use
describe()
to integrate with UIs or LLM-based planning systems - Avoid side effects inside tool logic (e.g. file writes or database mutations)
Interface Summary
Tools are the building blocks for agent autonomy. Define them clearly, validate inputs properly, and structure them for reusability. They integrate seamlessly into the Chainless Agent and TaskFlow system for powerful orchestration.