Harden: Fixing Broken Descriptions

validating and repairing model output

Part of: Screenshot Describer

Lesson 3's prompt asks nicely for a fixed schema. A nice request isn't a guarantee. Sooner or later the model hands you a description missing layout, a component missing text, or a type value that was never in your allowed list. This lesson stops those from becoming crashes. Normalize, don't trust The fix is one function that takes whatever came back and returns something with every field your renderer needs: Read the defaults carefully. Each one closes a specific way things go wrong: - No layout key at all → "single-column", a generic fallback. - No components key, or it's null → an empty list, not a crash on the next loop. - A component missing type → treated as plain "text", the most harmless guess. - A type the model invented that isn't in your allowed set (say, "navbar-thing") → downgraded to "div", the same fallback lesson 4's renderer already uses. - A component missing text → empty string, never None leaking into an f-string as the literal word "None". Why normalize once, here Skip this step and every later function needs its own defensive .get(..., default) calls scattered around: the HTML renderer, the CSS generator, the CLI. Miss one and it crashes. Normalizing right aft

Challenge: Normalize a Broken Description