Stop writing JSON boilerplate for your AI agents.
toolify-ai is a lightweight, dependency-free Python library that automatically generates OpenAI-compatible tool schemas from your Python functions and classes. It handles type hints, docstrings, and complex types so you can focus on building agents, not wrestling with JSON.
- Zero Boilerplate: Define your tools as Python functions with type hints and docstrings. Toolify does the rest.
- Type-Safe: Full support for standard Python types (
str,int,bool,float,list,dict) and Pydantic models. - Universal: Generates schemas compatible with OpenAI, Anthropic, and other function-calling LLMs.
- Lightweight: No heavy dependencies. Just install and go.
pip install toolify-aiJust write a standard Python function with type hints and a docstring.
from toolify import toolify
@toolify
def get_weather(location: str, unit: str = "celsius") -> dict:
"""
Get the current weather for a given location.
Args:
location (str): The city and state, e.g. San Francisco, CA.
unit (str): The temperature unit to use ('celsius' or 'fahrenheit').
"""
# ... implementation ...
passToolify automatically converts it to the JSON schema expected by the LLM.
import json
from toolify import get_schema
schema = get_schema(get_weather)
print(json.dumps(schema, indent=2))Output:
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA."
},
"unit": {
"type": "string",
"description": "The temperature unit to use ('celsius' or 'fahrenheit').",
"enum": ["celsius", "fahrenheit"],
"default": "celsius"
}
},
"required": ["location"]
}
}
}Toolify seamlessly integrates with Pydantic for complex data structures.
from pydantic import BaseModel, Field
from toolify import toolify
class SearchQuery(BaseModel):
query: str = Field(..., description="The search query")
limit: int = Field(10, description="Max number of results")
@toolify
def search_web(params: SearchQuery):
"""Search the web for information."""
passWe welcome contributions! Please check out our Contributing Guide for details.
MIT License. See LICENSE for more information.