Controlling the Length

length control

Part of: AI Text Summarizer

A summary you can't size is barely a summary. Sometimes you want a one-line headline; sometimes a five-bullet digest. This lesson is about steering the length reliably. Two knobs, one right answer There are two ways to make output shorter, and only one of them is good: - max tokens is a hard ceiling on how many tokens the model may generate. Set it too low and the model gets cut off mid-sentence, leaving a mangled fragment. It's a safety cap , not a length control. - The prompt is where you actually specify length: "in 2 sentences," "in about 40 words," "in 3 bullet points." The model plans its answer to fit. So the rule is: say the length in the prompt, and set max tokens comfortably above it as a guardrail. Now the length is a parameter of your function, wired straight into the prompt. Callers pick 1 sentence for a headline or 6 for a digest. Verify, don't trust Models are good at "about 40 words," not exact counts. When a limit is genuinely hard (a UI field, an SMS, a tweet), don't rely on the prompt alone: measure the result and enforce the cap yourself. Prompt for the length, then trim as a backstop. That trailing ... signals truncation so nobody mistakes a cut-off summary for

Challenge: Trim to the Word Budget