Sub topic 11
Run all formats as one batch workflow
This chapter assumes you can write a repurposing prompt, have a format spec for each channel, and can read basic Python. Earlier chapters covered the core message, brand voice, and fact checks. Here you combine them into one repeatable run.
Why batch the work
Running each format by hand means pasting the same source into a chat window several times. Details drift between runs, and nobody can tell which version of the core message produced which draft. A batch workflow fixes the inputs once and produces every format from them. You can then rerun it when the source changes.
A batch run has four steps:
- Load the source, core message, and brand voice once.
- Loop over the format specs.
- Attach automatic checks to each draft.
- Mark every draft for human review.
The format specs
Each target is a small data object. Keeping specs as data means that adding a channel is a one-line change.
from dataclasses import dataclass
@dataclass
class FormatSpec:
name: str
max_words: int
structure: str
FORMATS = [
FormatSpec("linkedin_post", 200, "Hook line, three short paragraphs, one closing question"),
FormatSpec("email_newsletter", 250, "Subject line, two-sentence intro, three bullets, one call to action"),
FormatSpec("video_script_60s", 150, "Hook in the first 5 seconds, three beats, spoken call to action"),
]The prompt builder
One function turns a spec plus the shared inputs into a prompt. The last instruction tells the model to use only facts from the source, which supports the fidelity work from the earlier chapter.
def build_prompt(source: str, core_message: str, voice: str, spec: FormatSpec) -> str:
return (
f"Rewrite the source material as a {spec.name}.\n"
f"Core message: {core_message}\n"
f"Brand voice: {voice}\n"
f"Length: at most {spec.max_words} words.\n"
f"Structure: {spec.structure}.\n"
"Use only facts, numbers, and claims that appear in the source. "
"If something is not in the source, leave it out.\n\n"
f"<source>\n{source}\n</source>"
)The automatic check
The check lists every number in a draft that is missing from the source. Invented statistics are a common failure, so this tells the reviewer where to look first.
import re
def numbers_in(text: str) -> set[str]:
return set(re.findall(r"\d+(?:[.,]\d+)*%?", text))
def unsupported_numbers(source: str, draft: str) -> list[str]:
return sorted(numbers_in(draft) - numbers_in(source))The check compares strings, so "3,000" and "3000" count as different numbers. It also cannot catch an invented claim that has no number in it. Treat it as a filter that sorts the review queue, not as proof that a draft is accurate.
The batch function
The loop below produces every format and records the checks next to each draft. The model call is a placeholder, so you supply your own provider's client.
def call_model(prompt: str) -> str:
raise NotImplementedError("Replace with your model provider's client call")
def repurpose(source: str, core_message: str, voice: str, formats: list[FormatSpec]) -> dict:
results = {}
for spec in formats:
draft = call_model(build_prompt(source, core_message, voice, spec))
results[spec.name] = {
"draft": draft,
"word_count": len(draft.split()),
"unsupported_numbers": unsupported_numbers(source, draft),
"status": "needs_review",
}
return resultsThe status is always needs_review. The workflow never publishes anything. A person changes the status after reading the draft.
Common errors
- Length overruns. Models often exceed
max_words. Compareword_countwith the spec and flag drafts that are over the limit, or regenerate them. - One failure stops the run. If
call_modelraises an error on the second format, the loop stops and you lose the third. Wrap the call intry/exceptand record anerrorstatus for that format. - Stale inputs. If you edit the core message but reuse old drafts, the formats disagree. Rerun the whole batch after any change to shared inputs.
- Silent unchecked drafts. A draft with an empty
unsupported_numberslist still needs review. Only the empty list is automatic. The approval is not.
Exercise
The batch loop calls the model for three formats, and the second call fails with a network error. What happens in the code as written, and what is one change that keeps the other formats?
Show answer
The exception propagates out of the loop, so repurpose stops, the third format is never generated, and no results are returned. Wrap the call_model call in try/except, store an entry such as {"status": "error"} for the failed spec, and continue to the next format.
Exercise
A draft's unsupported_numbers list is empty. Can you publish it without review? Explain.
Show answer
No. The check only compares numbers. The draft may still contain invented claims, wrong names, or a tone that does not fit the brand. Every draft keeps the needs_review status until a person approves it.