Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 4

Crafting Robust Tool Descriptions for LLM Reliability

Recommended resources

Introduction

In our previous lessons, we've constructed the essential execution engine for an agent, enabling it to call single functions and even execute multiple independent functions concurrently. You now have the machinery for your agent to interact with the world. However, the ability to execute a tool call is only half the story. The agent's reliability hinges on the Large Language Model's ability to choose the right tool and provide the correct parameters, every single time.

This lesson moves from the mechanics of execution to the art and science of instruction. We will focus on how to design the "API contract" for the LLM: the tool descriptions and parameter schemas. You'll learn that poor, ambiguous definitions are a primary source of agent failures, while clear, constrained schemas are the foundation of a robust and predictable system. This is not about prompt engineering in the traditional sense, but about applying rigorous software engineering principles to the interface between the LLM and your code.


The "Why": The High Cost of Ambiguity

When an LLM fails to use a tool correctly, it's rarely due to a fundamental inability to reason. More often, it's a direct result of ambiguity in the tool's definition. Consider the parallels to a distributed system: if an API's documentation is vague or its contract is loose, client services will inevitably make incorrect calls. The LLM is a client service, and your tool schemas are its documentation.

Ambiguous schemas lead to several common failure modes:

  • Incorrect Tool Selection: The LLM calls search_products when it should have called get_order_status.
  • Malformed Parameters: The model provides a user_id as a string when the function expects an integer, or it uses the wrong date format.
  • Hallucinated Arguments: The LLM invents parameters that don't exist, like trying to filter by color when the tool only supports filtering by brand and price.
  • Failure to Act: The LLM doesn't realize a tool is available to answer the user's query and instead attempts to answer from its own knowledge, often incorrectly.

Minimizing these errors is a core task in engineering reliable agents. The goal is to remove ambiguity and provide the model with a crystal-clear understanding of its capabilities.


Anatomy of a High-Quality Tool Schema

A tool schema, typically defined in JSON, has three primary components that you control: the tool's name, its description, and its parameters. While the name is a simple identifier, the description and parameters are where you can exert the most influence over the model's behavior.

Let's dissect these components and learn the best practices for each. The following article provides an excellent reference for the fundamental structure.

LLM Function Calling: Complete Implementation Guide (2026)

This guide includes a quick reference for the standard tool schema structures used by major API providers.

Familiarize yourself with the basic structure by reviewing the two schemas under the "Quick Reference" heading: OpenAI Tool Schema and Anthropic Tool Schema. Note the key fields: name, description, and parameters (or input_schema).

1. The description: Guiding Tool Selection

The description field is arguably the most critical piece of information for ensuring the LLM selects the correct tool. It's the primary "docstring" the model reads to understand a tool's purpose.

A vague description like "Search function" is an invitation for errors. A high-quality description is specific and directive.

LLM Function Calling: Complete Implementation Guide (2026)

This section of the guide contrasts good and bad descriptions and outlines what to include in an effective one.

Read the section Writing Effective Descriptions. Pay close attention to the "Bad description" vs. "Good description" example. The good description doesn't just state what the tool is; it specifies when to use it and what it returns.

Based on this, here are key principles for writing effective tool descriptions:

  • State the Action Clearly: Begin with a verb that describes what the tool does (e.g., "Get...", "Search for...", "Update...").
  • Specify the "When": Explicitly guide the model on the conditions for its use. For example: "Use this function when the user asks about weather conditions."
  • Describe the Output: Briefly mention what the function returns. This helps the model understand how the tool's output can be used in subsequent steps. E.g., "...Returns a list of product IDs and their current stock levels."
  • Mention Key Parameters/Capabilities: Hint at important parameters, such as filtering or sorting capabilities. E.g., "Supports filtering by category and price range."

The following video provides a live-coding example where the developer adds descriptive comments to guide the model's use of a memory function.

Function Calling is All You Need — Full Workshop, with Ilan Bigio of OpenAI

In this segment from a workshop by OpenAI's Ilan Bigio, he demonstrates how to instruct the model on when to call a function directly within its description.

Watch from this timestamp. The speaker adds a description: "when the user tells you something like factual about themselves their life or their preferences call this function". This is a perfect example of providing explicit triggers for the tool within the description itself.

2. The parameters: Enforcing Correct Invocation

Once the model has selected the right tool, it must generate the correct parameters. This is where the parameters object, defined using JSON Schema, becomes critical. You can use it to enforce strong typing and constraints, leaving no room for the LLM to guess.

LLM Function Calling: Complete Implementation Guide (2026)

This section details how to use JSON Schema features to constrain tool inputs, which is essential for preventing invocation errors.

Read the section Parameter Constraints. This demonstrates several powerful JSON Schema features: Type enforcement ("type": "integer") Value ranges ("minimum": 1, "maximum": 100) Enumerations ("enum": ["pending", "shipped"]) to restrict choices. Nested objects to structure complex parameters like a date range.

For each parameter, always include a description. This is as important as the tool's main description. It should explain the parameter's purpose and, critically, its expected format (e.g., "The start date for the search, in YYYY-MM-DD format.").

As schemas become more complex, writing them by hand in JSON can be cumbersome and error-prone. A common and robust practice is to define them programmatically using a library like Pydantic, which leverages Python's type hints to generate the JSON Schema for you.

LLM Function Calling - AI Tools Deep Dive

This video shows a practical example of using Pydantic to define a complex tool schema, moving from raw JSON to a more organized, type-safe Python class.

Watch the segment from defining complex functions. The presenter defines an EmailCampaign class with complex types like Optional[List[HttpUrl]] and Dict. Notice how this Python class is then used to generate a rich, detailed JSON schema that would be tedious to write manually. This approach combines Python's readability with the strictness of JSON Schema.

3. Forcing Compliance: Strict Mode

Even with a perfect schema, some models might occasionally produce outputs that are almost correct—perhaps including an extra field. For production systems, you need guarantees. Many APIs now offer a "strict" mode that forces the model's output to conform exactly to your schema.

LLM Function Calling: Complete Implementation Guide (2026)

This section explains how to use features that enforce strict schema compliance.

Read the section Structured Outputs with Strict Mode. The key takeaways are the strict: True flag and the requirement of "additionalProperties": false. Using these ensures the model cannot add extraneous fields or deviate from the defined types, significantly increasing reliability.


Architectural Patterns for Reducing Errors

Beyond designing individual tools, your system's architecture plays a huge role in minimizing invocation errors. As a systems architect, these patterns should be central to your design philosophy.

An excellent paper from arXiv, "A Practical Guide for Designing, Developing, and Deploying...", outlines several best practices derived from building production agentic workflows.

Pattern 1: Single Responsibility Principle for Agents

A common mistake is to overload a single agent with dozens of tools. This forces the LLM to perform a complex selection process, increasing "cognitive load" and the probability of error. A more robust pattern is to design specialized agents, each with a single, well-defined responsibility and a minimal set of tools.

A Practical Guide for Designing, Developing, and ...

This paper makes a strong, evidence-based case for designing agents with a single responsibility and a single tool to improve reliability.

First, read section 3.3 Avoid Overloading Agents. The authors describe how an agent with two tools (scrape_markdown, publish_markdown) would often fail, and how splitting it into two separate agents solved the problem. Next, read section 3.4 Single-Responsibility Agents. This extends the idea, showing how an agent tasked with both generating a JSON spec and generating a video led to malformed outputs. Separating these concerns into a JSON-builder agent and a deterministic video-generation function made the system robust.

Pattern 2: Pure Functions vs. Tool Calls

Not every action needs to be a tool call. If an operation is deterministic and doesn't require language-based reasoning (e.g., writing a file, posting data to an API endpoint whose payload is already known), it should be a "pure function" executed by your orchestrator code, not a tool delegated to the LLM.

This eliminates an entire class of potential failures, reduces token costs, and lowers latency. Reserve LLM tool calls for tasks that truly need them, such as interpreting natural language to formulate a database query.

A Practical Guide for Designing, Developing, and ...

This section explains the trade-offs and recommends using direct function calls for deterministic, non-reasoning tasks.

Read section 3.2 Direct Function Calls. The key insight is that invoking a create_github_pr function directly from the workflow controller is more reliable than having an agent formulate the tool call, because it removes the LLM's interpretation step.

Pattern 3: Managing Large Toolsets with Routers and Namespaces

What if your system genuinely requires access to many tools? The "one agent, one tool" principle can lead to a large number of specialized agents. The solution is to introduce a routing or triage layer.

A top-level "triage agent" can be given a small set of functions whose only job is to hand off the task to the appropriate specialized agent.

Function Calling is All You Need — Full Workshop, with Ilan Bigio of OpenAI

The presenter addresses the problem of managing hundreds of functions and demonstrates a live implementation of a triage agent that routes tasks to other agents.

Watch from this timestamp. The speaker outlines several strategies, but focuses on the router pattern. He defines a triage_agent whose only tools are transfer_to_email_agent and transfer_to_calendar_agent. This approach keeps the toolset for any single LLM call small and focused, dramatically reducing ambiguity.

Another, simpler technique is to use namespaces in your tool names. This helps the model disambiguate between similarly named functions in different domains.

LLM Function Calling: Complete Implementation Guide (2026)

This section offers a simple yet effective way to organize tools in complex systems.

Read the section Schema Organization. The example of naming tools crm.search_contacts and billing.get_invoice shows how a simple prefix can provide crucial context to the model.


Conclusion

In this lesson, we've established that the reliability of an agent is not an emergent property but a result of deliberate, careful engineering. By treating tool schemas as a formal API contract with the LLM, we can drastically reduce invocation errors and build more predictable systems.

Here are the key takeaways:

  • Descriptions are for Selection: Use detailed descriptions to tell the LLM what a tool does and, more importantly, when to use it.
  • Parameters are for Enforcement: Leverage the full power of JSON Schema—types, enums, value ranges, and detailed descriptions for each parameter—to constrain the LLM's output and prevent malformed calls.
  • Embrace Architectural Principles: Structure your system using patterns like single-responsibility agents and pure functions to reduce the LLM's "cognitive load" and eliminate unnecessary points of failure.
  • Organize for Scale: For complex systems with many tools, use routing agents or simple namespaces to maintain clarity and prevent ambiguity.

So far, our agent interactions have been stateless, single-turn exchanges. In the next lesson, we will address a crucial component of agentic behavior: managing multi-turn conversation state using message histories. This will allow our agent to remember past interactions, build context over time, and engage in meaningful, coherent dialogues.