Skip to main content
Schema validation catches broken custom tools at import time, before they confuse the LLM at runtime.
The user asks the agent to search; schema validation runs before the tool reaches the LLM.

Quick Start

1

Automatic validation with @tool

2

Explicit validation of a custom BaseTool

3

Validate a list of tools at once


How It Works


What Gets Checked


Common Errors & Fixes

Error: 'parameters' must have a 'properties' field for OpenAI compatibilityBroken Code:
Fix:
Error: get_schema() must return schema with type='function'Broken Code:
Fix:
Error: Schema round-trip validation failedBroken Code:
Fix:
Error: Duplicate tool name 'search' found in tool listBroken Code:
Fix:

Behavior of @tool Validation Failures

When the @tool decorator encounters validation errors, they are logged as warnings, not raised. The tool is still constructed, but may not work properly with the LLM.Check your logs for messages like:
This early detection helps you fix schema issues during development instead of discovering them when the LLM calls the tool.

Best Practices

Validation derives the schema from your function signature, so annotate each parameter (query: str, not bare query). Untyped parameters produce a weak or invalid schema that the LLM may misuse — explicit types give the model a precise contract.
The tool docstring becomes the description the LLM sees. Keep it short and action-oriented (“Search the web.”) so the model knows when to call the tool. A missing docstring leaves the model guessing about intent.
Broken schemas surface at import time as warnings like 'parameters' must have a 'properties' field for OpenAI compatibility. Treat these as errors during development — fix them before shipping rather than discovering the failure when the LLM first calls the tool.
Stick to types the schema round-trip understands (str, int, bool, and typed Optional/Union/Literal/Enum). Exotic or unannotated types can validate loosely and then fail at call time; validated, supported types keep tool calls reliable.

Tool Parameter Types

Use Optional, Union, Literal, Enum in tool parameters

Custom Tools

Learn to create custom BaseTool and @tool implementations

Tool Reliability

Runtime error handling and tool safety patterns

Dynamic Tool Schemas

Generate schemas dynamically at runtime