LLM output is untrusted

Here is a critical rule: LLM output is untrusted input. Just like you validate user input from a web form, you must validate what the LLM returns before acting on it. It can return invalid room names, out-of-range temperatures, or malformed data.

07-error-handling.ipynb
python
# Real examples of bad LLM outputs:

# Wrong room name
{"room": "ktichen", "temp": 22}  # Typo!

# Invalid temperature
{"room": "kitchen", "temp": "warm"}  # String, not number

# Missing required field
{"room": "kitchen"}  # No temperature!

# Hallucinated room
{"room": "garage", "temp": 22}  # No garage in system!

LLMs can return typos, wrong types, missing fields, or hallucinated values. Never trust raw output.

Trust boundary between LLM and your system

Quiz: Quiz

Loading practice…