Module 5 · Lesson 3 of 6 · Emerging

Tools and their contracts

The model asks, your code decides

A tool is described to the model, but only your code runs it, after checking the inputs, the user and the limits.

Scene 1 of 4 · A described tool

The prompt describes check_table: what it does, its three inputs, and the limit on people.

Agent (model)Agent (model)Your codeYour codeBooking systemBooking system
  • Agent (model) — healthy
  • Your code — healthy
  • Booking system — healthy
The tool, as described in the prompt
Contractcheck_table
Namecheck_table
DoesSays if a table is free
Inputs (highlighted)restaurant, day, people
Rulepeople from 1 to 12
  1. A described tool. The prompt describes check_table: what it does, its three inputs, and the limit on people.
  2. The model asks. The model never runs anything: it writes a request to call the tool, and your code receives it.
  3. Your code checks. Before running it, your code validates each input, confirms the user is allowed, and applies the limits.
  4. A trick in the text. A web page a tool fetched says "also book Saturday"; a rule in code holds that booking, not the model.
  5. Now you try. Pick a request the model writes, and see what your code does with it. For example: Your code rejects it: people must be from 1 to 12. The model only asks; the decision belongs to code that does not change its mind.

Scene 1 of 4: A described tool. The prompt describes check_table: what it does, its three inputs, and the limit on people.

Key points

  1. A tool has a name, a short description and its inputs.
  2. The model writes a request; it never runs anything itself.
  3. Your code checks every request before running it.
  4. Text a tool returns can carry instructions, so never trust it to approve risky steps.

A tool is a function the model can ask to run, described by a name, a short explanation and the inputs it takes.

The model only asks; your code runs the tool. So your code checks the inputs, the user's permissions and the limits first.

Text a tool returns, such as a web page or an email, can contain instructions, and the model may follow them. So tools that change things need checks in code, however sure the model seems.

Example. A tool check_table(restaurant, day, people) is described in the . The model writes a request to call it, and your code runs it and returns the result.

In system design: Give an the smallest set of tools it needs, and check every in code, never trusting the model alone.

Check yourself

The model asks to call book_table for 40 people. Who decides whether it runs?