args checks arguments against rules you set per tool. A value out of bounds gets a guide with what to fix, so the model can correct the call instead of retrying it unchanged.
guards.args({ refund_invoice: { amount: { min: 1, max: 500 }, currency: { oneOf: ["USD", "EUR"] } }, send_email: (args) => (String(args.to).endsWith("@example.com") ? undefined : "Only send to example.com addresses."),});The first argument maps tool names to either a map of field rules or a function. A function gets the arguments and returns a message when they are wrong (nothing when they are fine); the message becomes the guide. Tools without rules pass. The only other option is mode.
Field rules#
| TypeScript | Python and Ruby | Applies to | Check |
|---|---|---|---|
| min | min | Numbers and numeric strings | Value at least this |
| max | max | Numbers and numeric strings | Value at most this |
| maxLength | max_length | Strings | Length at most this |
| pattern | pattern | Strings | Must match. TypeScript: a RegExp. Python: a regex string (searched). Ruby: a Regexp or string. |
| oneOf | one_of | Any value | Must be one of the list |
Fields that are missing or null are skipped. min and max also hold for numbers passed as strings ("900"). A field with min or max whose value is a string that does not read as a number ("900abc") gets <field> has to be a number., since the tool might still read it as 900.
Messages#
| Rule | Message |
|---|---|
| max | amount can be at most 500. |
| min | amount has to be at least 1. |
| maxLength | note can be at most 200 characters. |
| pattern | invoice_id isn't in the expected format. |
| oneOf | currency has to be one of: USD, EUR. |
Every refusal has reason invalid_args. The guard stops at the first broken rule.