Quick Start
How It Works
| Phase | What Happens |
|---|---|
| @tool decoration | Validates schema structure and JSON compatibility |
| Agent creation | Checks for duplicate names across tool list |
| LLM interaction | Clean, validated schemas prevent runtime errors |
What Gets Checked
| Check | What it catches |
|---|---|
parameters.type present | Missing schema scaffold |
parameters.properties present | Most common OpenAI-incompatible bug |
get_schema() returns {type: "function", function: {...}} | Wrong top-level shape |
function.parameters is a dict with properties | Inner shape broken |
| JSON round-trip preserves structure | Non-serializable values (functions, sets, etc.) |
required is a list when present | Common typo (string instead of list) |
| Unique names across a list | Duplicate registration |
| Complex type annotations | Optional, Union, Literal, Enum, parameterized List/Dict translated to proper JSON Schema |
Common Errors & Fixes
Missing 'properties' field
Missing 'properties' field
Error: Fix:
'parameters' must have a 'properties' field for OpenAI compatibilityBroken Code:Bad get_schema() return shape
Bad get_schema() return shape
Error: Fix:
get_schema() must return schema with type='function'Broken Code:Non-JSON-serializable default values
Non-JSON-serializable default values
Error: Fix:
Schema round-trip validation failedBroken Code:Duplicate tool names
Duplicate tool names
Error: Fix:
Duplicate tool name 'search' found in tool listBroken Code:Behavior of @tool Validation Failures
Best Practices
Type every tool parameter
Type every tool parameter
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.Write a docstring the model can read
Write a docstring the model can read
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.
Watch the logs for validation warnings
Watch the logs for validation warnings
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.Prefer supported parameter types
Prefer supported parameter types
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.Related
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

