Quick Start
How It Works
The agent converts your Python type annotations into JSON Schema before the LLM sees the tool definition.| Python Annotation | JSON Schema Output |
|---|---|
str, int, float, bool | {"type": "string"} and related primitives |
Optional[int] | {"anyOf": [{"type": "integer"}, {"type": "null"}]} |
Union[str, int] | {"anyOf": [{"type": "string"}, {"type": "integer"}]} |
Literal["fast", "deep"] | {"type": "string", "enum": ["fast", "deep"]} |
| Enum subclass (str-valued) | {"type": "string", "enum": ["low", "medium", "high"]} |
List[int] | {"type": "array", "items": {"type": "integer"}} |
Dict[str, int] | {"type": "object", "additionalProperties": {"type": "integer"}} |
Common Patterns
Mode Flags with Defaults
Shared Choice Sets
Structured Collections
Best Practices
Prefer Optional types over bare parameters
Prefer Optional types over bare parameters
Use
Optional[int] with a default of None instead of leaving parameters untyped. This tells the agent the parameter can be omitted and what type to use when provided.Use Literal for small fixed sets, Enum for reusable choices
Use Literal for small fixed sets, Enum for reusable choices
Choose
Literal[...] when values are unique to one tool. Use Enum when the same choices appear across multiple tools.Parameterize your collections
Parameterize your collections
Write
List[str] instead of bare list so the agent knows what elements to include.Related
Tool Schema Validation
Validate tool schemas and catch type errors
Custom Tools Guide
Complete guide to creating custom tools
Dynamic Tool Schemas
Generate schemas dynamically at runtime
Different Ways to Create Tools
Explore all methods for tool creation

