Alt Text Has Rules

accessibility validation

Part of: Caption & Alt-Text Generator

Ask a model for "alt text under 125 characters" and it will sometimes ignore you. Screen reader software doesn't check the model's manners, so your product has to. This lesson builds the validator that catches bad alt text before it ships. The three rules that matter most 1. Length. Screen readers read alt text aloud in full. A widely used guideline caps useful alt text near 125 characters. Past that it turns into a monologue. 2. No redundant phrasing. Screen readers already announce "image" or "graphic" before the alt text plays, so text starting with "image of" or "picture of" makes the user hear it twice. 3. Not empty. Empty alt text is correct only for a truly decorative image. For a content image the reader gets nothing, which is a broken experience. Writing the validator The empty check returns right away. There's no point measuring the length of nothing. What you do with a failing validator A validator that only prints "bad" doesn't help a product. Retry instead: call again and check the new attempt. Why validation lives outside the prompt You could tighten the prompt forever and still get an occasional miss. Models are probabilistic, not compilers. A prompt lowers how often

Challenge: Validate the Alt Text