Controlling the Format

format control

Part of: AI Text Summarizer

Same article, different shapes: a flowing paragraph, a bullet list, or structured fields your program can read. Format is a first-class dial on a summarizer, and you set it the same way you set length, in the prompt, plus a little parsing on your side. Formats you'll actually want - Paragraph for reading: 2 to 4 sentences of prose. - Bullets for scanning: 3 to 5 short lines, one idea each. - Structured for programs: JSON with fixed keys, so downstream code can pull fields out. The first two are prompt-only. Ask and you receive: Structured output is different When you want the summary as data, ask for JSON and say the keys exactly: Then parse defensively. Models sometimes wrap JSON in chatty text or a code fence, so pull out the object before json.loads: Slicing from the first { to the last } throws away any preamble or fence and hands json.loads a clean object. If parsing still fails, that's your signal to retry (a later lesson wires that up). Why format control matters A summarizer that only makes paragraphs is a toy. The one that also emits {"headline": ..., "points": [...]} plugs into a UI, an email digest, or a database. Same model call, same article; the format is just another

Challenge: Format the Summary