Sub topic 5
Summarizing, rewriting, translating, and drafting
This chapter covers the four text-to-text tasks that most LLM products start with. It assumes you can call a model through a complete(prompt) function, as in earlier chapters, and that you know the basics of prompting: instructions, context, and output format.
The working model
All four tasks transform text you supply into new text. The model has the source in its prompt, so it does not need to recall facts from training. This makes these tasks more reliable than open-ended question answering. They still fail in predictable ways.
| Task | Input | Output | Main risk |
|---|---|---|---|
| Summarizing | Long text | Shorter text | Dropped or invented details |
| Rewriting | Text and a style rule | Same meaning, new style | Meaning drift |
| Translating | Text and a target language | Same meaning, new language | Lost tone, wrong terms |
| Drafting | Notes and a goal | New text | Invented facts |
Put constraints in the prompt
A vague prompt such as "Summarize this" gives a result of unpredictable length and focus. State the audience, length, and what to keep.
def summarize(text: str, complete, max_words: int = 60) -> str:
prompt = (
f"Summarize the text below for a busy manager in at most {max_words} words.\n"
"Keep names, dates, and amounts exactly as written.\n"
"Do not add information that is not in the text.\n\n"
"Text:\n" + text
)
return complete(prompt).strip()The same pattern covers the other tasks. For rewriting, name the target tone and say what must not change ("keep every number and product name"). For translation, give the source and target language, the audience, and any glossary terms that must stay fixed. For drafting, supply the facts as a list and tell the model to use only those facts.
Check the output in code
Models often ignore length limits. A cheap check catches this, and a retry with feedback usually fixes it.
def summarize_checked(text: str, complete, max_words: int = 60, tries: int = 2) -> str:
summary = summarize(text, complete, max_words)
for _ in range(tries):
if len(summary.split()) <= max_words:
return summary
summary = complete(
f"Shorten this to at most {max_words} words, keeping all numbers:\n\n{summary}"
).strip()
return summaryYou can also check that every number in the source appears in the output, or that required glossary terms survive translation. These checks are simple, and they catch the errors that matter most.
Common errors
- Long inputs. Summaries of very long documents skew toward the start and end. Split the text into chunks, summarize each, then summarize the summaries.
- Meaning drift in rewriting. A "more formal" rewrite may soften a firm deadline. Compare key facts before and after.
- Literal translation. Idioms and product names translate badly. Provide a glossary and say which terms to leave untranslated.
- Invented details in drafts. Given thin notes, the model fills gaps with plausible content. Mark missing information as "unknown" in the prompt and instruct the model not to guess.
- Hidden language bias. Quality is usually lower for less common languages. Test with a native speaker before shipping.
Exercise
A summarizer works on short articles but misses key points in 100-page reports. Name one fix and explain why it helps.
Show answer
Split the report into chunks that fit comfortably in the context, summarize each chunk, then summarize the combined chunk summaries. Each call sees a manageable amount of text, so the model is less likely to skip material in the middle.
Exercise
You translate product descriptions and the brand name "SnapDeck" keeps coming back as a translated word. How do you prevent it?
Show answer
Add a rule to the prompt that lists "SnapDeck" as a term to leave untranslated, or include a glossary. Then add a code check that the output still contains "SnapDeck".