Sub topic 3
Adding Examples and Format Hints to Tool Descriptions
Assume you can call an LLM API, read JSON, and understand basic JSON Schema. This chapter focuses on details that improve tool selection and argument quality.
Add examples and format hints
Descriptions should show formats the model cannot safely infer. State whether a date uses YYYY-MM-DD, whether an ID includes a prefix, and what happens when a value is omitted. Examples are useful when two valid formats look similar.
{
"name": "get_order",
"description": "Get one order by ID. Use this when the user gives an order ID, such as 'ord_1001'. If the user gives no ID, use search_orders.",
"input_schema": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "Order ID including the 'ord_' prefix, for example 'ord_1001'."
}
},
"required": ["order_id"]
}
}Shape useful results and errors
Return compact, stable objects. Include fields the model needs for its next response, rather than internal database records.
def get_order(order_id):
if not order_id.startswith("ord_"):
return {
"is_error": True,
"message": "Use an order ID like 'ord_1001', or call search_orders first."
}
return {"is_error": False, "order": {"id": order_id, "status": "shipped"}}An error should explain what failed and suggest the next action. This lets the model recover instead of repeating the same invalid call.
Manage context cost
Tool definitions and results occupy the model's context. Keep descriptions specific but short. Avoid repeating general instructions in every parameter. Return summaries, pagination data, and only fields needed for the task.
Validate before execution
The model produces arguments; it does not enforce your security or business rules. Validate types, ranges, formats, permissions, and resource ownership on the server before performing an action.
Provider differences
Providers use different wrapper names and support different JSON Schema features. One API may call the schema input_schema; another may call it parameters. Check the target provider's current contract, then keep your schemas within its supported subset. Always perform server-side validation even when provider-side validation is available.
Test and refine
Create realistic cases for correct tool choice, missing values, invalid formats, overlapping tools, and unrelated questions. Record the selected tool and arguments, compare them with expected results, and revise descriptions based on repeated failures.
Exercise
Why should a server validate arguments even when a JSON Schema is supplied?
Show answer
The model and provider can still produce unsupported, malformed, unauthorized, or unsafe values. Server validation protects the actual operation.