A model can only do what its tools allow. lookup_order needs an order number, so a customer who only knows their email gets no help. In this lesson you give the model a second lookup tool, find_orders, which finds a customer's orders by email.
Two tables, one query: the orders table has no email column. The email is in customers, and each order points to its customer with customer_id. A JOIN puts the matching rows side by side, so you can filter by a column of the other table. The same idea on books and authors:
SELECT books.title
FROM books
JOIN authors ON authors.id = books.author_id
WHERE authors.name = ?
With two tools that look things up, the description decides which one the model picks: say what the tool does and when to use it. The input schema tells the model the shape of the input, here one string named email. A customer with no orders gets an empty list: that is an answer, not an error.
The customer writes "Has my order shipped? I don't know its number. My email is chloe@example.com." Your finished program prints the lines below. The check also calls find_orders itself, for example for a customer with no orders.
Model: I'll find your orders by your email.
Tool: find_orders {'email': 'chloe@example.com'} -> {'orders': [{'id': 4, 'ordered': '2026-04-18', 'status': 'shipped'}, {'id': 7, 'ordered': '2026-05-30', 'status': 'paid'}]}
Tool results sent in one message: 1
Answer: I found two orders for chloe@example.com. Order 4, from April 18, has shipped. Order 7, from May 30, is paid and hasn't shipped yet.
The check asks find_orders for eva@example.com, who has no orders: {'orders': []}
Your task: finish the query and the function find_orders, describe the tool for the model (its description and its input schema), then add it to tools and to functions.
Assignment
Follow the Coding Tutorial to build the find_orders tool and offer it to the model next to lookup_order.
Hint
The ? in the query is the placeholder for the email. run_tools needs no change: it picks the function by the tool's name.
Free plan: 30 tutor messages. PRO is unlimited.
