Writing Tool Instructions for AI Agents

La Lakshmi Priya Updated 07 Nov 2026
9 min read ·Lesson 109 of 140

Tool Descriptions Are Prompts When an agent decides which tool to call and what arguments to pass, it relies almost entirely on text you wrote: each tool's name, its description, the descriptions of its parameters, and the tool guidance in the agent's instructions. Tool descriptions are therefore prompts, and they deserve the same care.

Lesson 78 introduced tool definitions and showed how vague descriptions cause wrong tool choices. This lesson goes deeper into writing tool instructions for agents that use many tools over many steps, where small ambiguities compound:

How to describe a tool completely How to design parameters the model fills correctly How to design results and errors the agent can act on How to describe relationships between tools How to check tool definitions automatically The Anatomy of a Complete Tool Description A strong tool description answers six questions:

Question Example for get_enrollment What does it do? Looks up the current student's enrollment What does it return? Course name, days since purchase, progress percentage When should it be used? Before answering questions about the student's own course, progress, or refund eligibility When should it not be used? Not for general course information (use search_catalog) or for other students What are its limits? Only finds enrollments for the email the student provided Does it change anything? No; it is read-only Example Look up the current student's enrollment by email. Returns the course name, days since purchase, and progress percentage. Use this before answering questions about the student's own course, progress, or refund eligibility. Do not use it for general course information (use search_catalog) or to look up other students. Read-only: it does not change any data. Why Each Part Matters What it returns lets the agent know whether calling the tool will give it what it needs, before calling it. When to use it and when not to are the main inputs to tool selection. "When not" is especially important when tools overlap. Read-only vs side effects tells the agent how careful to be. Tools that change data need explicit confirmation rules. Naming Tools Guideline Good Weak Use verb_object get_enrollment, issue_refund enrollment, refund Make the effect clear from the verb get_, search_, create_, update_, send_ handle_, process_ Keep names consistent across tools get_course, get_enrollment get_course, fetch_enrollment_info Avoid near-duplicates One search_docs search_docs and find_documents Verbs carry meaning: get_ suggests a read, issue_ and send_ suggest actions with consequences. A model reading process_refund cannot tell whether it checks eligibility or sends money.

Designing Parameters Describe Every Parameter, With a Format and an Example "email": { "type": "string", "description": "The email address the student gave in this conversation, e.g. 'asha@example.com'. " "Never guess or construct an email.", } The instruction "never guess or construct" addresses a common failure: agents inventing plausible argument values, such as asha@gmail.com, when the real value is unknown.

Use Enums for Fixed Sets "doc_type": { "type": "string", "enum": ["policy", "faq", "course_page"], "description": "The type of document to search.", } Enums prevent invalid values such as "policies" or "FAQ page" (Lesson 99).

Use Units in Names or Descriptions amount_rupees or "Amount in rupees, as an integer" prevents confusion between rupees and paise, or between amounts with and without tax.

Keep Parameters Few and Necessary Each extra parameter is another value the model must get right. Prefer tools with two or three clear parameters over one tool with ten optional ones.

Make Missing Values Explicit In strict schemas, every parameter is required (Lesson 99). For values that can be unknown, use a nullable type and explain when to use null:

"course_name": { "type": ["string", "null"], "description": "The course name if the student mentioned one; null if they did not.", } Designing Tool Results and Errors What a tool returns is the agent's observation (Lesson 111). Results should be easy for the model to interpret and act on.

Return Structured, Labeled Results {"course": "Django REST APIs", "days_since_purchase": 4, "progress_percent": 12} Field names with units, such as progress_percent, prevent misreading.

Return Errors That Explain What to Do Weak Error Helpful Error "Error 404" {"error": "No enrollment found for this email. Ask the student to confirm the email they used to register."} "Invalid input" {"error": "amount_rupees must be a positive integer, e.g. 4999."} "Failed" {"error": "Payment service is temporarily unavailable. Do not retry more than once; offer a handover."} A helpful error says what went wrong and what to do next. Agents recover much better from errors that suggest an action (Lesson 113).

Keep Results Short Return only what the agent needs. Large results, such as full database records or long documents, increase cost and can distract the agent. Summarize or filter in the tool, not in the prompt.

Describing Relationships Between Tools Individual descriptions cannot explain how tools work together. Put that in the agent's instructions:

Tool order:

  • Before discussing a student's refund, call get_enrollment, then search_docs for the refund policy, and compare them.
  • Call issue_refund only after both checks show eligibility and the student has confirmed.
  • If get_enrollment finds no enrollment, do not call issue_refund; ask the student to check their email, or hand over. Why This Belongs in the Agent Prompt Each tool description describes one tool. Rules about sequence and prerequisites, such as "check before acting", involve several tools and the agent's overall goal. Placing them in the agent's instructions keeps tool descriptions focused and the workflow rules in one place.

How Many Tools? As the number of tools grows, choosing the right one becomes harder, especially when descriptions overlap.

Situation Approach A few distinct tools Provide them all Many tools for different tasks Provide only the tools relevant to the current task or conversation stage Tools with overlapping purposes Merge them, or make the differences explicit in both descriptions Rarely used, risky tools Exclude them unless the task requires them Providing fewer, well-described tools usually produces better tool selection than providing many similar ones.

Checking Tool Definitions Automatically A simple linter, a program that checks for common problems, can review tool definitions before they reach the agent.

import re

def lint_tool(tool: dict) -> list[str]: """Return a list of problems in a tool definition.""" problems = [] name, description = tool.get("name", ""), tool.get("description", "") if not re.fullmatch(r"[a-z]+(_[a-z]+)+", name): problems.append("name should be verb_object in snake_case, e.g. get_course") if len(description) < 60: problems.append("description is too short to explain purpose and usage") if not re.search(r"\buse (this|it) (when|for|whenever)\b", description, re.IGNORECASE): problems.append("description should say when to use the tool") if tool.get("side_effects") and not re.search(r"confirm", description, re.IGNORECASE): problems.append("tool has side effects but does not mention confirmation") for parameter, spec in tool.get("parameters", {}).get("properties", {}).items(): if not spec.get("description"): problems.append(f"parameter '{parameter}' has no description") return problems

tools = [ {"name": "get_course", "description": "Look up a course in the catalog and return its fee and seats left. " "Use this when the user asks about price or availability.", "parameters": {"properties": { "course_name": {"type": "string", "description": "Course name as the user wrote it."}}}}, {"name": "refund", "description": "Refund a payment.", "side_effects": True, "parameters": {"properties": { "payment_id": {"type": "string"}, "amount": {"type": "integer", "description": "Amount in rupees."}}}}, ]

for tool in tools: print(tool["name"], lint_tool(tool)) Output:

get_course [] refund ['name should be verb_object in snake_case, e.g. get_course', 'description is too short to explain purpose and usage', 'description should say when to use the tool', 'tool has side effects but does not mention confirmation', "parameter 'payment_id' has no description"] Code Explanation Name check: requires lowercase words joined by underscores, with at least two words, which encourages the verb_object pattern. refund fails. Description length: a very short description cannot explain purpose, results, and usage. Usage guidance: the description should contain a phrase such as "Use this when". Side effects: side_effects is a field you add to your own tool records (it is not sent to the API). Tools that change data must mention confirmation. Parameters: every parameter needs a description. payment_id has none. Using the Linter Run it in your test suite, so every new or changed tool definition is checked automatically. The checks are simple heuristics: passing them does not guarantee a good description, but failing them reliably identifies weak ones.

Testing Tool Instructions Tool instructions should be tested with realistic requests, measuring:

Measure Question Selection accuracy Did the agent choose the expected tool, or correctly choose none? Argument accuracy Were the arguments correct, with no invented values? Order Were prerequisites checked before actions? Error recovery After a tool error, did the agent follow the error's guidance? Build a test set of requests with expected tools and arguments (Lesson 78), and re-run it whenever tool descriptions change. Treat tool descriptions like prompts: version them (Lesson 67) and evaluate changes (Lesson 66).

Common Mistakes Mistake 1: Describing Only What the Tool Does What it is: "Searches documents."

Why it happens: The function's purpose seems sufficient.

What it causes: The agent does not know what it will get back or when to use the tool instead of another.

How to fix it: Describe results, when to use, when not to use, limits, and side effects.

Mistake 2: Parameters Without Guidance What it is: Parameters with only a type, such as email: string.

Why it happens: The meaning seems obvious.

What it causes: Wrong formats and invented values.

How to fix it: Describe each parameter with format, example, and what to do if it is unknown.

Mistake 3: Unhelpful Errors What it is: Tools that return "Error" or raise exceptions.

Why it happens: Errors are designed for developers, not agents.

What it causes: Agents that retry blindly or give up.

How to fix it: Return structured errors that explain what went wrong and what to do next.

Mistake 4: Overlapping Tools What it is: Several tools that could answer the same request.

Why it happens: Tools are added for different features over time.

What it causes: Inconsistent tool selection.

How to fix it: Merge overlapping tools, or state the difference clearly in each description.

Mistake 5: Workflow Rules Hidden in Tool Descriptions What it is: Sequence rules spread across several tool descriptions.

Why it happens: Each tool is written separately.

What it causes: Incomplete or contradictory rules.

How to fix it: Put rules about order and prerequisites in the agent's instructions.

Best Practices Treat tool descriptions as prompts. Write, test, version, and review them.

Answer the six questions in every description. What, returns, when, when not, limits, side effects.

Name tools with clear verbs. Consistent verb_object names.

Design parameters carefully. Descriptions, formats, examples, enums, units, and nullable values.

Return helpful results and errors. Short, labeled, and actionable.

Describe tool relationships in the agent prompt. Order, prerequisites, and confirmation rules.

Lint and test tool definitions. Automatically, and with realistic requests.

Try It Yourself Exercise 1: Rewrite Weak Tools Rewrite the refund tool from the linter example as issue_refund, with a complete description, described parameters, and a confirmation rule. Run lint_tool() until it reports no problems.

Exercise 2: Design Error Messages For the tools get_enrollment, search_docs, and issue_refund, write three realistic error cases each, with helpful error messages that explain what to do next. Test one error with the agent from Lesson 108 and check whether it follows the guidance.

Exercise 3: Tool Selection Test Write 15 requests for an agent with four tools: search_docs, get_enrollment, search_catalog, and issue_refund. Include requests that need no tool, one tool, and several tools in order. Run them, record the tools and arguments chosen, and improve the descriptions where selection was wrong.

0 Comments

Reviewed before they appear

No comments yet.

Prompt Engineering
Prompt Engineering Introduction How Large Language Models Respond to Prompts Prompting Basics Elements of an Effective Prompt Writing Clear Instructions for AI Models Adding Context to a Prompt Providing Input Data in Prompts Using Output Indicators and Response Formats Prompt Formatting: Questions, Instructions, and Templates General Tips for Designing Better Prompts Common Prompt Engineering Mistakes Iterative Prompt Design and Refinement Understanding Instruction, Context, Input, and Output How Specificity and Conciseness Affect Prompt Quality Breaking Large Tasks into Smaller Prompting Tasks Zero-Shot Prompting Zero-Shot Prompting Examples for Everyday Tasks Zero-Shot Text Classification Zero-Shot Question Answering Zero-Shot Summarization Zero-Shot Translation Zero-Shot Prompting for Information Extraction When to Use Zero-Shot Prompting Limitations of Zero-Shot Prompting Improving Weak Zero-Shot Prompts Few-Shot Prompting One-Shot Prompting vs Few-Shot Prompting Choosing Good Examples for Few-Shot Prompts Formatting Examples in Few-Shot Prompts Few-Shot Classification with Examples Few-Shot Prompting for Structured Output Few-Shot Prompting Zero-Shot vs Few-Shot Prompting Role Prompting and Persona Instructions Instruction-Based Prompting Task-Oriented Prompt Templates Using Delimiters to Separate Prompt Sections Prompt Templates with Variables Chain-of-Thought Prompting Zero-Shot Chain-of-Thought Prompting Few-Shot Chain-of-Thought Prompting Automatic Chain-of-Thought (Auto-CoT) When Chain-of-Thought Prompting Helps Limitations of Chain-of-Thought Prompting Self-Consistency Prompting Comparing Chain-of-Thought and Self-Consistency Tree of Thoughts (ToT) Prompting Exploring Multiple Solutions with Tree of Thoughts Least-to-Most Prompting Complexity-Based Prompting Maieutic Prompting Self-Consistency: Sampling Multiple Reasoning Paths Self-Consistency for Arithmetic and Logic Tasks Tree of Thoughts: Search, Evaluation, and Backtracking Meta Prompting Generate Knowledge Prompting Directional Stimulus Prompting Program-Aided Language Models (PAL) React: Reasoning and Acting with Language Models Reflexion: Improving Agents Through Feedback Prompt Chaining Designing Multi-Step Prompt Chains Decomposing Complex Tasks into Prompt Chains Automatic Prompt Engineer (APE) Active-Prompt: Selecting Useful Reasoning Examples Optimizing Prompts Systematically Prompt Iteration and Versioning Building Reusable Prompt Libraries Testing Prompt Variants Prompt Chaining Fundamentals Passing Outputs Between Prompt Steps Prompt Chains for Summarization and Extraction Validating Intermediate Results in a Prompt Chain Debugging a Multi-Step Prompt Workflow Graph Prompting Multimodal Chain-of-Thought Prompting Automatic Reasoning and Tool-Use (ART) Prompting for Tool Selection and Use Combining Prompting Techniques for Complex Tasks Prompts for Text Summarization Prompts for Information Extraction Prompts for Text Classification Prompts for Question Answering Prompts for Sentiment Analysis Prompts for Rewriting and Editing Prompts for Translation and Localization Prompts for Brainstorming and Creative Writing Prompts for Generating Structured Data Prompts for Explaining Technical Concepts Prompts for Generating and Reviewing Code Prompting for Code Generation Prompting for Code Explanation Prompting for Debugging and Error Analysis Prompting for Unit Test Generation Prompting for SQL Query Generation Prompting for API Documentation Prompting for Technical Documentation Using Prompting to Extract Requirements Creating JSON-Style Structured Responses with Prompts Designing Prompts for Repeatable Developer Workflows Retrieval-Augmented Generation (RAG) How Prompt Engineering Supports RAG Writing Prompts That Use Retrieved Context Grounding Answers in Provided Documents Handling Missing Information in RAG Prompts Reducing Unsupported Claims in Context-Based Answers Prompt Engineering for AI Agents ReAct Prompting for Tool-Using Agents Writing Tool Instructions for AI Agents Prompting Agents to Plan Multi-Step Tasks Prompting Agents to Observe Tool Results Using Feedback and Reflection in Agent Workflows Prompting for Agent Error Recovery How to Evaluate Prompt Quality Creating Test Cases for Prompts Comparing Prompt Outputs with a Rubric Evaluating Accuracy, Relevance, and Completeness Regression Testing for Prompt Changes Building a Prompt Evaluation Dataset Common Causes of Inconsistent Prompt Outputs Prompt Injection: Introduction and Examples Recognizing Prompt Injection Attempts Prompt Leaking and Instruction Disclosure Risks Jailbreaking: Understanding Adversarial Prompts Writing Safer Prompts for Untrusted Inputs Reducing Hallucinations with Clear Instructions and Context Prompt Safety: Limitations and Best Practices Build a Zero-Shot Sentiment Classifier Project Goal Build a Few-Shot Text Classification Prompt Build a Prompt-Based Text Summarizer Project Goal Build a Structured Information Extraction Prompt Build a Prompt Template for Blog Outlines Build a Prompt-Based SQL Assistant Build a Code Explanation Prompt Workflow Build a Multi-Step Research and Summarization Workflow Build a Prompt Comparison and Evaluation Pipeline Build a Prompt-Chaining Workflow for Document Analysis Build a RAG Prompt for Question Answering over Documents Build a Tool-Using ReAct Assistant Create a Reusable Prompt Library for a Web Application
Ask about this post
AI Ask about this post

Ask questions about Writing Tool Instructions for AI Agents and get answers drawn from it.

Signed-in readers only.