Command Palette

Search for a command to run...

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

Confirm writes and keep an audit log

Write guarded_run(tool, args, confirm, audit). tool is a dict with name, risk ("read" or "write") and fn (takes args, returns a value). confirm(name, args) returns True or False. audit is a list.

A read tool runs and appends "<name> ran" to audit. A write tool calls confirm: on True it runs and appends "<name> approved"; on False it does not run, appends "<name> declined" and returns "declined". Return the function's result when it ran. Any risk other than "read" counts as a write.

What Check tests

  1. An approved write runs and is logged
  2. A declined write does not run
  3. A read tool runs without asking
  4. Unknown risk fails closed

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.