Designing Unambiguous Tool Sets and Schemas
Explore how ambiguous tool definitions can make AI agents choose inconsistently. Learn to merge overlapping tools, write discriminating descriptions, constrain inputs with enums and strict schemas, validate calls locally, and test tool sets for overlap so production workflows are more reliable and easier to trace.
We'll cover the following...
In the previous lesson, we saw two skills with overlapping triggers give the model opposite instructions. Tools can overlap in the same way. In this lesson, we’ll apply the same check to the tool definitions that sit next to the prompt.
So far, our on-call assistant has one tool, search_documents(), which searches runbooks and postmortems. To answer “What changed?”, it also needs to see recent deploys. Over a few weeks, two teammates each add a tool for that. One adds get_deploy_log(). The other adds get_change_history(), which covers deploys and feature flag changes. On paper, that looks like more capability. In practice, it gives the model a choice it can’t make well.
Two tools for one job
Let’s write both tools in the same OpenAI function format we’ve used since Chapter 1, next to the existing search tool. A small helper keeps each definition short.
In the code above:
Lines 4–7: We define
make_tool(), which builds a tool definition from a name, a description, parameters, and the required parameter names.Line 10: We define
SERVICE_PARAM, a single free-textserviceparameter.Lines 11–16: We define
get_deploy_logandget_change_history. Both take onlyservice, and both descriptions promise recent deploys.Lines 18–19: We collect the three tools and write a “what changed?” question.
Lines 21–24: We print each tool’s name, required parameters, and the start of its description.
The two change tools look almost the same:
search_documents | needs ['query', 'top_k'] | Search the team's runbooks and postmortems an...get_deploy_log | needs ['service'] | Return recent deploys for a service, with tim...get_change_history | needs ['service'] | Return recent changes to a service, including...
Try to decide which tool should answer “What deployed to checkout right before the 14:05 spike?” Both take a service name, and both return deploys. There’s no clear answer.
Which tool does the model pick?
Let’s ask the model the same question several times with all three tools available. We set tool_choice="auto" ...