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
- An approved write runs and is logged
- A declined write does not run
- A read tool runs without asking
- 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.