Sub topic 11
Adding Examples and Format Hints to Descriptions
This chapter assumes you can read short Python examples and JSON Schema basic types. It also assumes you have seen the parts of a tool definition: name, description, and input schema. Here you will learn how to add examples and format hints to descriptions so the model sends values your tool accepts.
Why a type is not enough
A schema type such as "type": "string" tells the model only that the value is text. A date, an ID, a phone number, and a free-text query are all strings. The model has to guess which one you mean. Common guesses that go wrong:
- It sends
"November 3"or"11/03/2026"when the tool expects2026-11-03. - It sends
"4821"when the tool expects"cus_4821". - It sends
"Shipped"or"in transit"when the tool expects"shipped". - It sends a whole sentence when the tool expects one keyword.
A short hint inside the description removes most of these guesses. The model reads the description when it fills the argument, so that is where the hint belongs.
What a format hint should state
A good format hint answers four questions in one sentence or two:
- What shape does the value have? ("in YYYY-MM-DD format", "a 2-letter ISO country code")
- What does a real value look like? ("for example 'cus_4821'")
- Where does the value come from? ("Ask the user if you do not know it", "returned by search_orders")
- What happens if it is left out? ("Defaults to 10 if omitted")
The search_orders definition from earlier in this tutorial uses all four:
{
"customer_id": {
"type": "string",
"description": "Customer ID, for example 'cus_4821'. Ask the user if you do not know it."
},
"created_after": {
"type": "string",
"description": "Only return orders created on or after this date, in YYYY-MM-DD format."
},
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 50,
"description": "Maximum number of orders to return. Defaults to 10 if omitted."
}
}Notice that the limit description does not repeat the range 1 to 50. The minimum and maximum keywords already carry it. Use the description for what the schema cannot express: meaning, source, default, and format.
Examples inside descriptions
An example value is the strongest format hint, because the model can copy its shape. Put examples in these places:
- Parameter descriptions. Give one or two realistic values:
'cus_4821','2026-11-03'. - Tool descriptions. Give a short usage pattern when the choice between tools is subtle: "Use this when the user does not give an order ID."
- Result descriptions. Say what the tool returns, such as "each with id, status, total, and created_at", so the model knows what it can quote.
Keep examples realistic and varied
Models tend to anchor on example values. If every example is 'cus_4821', the model may send that exact ID when it does not know the real one. Three habits reduce this risk:
- Pair the example with a sourcing instruction: "Ask the user if you do not know it."
- Use an obviously illustrative value, not one that could pass for a real record.
- For free-text parameters, show two examples with different shapes, so the model learns the pattern and not one string.
Do not use examples to patch a vague tool
If you need five examples to explain what a tool does, the name or scope is the problem. Compare the weak do_order_thing definition from earlier. Adding examples to data and mode would still leave the model guessing which task the tool performs. Fix the name, split the tool, and add enums first. Then use examples for the remaining format questions.
Hints for common value types
| Value type | Weak hint | Stronger hint |
|---|---|---|
| Date | "The date" | "Date in YYYY-MM-DD format, for example '2026-11-03'. Use the user's local date." |
| Timestamp | "When it happened" | "UTC timestamp in ISO 8601 format, for example '2026-11-03T14:30:00Z'." |
| ID | "The ID" | "Order ID such as 'ord_1001'. Returned by search_orders as `id`." |
| Money | "The amount" | "Amount in cents as an integer, so $42.50 is 4250." |
| Country | "Country" | "2-letter ISO 3166-1 code, for example 'DE'." |
| List filter | "Tags" | "Tags to match, for example ['gift', 'urgent']. Omit to match all." |
Money shows why units belong in the hint. A field named amount could mean dollars, cents, or a string with a currency symbol. The model cannot recover the intended unit from the type.
The JSON Schema `examples`, `format`, and `pattern` keywords
JSON Schema has keywords for these hints: examples, format (such as "date"), and pattern (a regular expression). They are tidy, but support depends on the provider. Some APIs ignore them, some reject them in strict mode, and some enforce only part of them. The chapter on provider differences covers this in detail.
A safe approach is to state the format in the description, where every provider passes it to the model as text. Add format, pattern, or examples only if you have confirmed that your provider accepts them. Even then, keep the sentence in the description.
Keep the hint and the check in sync
The description makes a promise, and your code must enforce it. If the two drift apart, the model follows the hint and your validator rejects the result. The Python below checks the same two formats that the search_orders descriptions state. It runs as shown with Python 3.10 or later.
import re
from datetime import date
CUSTOMER_ID = re.compile(r"^cus_\d+$")
DATE_ONLY = re.compile(r"^\d{4}-\d{2}-\d{2}$")
def check_search_args(args: dict) -> str | None:
"""Return an error message for the model, or None if the arguments are valid."""
customer_id = args.get("customer_id")
if not isinstance(customer_id, str) or not CUSTOMER_ID.match(customer_id):
return (
f"Invalid customer_id {customer_id!r}. IDs look like 'cus_4821'. "
"Ask the user for their customer ID."
)
created_after = args.get("created_after")
if created_after is not None:
if not isinstance(created_after, str) or not DATE_ONLY.match(created_after):
return (
f"Invalid created_after {created_after!r}. "
"Use YYYY-MM-DD format, for example '2026-11-03'."
)
try:
date.fromisoformat(created_after)
except ValueError:
return f"{created_after!r} is not a real calendar date. Use YYYY-MM-DD."
return None
print(check_search_args({"customer_id": "cus_4821", "created_after": "2026-11-03"}))
print(check_search_args({"customer_id": "4821"}))
print(check_search_args({"customer_id": "cus_4821", "created_after": "2026-13-45"}))The regex runs before date.fromisoformat on purpose. In Python 3.11 and later, fromisoformat also accepts forms such as 20261103, which the description does not promise. The regex keeps the check as strict as the hint. The error messages repeat the format and an example, so the model can fix the call on its next turn.
Where hints sit in the loop
Common mistakes
- Contradicting the schema. The description says "up to 100" but
maximumis 50. The model trusts one and the API rejects it. - Stating a format in the description only for some fields. The model learns that unmarked strings are free text. Hint every string that has a required shape.
- Examples that look like instructions. "For example, always set status to 'shipped'" reads as a rule. Say what a value looks like, not what to choose.
- Long example lists in every parameter. Each word costs context on every request. Use one or two examples, and only where the shape is not obvious.
- Changing the format without changing the hint. Update the description, the validator, and your test cases in the same commit.
Check the effect with your test set
Format hints are easy to add and hard to judge by eye. Add test prompts that exercise them, such as "orders since Nov 3" and "my customer number is 4821". Run them through your evaluation loop before and after the change. If the pass count for argument format does not rise, the hint is not helping and you should look at the schema or scope instead.
Exercise
A tool parameter due_date is typed as a string. The description says only "The due date." The model often sends "next Friday". Rewrite the description so the model sends a usable value, and name the server-side check you would add.
Show answer
Example description: "Due date in YYYY-MM-DD format, for example '2026-11-03'. Convert relative dates such as 'next Friday' to an absolute date using today's date before calling." The server-side check is a strict pattern match on ^\d{4}-\d{2}-\d{2}$ followed by date.fromisoformat. If the check fails, return an error that repeats the format and the example so the model can retry.
Exercise
Why can using the same example ID, 'cus_4821', in every description cause trouble, and how do you reduce the risk?
Show answer
The model may anchor on the example and send it when it does not know the real value, which looks up another customer's data. Reduce the risk by adding a sourcing instruction ("Ask the user if you do not know it"), using a value that is clearly illustrative, and validating on the server that the ID belongs to the current user.