Emma pulled up James's TutorClaw on her phone and typed a single character into the WhatsApp chat: an empty string, just a space and send.
The response came back fast: a wall of Python. TypeError, KeyError, a file path from James's laptop, a line number deep inside server.py.
"Your product just leaked its implementation to the user," Emma said, turning the screen toward him.
James squinted at the traceback. "That is just an edge case. Nobody sends an empty message."
"Every user is an edge case generator. A two-year-old borrows a phone and mashes the keyboard. Someone pastes an emoji where a name should go. A learner types Module 9.3, Chapter 9999 because they are curious." She set the phone down. "You built a product that works when inputs are perfect. Now make it work when inputs are not."
You are doing exactly what James is doing. TutorClaw works when everything goes right. Now you make it handle the cases where everything goes wrong.
In this chapter, you send malformed inputs to every tool, observe the failures, describe hardening requirements to Claude Code, add structured logging, and verify the result. By the end, every bad input produces a clear message instead of a crash, and every tool call leaves a structured record in a log file.
Before fixing anything, see what breaks. Open Claude Code in your tutorclaw-mcp project and ask it to test each tool with bad inputs:
Categorize what you see:
Now describe the fix. Tell Claude Code what "valid" means for each tool:
Validation tells users what went wrong. Logging tells you what happened:
One JSON object per line (JSONL) means each log entry is a complete, parseable record. You can filter by tool name, find all errors for a specific learner, or calculate average response times.
Resend the same malformed inputs from Step 1:
Compare the results to your initial baseline:
Check the log file. Each malformed input should have produced a structured entry:
The pytest suite from Module 9.3, Chapters 11-12 tested the happy path. Hardening added new behavior that needs test coverage:
Run the suite to ensure full coverage:
What you are learning: A good error message is a tiny piece of documentation. The quality of your error messages determines whether users retry with correct input or simply give up.
What you are learning: Structured logs are queryable data. When TutorClaw has real users, you can answer "which tool fails most often?" without adding any new code. The log file is your operations dashboard.
What you are learning: Structured logs are the foundation for monitoring and alerting. Good logging design happens before you actually need the logs.
James resent every malformed input from the morning. Empty names, impossible chapter numbers, restricted imports. Each one came back with a clear sentence telling the user what went wrong and how to fix it.
He opened the log file. Neat rows of JSON, one per line. Timestamp, tool name, learner ID, status, duration. Every call recorded.
"The product feels professional now," he said.
"Professional is a word for 'it does not leak its internals when surprised,'" Emma said. She closed her laptop halfway, then paused. "That is why I care about error messages more than features."
James looked at the log file again. "So we have validation, logging, and tests for both. What is left?"
"Publishing. Your product works. Your product handles surprises. Your product records what happens. Now other people need to be able to install it." She pointed at the ClawHub tab in his browser. "Chapter 20."