Sub topic 3
Generating a first draft
This chapter covers the step between a finished brief and a draft that a person can review. It assumes you have used a large language model (LLM) in a chat or API, can read simple Python, and know the brief fields from the previous chapter: audience, purpose, sources, and constraints. The code uses a stand-in function for the model call, so it runs without an API key.
What a first draft is in this pipeline
In this pipeline, a first draft is an input to review. It is not a finished product. The model's job is to produce text that is cheap to check, easy to edit, and honest about what it does not know. A pleasant, confident draft that hides its weak spots is worse than a plainer one that marks them.
That goal changes how you write the prompt. You are not only asking for good prose. You are asking for text that makes a reviewer's work easier, and for a draft record that a later stage can trust.
Separate rules from task material
Split the prompt into two parts.
- Standing rules do not change between pieces of content. Examples are "use only the supplied sources" and "mark gaps instead of guessing." Put these in the system message or the first block of the prompt.
- Task material changes every time. This is the audience, the purpose, the numbered sources, and the constraints from the brief.
Keeping the two apart has practical benefits. You can version the rules once and review them like code. A change to the rules is a deliberate event, not something that slips in while someone edits a single brief. Pasted sources are also less likely to be mistaken for instructions, because they sit in a labeled block.
Make the model show its support
Hallucination is a model stating something unsupported as fact. You cannot remove it with a prompt, but you can make it visible. Two conventions do most of the work.
- Source tags. Number each source (
S1,S2, ...) and require a tag after each factual claim. A reviewer can then check a claim against one source instead of searching everything. - A gap marker. Tell the model to write
[NEEDS SOURCE]where the sources are silent. Without this instruction, a model tends to fill gaps with plausible text.
Neither convention proves a claim is true. A model can attach [S1] to a sentence that source S1 does not support. The tags narrow what a human has to check. They do not replace the check.
A drafting function
The code below builds the prompt from a brief and calls a model through an injected function. It returns a draft record and runs a mechanical sanity check on the tags. The call_model parameter lets you swap in any provider, or a fake for tests.
import hashlib
import re
from dataclasses import dataclass, field
from datetime import datetime, timezone
SYSTEM_RULES = (
"You write first drafts for human review. "
"Use only facts found in the numbered sources. "
"After each factual claim, add the source id in square brackets, such as [S1]. "
"If the sources do not cover something, write [NEEDS SOURCE] instead of guessing."
)
@dataclass
class Brief:
audience: str
purpose: str
sources: dict
constraints: list
@dataclass
class DraftRecord:
text: str
model: str
temperature: float
prompt_digest: str
created_at: str
unknown_sources: list = field(default_factory=list)
gap_count: int = 0
def build_prompt(brief):
sources = "\n".join(f"[{sid}] {body}" for sid, body in brief.sources.items())
constraints = "\n".join(f"- {c}" for c in brief.constraints)
user = (
f"Audience: {brief.audience}\n"
f"Purpose: {brief.purpose}\n\n"
f"Sources:\n{sources}\n\n"
f"Constraints:\n{constraints}\n\n"
"Write the draft now."
)
return SYSTEM_RULES, user
def generate_draft(brief, call_model, model_name, temperature=0.3):
system, user = build_prompt(brief)
text = call_model(system, user, temperature)
digest = hashlib.sha256((system + "\n" + user).encode("utf-8")).hexdigest()
cited = set(re.findall(r"\[(S\d+)\]", text))
return DraftRecord(
text=text,
model=model_name,
temperature=temperature,
prompt_digest=digest,
created_at=datetime.now(timezone.utc).isoformat(),
unknown_sources=sorted(cited - set(brief.sources)),
gap_count=text.count("[NEEDS SOURCE]"),
)
def fake_model(system, user, temperature):
return (
"The Basic plan costs 10 dollars a month [S1]. "
"It includes email support [S2]. "
"Refunds are available for 90 days [S9]. "
"[NEEDS SOURCE]"
)
brief = Brief(
audience="small-business owners",
purpose="explain the Basic plan in three sentences",
sources={
"S1": "Basic plan: 10 dollars per month.",
"S2": "Basic plan includes email support.",
},
constraints=["no more than 60 words", "no superlatives"],
)
record = generate_draft(brief, fake_model, "example-model-1")
print(record.unknown_sources)
print(record.gap_count)
print(record.prompt_digest[:12])Running it prints ['S9'], then 1, then a twelve-character hash prefix. The fake model cited a source that does not exist, and the sanity check caught it without any model judgment.
What to store with the draft
The DraftRecord keeps more than the text. Each extra field answers a question someone will ask later.
| Field | Question it answers |
|---|---|
| `model` | Which model produced this? |
| `temperature` | Was it set for creative or conservative output? |
| `prompt_digest` | Which exact rules, brief, and sources were used? |
| `created_at` | When was it generated? |
| `unknown_sources`, `gap_count` | What did the sanity check flag before a human looked? |
Store the full prompt text as well, keyed by the digest, if you can. The digest proves which prompt was used. It cannot recreate it. A later chapter builds these records into the audit trail. For now, the rule is to capture them at generation time, because you cannot reconstruct them afterwards.
Settings that affect draft quality
- Temperature. Lower values (around 0.2 to 0.4) make output more repeatable and less inventive. For fact-bound content, prefer low values. Raise it only for brainstorming headlines or tone variants.
- Length. State a word limit in the constraints and also set the model's output token limit above it. A token cap set too low truncates the draft mid-sentence, and a truncated draft can look finished.
- Source size. Long source blocks can push important material out of the model's context window or bury it. Include the sources the piece needs and no more.
Edge cases to handle
- Truncation. Check the model's finish reason, where your provider reports one. A draft that stopped because it hit the token limit should be regenerated, not submitted.
- Empty or refusal output. If the model returns nothing or a refusal, record the failure and stop. Do not create an empty draft that moves into review.
- Sources that conflict. The model will often pick one silently. Add a constraint such as "if sources disagree, write [CONFLICT] and name both ids," and treat that marker the way you treat
[NEEDS SOURCE]. - Regeneration. Generating again overwrites nothing. Each attempt is a new record with its own digest and timestamp. Keep the old ones. A reviewer may prefer an earlier version, and your records should show how many tries it took.
- Fresh versus edited prompts. If you change the brief and regenerate, the digest changes. That is correct, because the draft now comes from a different input.
Keep the model out of the approval path
The drafting step should have no power over workflow state beyond creating a draft. Do not give the model's output a way to mark itself approved, and do not ask the model to "review its own draft" and treat a positive answer as a gate. A model reviewing its own text tends to agree with it. A second model pass can be a useful extra check, but it is a pre-review aid. Approval stays with a person, in a later stage of the pipeline.
In practice, the drafting function should return a record and nothing else. The caller creates the content item in the draft state, as covered in the next chapter on states and transitions.
Common errors
- Putting rules and sources in one blob. Rules get edited casually and sources get mistaken for instructions. Keep them separate.
- Asking for citations without supplying sources. The model will invent plausible source names. Only request tags for sources you provided.
- Not recording the model and prompt. When a draft goes wrong, you cannot tell whether the prompt or the model changed.
- Treating tag presence as verification. Tags help a human check. They do not do the check.
- Submitting truncated drafts. Check the finish reason or the ending of the text before the draft enters the workflow.
Exercise
Your sanity check reports no unknown source ids and zero gaps for a draft. A teammate says the draft can skip detailed review. What is wrong with that reasoning, and what does the check actually tell you?
Show answer
The check only verifies mechanics: every tag points to a source that was supplied, and the model left no [NEEDS SOURCE] markers. It cannot tell whether a claim is actually supported by the source it cites, whether the tone suits the audience, or whether the model ignored a constraint. A tag can be attached to a false sentence. The check reduces what a reviewer has to look at, but human review against the rubric is still required.
Exercise
You regenerate a draft after tightening the brief's constraints. Which fields in the new DraftRecord will differ from the old one even if the model produces identical text, and why should you keep both records?
Show answer
The promptdigest changes because the constraints are part of the prompt, and createdat changes because the call happened at a different time. Keeping both records shows which input produced which output, how many attempts were needed, and lets a reviewer or auditor compare versions or fall back to the earlier draft.