Skip to content

Check what the model sends

Read · 1 of 3

The model is not a trusted caller

When the model calls refund(amount), the amount came from a model that read a customer's message. It can be wrong, or the customer may have talked it into something.

So every tool checks its own inputs, exactly as you'd check a web form: types, ranges, formats. Then a confused or manipulated model can't do damage.

Read this lesson as text

Tool arguments come from a model. Validate them like user input.

The model is not a trusted caller

When the model calls refund(amount), the amount came from a model that read a customer's message. It can be wrong, or the customer may have talked it into something.

So every tool checks its own inputs, exactly as you'd check a web form: types, ranges, formats. Then a confused or manipulated model can't do damage.

Break it: Break the refund check

Refunds must be more than 0 and at most 1000. This check guards the refund tool.

Find an amount it wrongly allows.

amount = int(input())
print("ok" if amount <= 1000 else "rejected")

Input rules: One whole number from -1,000,000 to 1,000,000: the amount the model asked to refund.

Exercise: Don't pay twice

A retry can send the same tool call twice. Payment tools defend with an idempotency key: each request carries a key, and a key that's been seen is skipped.

Input: n, then n lines key amount. Print paid key amount or skipped key (duplicate) for each, then total paid: T.