Defining Tools: Pydantic Schemas and the BaseTool Pattern
~15 min read
The book's CrewAI CurrencyConverterTool example shows the standard shape every custom tool follows: a Pydantic input schema defining exactly what arguments the tool needs, plus a BaseTool subclass that wires that schema to the actual logic.
Defining Tools: Pydantic Schemas and the BaseTool Pattern is a Pro topic
Sign in, then upgrade to Pro or Power to unlock this topic and the full AI Engineering curriculum.
Key points
- •Defining a tool starts with a Pydantic schema specifying exactly what typed arguments it expects
- •Pydantic validates incoming arguments against these types before the tool's logic runs, catching malformed input early
- •A BaseTool subclass wires that schema to the actual logic, and carries the tool's name and description
- •The description matters enormously — it's what the LLM reads to decide when a tool is relevant, covered in the next subtopic
- •This typed-schema-plus-execution-class pattern is common across agent frameworks and even MCP's own tool definitions