Command Palette

Search for a command to run...

Hectal
Phase 7: Tools and Function Calling
LLM Engineering · Exercise 1 of 6Next
Intermediate

Parse a tool call

A model returned a tool call. Write parse_call(call) that returns a tuple (name, args): the function name and the arguments as a dict (the arguments field is a JSON string).

If the string is not valid JSON, raise ValueError("arguments are not valid JSON"). If it is valid JSON but not an object, raise ValueError("arguments must be a JSON object").

What Check tests

  1. A valid call gives (name, args)
  2. Broken JSON raises ValueError
  3. Valid JSON that is not an object raises ValueError
  4. An empty object is fine

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.