Examples in the Tool Definition

7 min read

K16
Deep Dive · Tool & Capability Design

An example is the only part of a tool contract that can teach restraint.

Your schema can declare a field optional; nothing in it can say usually leave this out. That gap is why examples became a first-class field rather than something you smuggle into a description — an omission is a lesson no type expresses, and a worked example is the only place in the contract where the absence of a value is itself informative. The price is about 100 input tokens per flat example and 200 per nested one, charged on every request that carries the tool, and there is one documented case where the platform stops checking that your examples are even valid.

Step 1What an example says that a type cannot.

A JSON Schema is a statement about the set of acceptable values. It is silent on which acceptable value is usual, and that is most of what a model needs in order to call a tool well. The clearest illustration is in Anthropic's own documentation, where get_weather ships three examples and the third is the interesting one:

"input_examples": [
  {"location": "San Francisco, CA", "unit": "fahrenheit"},
  {"location": "Tokyo, Japan",      "unit": "celsius"},
  {"location": "New York, NY"}    // 'unit' is optional
]

The third example carries no new value. Its entire content is a missing key. The schema already said unit was outside required, and the description already said what unit means, but neither could show the shape of a call that correctly declines to set it. That is the thing examples are for, and it generalises past optionality: an example demonstrates which fields travel together, how a nested object is actually assembled, and what a format-sensitive string looks like when it is right. The documentation is explicit that examples are most useful exactly where description alone fails — complex inputs, nested objects, and format-sensitive parameters.

Read against Schemas, Contracts & Defaults, this makes examples the strongest instrument in the prose channel. The grammar reads types and enums; the model reads everything. An example is prose that happens to be machine-checkable, which is a rare combination and the reason it earns its own field.

Step 2They are validated for you — except in one case the docs name.

Each example must be valid against the tool's own input_schema, and the API usually returns a 400 for one that is not. That is a genuine improvement on examples pasted into a description, which nothing has ever checked. But the documentation records a specific exception, and it is worth reading twice: when the schema contains a pattern, the check is skipped and the model is shown the invalid example anyway.

Put that together with strict mode and you get a trap with no error message in it. A pattern is one of the few constraints that actually compiles into the grammar, so an engineer adding "pattern": "^ord_[0-9a-f]{8}$" is doing the right thing — tightening the contract where tightening works. The same edit silently disables validation of the examples sitting beside it. If one of those examples says "order_8f3a" rather than "ord_8f3a12cd", the model is now taught a format that its own sampling grammar will refuse to emit. You have created a disagreement between the two readers of the schema, and the platform has stopped being the thing that catches it.

The guidance is to validate every example against the schema yourself rather than relying on the 400. Treat that as a build step, not a code-review habit: one assertion per tool, run in CI, checking each entry in input_examples against the same schema you ship. It is four lines and it closes the only hole in the field.

Step 3The price is per request, and it is paid in the budget you were already short of.

Examples are included in the prompt alongside the schema, which means they are part of the tool definition and therefore re-sent on every turn that carries the tool. The documented cost is about 100 input tokens for an example with a few flat values and about 200 for one with nested objects. Three nested examples is roughly 600 tokens standing in your window permanently, per tool.

That is affordable for one tool and not for forty. The arithmetic to run is not "can I afford 600 tokens" but "which of my tools is this the right 600 tokens for" — and the answer is the small number of tools where a malformed call is expensive and the right call is non-obvious. For everything else the money is better spent on the description, or not spent.

There is a second budget, and it is tighter. Where tool definitions are deferred and retrieved on demand, the selection step may read only the opening slice of a tool's text — Tool Docs & Discoverability works through the two separate character budgets this creates. Examples help a model that has already selected your tool call it correctly; they do nothing to help it find the tool in the first place. Do not let them crowd out the text that does.

Step 4Example, description, or constraint: pick by which failure you are buying off.

The three channels are not interchangeable and they fail differently, so choose by the error you are trying to delete. A constraint deletes an error class outright when it compiles — a discrete range as an enum cannot be violated at all. A description is the only place a non-compilable rule can live, which is where every length bound and numeric floor ends up. An example is for the case where no rule exists to write down: the correct value depends on context the schema cannot encode, or the correct call is a pattern of fields rather than a property of any one field.

The practical test is to ask what the wrong call would look like. If it would be well-typed and still wrong — the right fields, plausible values, assembled in a combination nobody uses — that is an example's job, and neither a tighter type nor a longer description will reach it. If the wrong call would be out of range or badly formatted, reach for a constraint first and accept a description as the fallback when the constraint is one the grammar refuses.

One example per failure you have actually observed in a trace beats three invented ones. The library of real malformed calls your agent has already made is the best source of examples you will ever have, and it is sitting in your logs.

Step 5When to add none, and the two ways a set of examples misleads.

Most tools do not need examples. A tool with one required string and an unambiguous format is already fully specified; adding an example buys nothing and costs tokens on every turn. The honest default is zero, with examples added to the specific tools where traces show the model getting the shape wrong rather than the intent.

When you do add them, two failure modes are worth designing against. The first is anchoring: a set of examples is a distribution, and the model reads it as one. Three examples that all set the same enum value, all omit the same optional field, or all use the same region will bias calls in that direction, which is useful when you meant it and a silent defect when you did not. Vary the set deliberately across any axis you do not want anchored — which is exactly what the get_weather set above does, alternating fahrenheit, celsius, and absent.

The second is assuming the field exists everywhere. input_examples applies to user-defined tools and to only some of the platform's own schema tools, so the field you added to a custom tool is not necessarily available on the built-in one next to it; the tool reference is the place that says which accept it. And because examples live in the tool definition rather than the conversation, they share the tool definition's fate — including, under strict mode, being compiled and cached as part of a schema that is held on a different retention track from your messages.

Add examples to the handful of tools where a well-typed wrong call is expensive; derive each one from a real trace; vary the set across every axis you do not want the model to anchor on; include at least one example that omits each optional field, because the omission is the only lesson a type cannot teach; and assert in CI that every example still validates against the schema you ship — the platform will not do that last one for you the moment you add a pattern.