AI Agents by HandAll problemsAbout

All problems › Python drill · easy · ~4 min

d13 · Format tool errors

error text error handling tool results

Solve it in your browser →

d13 · Format tool errors (~4 min)

Numbers, missing values, time. Edit drills.py. Standard library only; no model calls, no API key.

def error_text(exc):

Turn a tool's exception into tool_result error text: "<Type>: <message>".

The message is what the code raised with, not its repr: KeyError("tokyo") and a failed d["tokyo"] both give "KeyError: tokyo"; ValueError("bad qty") gives "ValueError: bad qty". No message: just the type name ("TimeoutError"). Several args: use str(exc).

Failure messages are enough to go on, so leave the tests unread until you submit.

Starter code and hidden tests open in the editor. Nothing to install.