Sub topic 11
Adding examples and format hints to descriptions
This chapter assumes you can read JSON Schema and short Python examples. You should also know how a tool definition is laid out: a name, a description, and an input schema.
Why examples help
A type like "type": "string" tells the model nothing about the shape of the text. Dates could be 2026-11-28, 28/11/2026, or last Tuesday. The model picks one, and your server may reject it.
A short example or format hint in the description removes that guess. It is cheap, and it works on the parameters that models get wrong most often: dates, IDs, and free-text fields with a required structure.
Format hints
State the format in words, then add one example. Compare these two descriptions for the same parameter.
| Weak | Better |
|---|---|
| `"A date."` | `"Only return orders created on or after this date, in YYYY-MM-DD format."` |
| `"The customer."` | `"Customer ID, for example 'cus_4821'. Ask the user if you do not know it."` |
The better versions name the format, show a real value, and say what to do when the value is missing. The search_orders definition from earlier in this tutorial uses all three.
Where to put examples
- Parameter descriptions: best for value formats such as IDs, dates, and units.
- Tool descriptions: best for choosing between tools. A line like "If the user gives an order ID, use get_order instead" works as a contrast example.
- Defaults: state them in the text, as in "Defaults to 10 if omitted." The model cannot see your server code.
Keep examples honest
Examples carry weight with models, so they can mislead.
- Copying: a model may reuse your example value as an actual argument. Use a plausible example that is clearly a sample, and never one that matches a real customer.
- Narrowing: one example can make the model think only that form is valid. If two formats are accepted, say so.
- Drift: an example that no longer matches the server's rules causes errors. Update it when the schema changes.
- Length: every word is repeated on each request. One example per parameter is usually enough.
A worked example
This parameter is vague.
{
"created_after": {
"type": "string",
"description": "Start date."
}
}This version gives the format, the meaning, and a sample.
{
"created_after": {
"type": "string",
"description": "Only return orders created on or after this date, in YYYY-MM-DD format, for example '2026-11-01'. Omit to include all dates."
}
}You can also let the server check the format. The sketch below returns an error message that repeats the expected format, so the model can retry.
from datetime import date
def parse_created_after(value: str) -> dict:
try:
return {"is_error": False, "date": date.fromisoformat(value)}
except (TypeError, ValueError):
return {
"is_error": True,
"message": (
f"Invalid created_after {value!r}. "
"Use YYYY-MM-DD, for example '2026-11-01'."
),
}Exercise
A parameter due_date is typed as a string with the description "The due date." Models send values like "next Friday". Rewrite the description, and name one thing besides the description that should catch bad values.
Show answer
For example: "Due date in YYYY-MM-DD format, for example '2026-12-15'. Convert relative dates such as 'next Friday' before calling." The server should also validate the value, for example with date.fromisoformat, and return an error that restates the expected format.