AlgoMaster Logo

Exercise: Designing Tool Schemas

3 min readUpdated June 22, 2026
Listen to this chapter
Unlock Audio

Exercise 1: Write a Tool Schema the Model Can Use

Design the JSON Schema for a tool with several typed parameters, including an enum and a required field, then confirm the model fills it in correctly from a natural-language request.

The schema is the contract between your code and the model. A vague or loose schema produces malformed or ambiguous tool calls; a precise one, with clear descriptions, typed parameters, and enums for fixed choices, gets you arguments you can pass straight into your function. Designing schemas well is most of what makes tool use reliable.

Requirements

  • Define a create_event tool with parameters: title (string, required), date (string, required), and priority (enum of low, medium, high).
  • Write clear descriptions for the tool and each parameter.
  • Send a natural-language request and inspect the arguments the model produces.
  • Print the parsed arguments.
main.py
Loading...

Expected Output

The model maps the sentence onto your schema, picking the right enum value and field names.

Solution

main.py
Loading...

The schema does three jobs at once: type tells the model what kind of value each field holds, required forces the must-have fields to appear, and enum restricts priority to a closed set so you never get a surprise value. The descriptions guide the model on what each field means, which matters most when a field is ambiguous. A function written against this schema can trust the arguments without defensive parsing, because the contract was enforced during generation.

Exercise 2: Design a Schema with an Array and a Nested Object

Real tool arguments are not flat. A calendar event has a list of attendees and a structured location. Design a schema with an array parameter and a nested object parameter, and confirm the model populates both correctly from one sentence. Nested schemas are where tool design gets real, and where a loose schema produces unusable arguments.

Requirements

  • Define a create_event tool with title (string), attendees (array of strings), and location (nested object with name and room).
  • Send a natural-language request mentioning multiple attendees and a structured location.
  • Parse and print the arguments the model produced.
main.py
Loading...

Expected Output

The model fills the array of attendees and the nested location object from the sentence.

Solution

main.py
Loading...

Declaring attendees as an array with string items tells the model to return a list, not a comma-joined string, and the nested location object gives the room and building their own typed fields instead of one blob. The model maps the sentence onto this structure because the schema spells out the shape it must produce. A function written against this schema receives a ready-to-use list and dict, which is the payoff of designing the structure rather than parsing free text afterward.