Skip to content

Tool Schema Generation

Definition

Tool Schema Generation — the process of automatically generating JSON Schema that describes the parameters and return values of functions that LLMs can call. The schema is generated from the function signature, documentation, or usage examples. This allows LLMs to correctly form function calls without manual description.

Generation Sources

Source Example Advantages
Function signature def search(query: str, limit: int = 10) Type accuracy
Docstring """Search the database""" Semantic description
Usage examples search("AI", limit=5) Account for real usage
Type annotations query: str Validation at compile time

Example Schema

{
  "name": "search",
  "description": "Search documents by query",
  "parameters": {
    "type": "object",
    "properties": {
      "query": {"type": "string"},
      "limit": {"type": "integer", "default": 10}
    },
    "required": ["query"]
  }
}

See also