Designing a Good Tool Schema
In this article
- Write a tool input schema with minimal required fields, strong types, enums, explicit units and bounds, so the model cannot easily express an illegal call.
- Shape a tool result so success and failure are told apart by one stable field, with the same field names every time.
- Add an input example for what the schema cannot say, and spot an example or a schema size that works against the model.
- Terms defined here: tool contract.
Overview
You give a model a tool that moves money, and it calls it with arguments it wrote itself. If its parameters are loose, the model fills the gaps by guessing: is amount in euros or cents, is the order id needed, what counts as a reason? Each guess is a call your code may run.
The model builds its arguments from the tool's input schema, a written description of the arguments the tool accepts, and reads the result against what it expects back. [4] By the end you can write that schema so a wrong call is hard to even express, shape a result so success and failure never look alike, add one example for the meaning a schema cannot carry, and say where the schema stops and your code takes over.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- A schema that invites guesses
- Required means the model must decide
- Units, enums and bounds
- Absent or null
- Examples say what a schema cannot
- The result is part of the contract
- Strict decoding and what it cannot check
- Small enough to read
- The rule at work
- Sources
- Check yourself, 13 questions