How to Have the AI Build a Tool
When writing a tool requirement, the point is not to "write a lot"—it is to describe the interface clearly.
A good tool prompt usually only needs to answer 6 questions:
- What does this tool do
- What is the input
- What rules to process by
- What artifact to output
- What to return in the end
- Whether to print stage logs
Note: documents like this can live in the
examplesdirectory; the page path can beindexor any other path.
Recommended Format
txt
Help me build a {tool name} tool.
Goal:
- What task should this tool accomplish
Input:
- What is the input, what type, is it required
Processing rules:
- What to extract, transform, filter, or count
Output:
- Whether to generate a file
- If a file is generated, specify its format and save location
Return:
- Return JSON
- Or return the result file path
Logging:
- Whether to print stage logs
Constraints:
- Requirements for large-file handling, error handling, sensitive information, etc.
The Difference Between "Output" and "Return"
- Output: the actual result the tool produces, such as a CSV file, an Excel file, or a piece of structured data
- Return: what the tool hands back directly when execution finishes, such as the result file path, or JSON
Two common patterns:
- Output a file, and return the path to that file
- Do not generate a file, and return JSON directly
Three Most Common Examples
1. Output a File, Return the File Path
txt
Help me build a PDF information extraction tool.
The input is a PDF file path.
Extract the company name, contact person, phone number, and contract number.
Output a CSV file saved in the same directory as the input file.
For the return value, provide the full path to the generated CSV file.
Please print stage logs for reading the PDF, extracting fields, and writing results.
2. Do Not Generate a File, Return JSON Directly
txt
Help me build a web content statistics tool.
The input is a web page URL.
Extract the plain text of the page body and count characters, paragraphs, and links.
Do not generate a file; return JSON directly.
3. Return Both a File Path and Summary Information
txt
Help me build a CSV cleaning tool.
The input is a CSV file path.
Output a new, cleaned CSV file.
The return value should include the result file path, the original row count, the cleaned row count, and the number of removed rows.
Please print stage logs, but do not output raw sensitive content.
A One-Line Reminder
- When results are large or contain sensitive information, prefer "output a file + return the file path"
- When results are small and have a fixed structure, prefer returning JSON directly
- Do not write accounts, passwords, or keys directly into the prompt—read them from runtime variables
Self-Check After Writing
If you can clearly answer these 5 questions, it is usually enough:
- What is the input
- How to process it
- What is the output
- What to return
- Whether logs are needed