Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

5. What is a tool schema and how is it defined?

A tool schema is a structured definition that describes how a tool (i.e., a callable function or API) should be used by an LLM agent. It includes details like the toolโ€™s name, purpose, required inputs, and expected output format. Tool schemas enable LLMs to make informed decisions about when and how to invoke external tools.

In platforms like OpenAI, LangChain, or CrewAI, tool schemas are often expressed in JSON or Python objects and follow a well-defined structure to ensure interoperability with the LLMโ€™s reasoning engine.

๐Ÿ“ Components of a Tool Schema

  • Name: A unique identifier for the tool (e.g., getWeather).
  • Description: Human-readable purpose statement so the LLM knows when to use it.
  • Parameters: Input fields the tool accepts โ€” names, types, and optionally descriptions.
  • Required Fields: Specifies which parameters must be present.

๐Ÿงพ JSON Schema Example

{
  "name": "getCryptoPrice",
  "description": "Retrieve the current price of a given cryptocurrency.",
  "parameters": {
    "type": "object",
    "properties": {
      "symbol": {
        "type": "string",
        "description": "The ticker symbol, e.g., BTC, ETH"
      }
    },
    "required": ["symbol"]
  }
}

๐Ÿ Python Definition (LangChain Style)

def get_crypto_price(symbol: str) -> str:
    """Retrieve current price of a given crypto coin."""

๐Ÿ“ฆ Schema Usage in Practice

  • Used by the LLM to determine which tool matches a given task.
  • Parsed by the orchestrator to validate and structure requests.
  • Displayed in developer-facing UI or model logs for clarity.

๐Ÿ”’ Validation & Security

  • Schemas enforce correct input typing (string, number, object, etc.).
  • Minimize ambiguity in tool descriptions to prevent misuse.
  • Combine with access controls to restrict tool invocation by user/session.

๐Ÿ’ก Pro Tips

  • Use clear naming โ€” both for the tool and its parameters.
  • Include descriptive text that helps the model understand appropriate use cases.
  • Group related tools into modules if exposing many endpoints.

๐Ÿš€ Summary

A tool schema is the interface contract between the agent and its available capabilities. By defining the โ€œwhatโ€ and โ€œhowโ€ of external function usage, it allows LLMs to invoke the right tool at the right time โ€” enabling safe, structured, and extensible tool-based reasoning.