Parameter Types, Tool Descriptions, and Additional Customization
Type Coercion and Validation
FastMCP validates tool arguments using Pydantic before your function runs. Pydantic's default (lax) mode performs safe type conversions when possible.
LLMs generally send correct JSON types because they receive the tool's JSON Schema, but coercion acts as a safety net. Invalid conversions fail validation and return an error before your tool runs.
To put it simply, Pydantic plays two roles in FastMCP.
Role 1: At registration time (when
@mcp.toolruns), Pydantic inspects the function signature — type hints likeage: intand constraints likeField(ge=0, le=30)— and generates the JSON Schema (inputSchema
Practical MCP with FastMCP & LangChain
Engineering the Agentic ExperienceEnroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!
